Module: SparkEngine::Command
Instance Method Summary collapse
-
#build(options = {}) ⇒ Object
Build assets.
- #clean ⇒ Object
-
#dispatch(command, *args) ⇒ Object
Handles running threaded commands.
- #from_root(command = nil, &blk) ⇒ Object
- #gem_build ⇒ Object
- #gem_bump(v) ⇒ Object
- #gem_install ⇒ Object
- #gem_release ⇒ Object
- #gem_tag ⇒ Object
- #production? ⇒ Boolean
- #require_rails ⇒ Object
- #run(options) ⇒ Object
-
#server(options = {}) ⇒ Object
Run rails server and watch assets.
- #version ⇒ Object
-
#watch(options = {}) ⇒ Object
Watch assets for changes and build.
Instance Method Details
#build(options = {}) ⇒ Object
Build assets
129 130 131 132 133 134 |
# File 'lib/spark_engine/command.rb', line 129 def build(={}) puts SparkEngine.production? ? 'Building for production…' : 'Building…' require_rails clean if SparkEngine.production? SparkEngine.plugin.build() end |
#clean ⇒ Object
113 114 115 116 117 118 |
# File 'lib/spark_engine/command.rb', line 113 def clean FileUtils.rm_rf('public') FileUtils.rm_rf(SparkEngine.rails_path('tmp/cache/')) FileUtils.rm_rf('.sass-cache') FileUtils.rm_rf(SparkEngine.rails_path('.sass-cache')) end |
#dispatch(command, *args) ⇒ Object
Handles running threaded commands
122 123 124 125 126 |
# File 'lib/spark_engine/command.rb', line 122 def dispatch(command, *args) @threads = [] send command, *args @threads.each { |thr| thr.join } end |
#from_root(command = nil, &blk) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/spark_engine/command.rb', line 156 def from_root(command=nil, &blk) unless SparkEngine.gem_path abort "Command must be run from the root of an engine (adjacent to the gemspec)." end Dir.chdir(SparkEngine.gem_path) do if command system command else blk.call end end end |
#gem_build ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/spark_engine/command.rb', line 64 def gem_build @production = true FileUtils.rm_rf('public') dispatch(:build) system "bundle exec rake build" system "git add Gemfile* lib" end |
#gem_bump(v) ⇒ Object
101 102 103 |
# File 'lib/spark_engine/command.rb', line 101 def gem_bump(v) system "bump #{v} --no-commit" end |
#gem_install ⇒ Object
72 73 74 75 76 77 |
# File 'lib/spark_engine/command.rb', line 72 def gem_install @production = true FileUtils.rm_rf('public') dispatch(:build) system "bundle exec rake install" end |
#gem_release ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/spark_engine/command.rb', line 79 def gem_release @production = true gem_build spec = SparkEngine.plugin_spec gem_file = "./pkg/#{spec.name}-#{spec.version}.gem" if File.exists?(gem_file) system "git commit -m v#{spec.version}" gem_tag system "git push origin $(git rev-parse --abbrev-ref HEAD) --tag" if key = ENV['RUBYGEMS_API_KEY'] gem = "#{spec.name}-#{spec.version}.gem" system "bundle exec rake build" system "curl --data-binary @./pkg/#{gem} -H 'Authorization:#{key}' https://rubygems.org/api/v1/gems" else system "gem push #{gem_file}" system "rm ./public/*.gz" end end end |
#gem_tag ⇒ Object
105 106 107 |
# File 'lib/spark_engine/command.rb', line 105 def gem_tag system "git tag v#{SparkEngine.plugin_spec.version}" end |
#production? ⇒ Boolean
60 61 62 |
# File 'lib/spark_engine/command.rb', line 60 def production? @production == true end |
#require_rails ⇒ Object
109 110 111 |
# File 'lib/spark_engine/command.rb', line 109 def require_rails require File.join(Dir.pwd, SparkEngine.rails_path('config/application')) end |
#run(options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/spark_engine/command.rb', line 5 def run() @production = [:production] if [:help] version puts [:help] return end case [:command] when 'new', 'n' require "spark_engine/scaffold" Scaffold.new() when 'generate', 'g' from_root { require "spark_engine/scaffold" require_rails Scaffold.new() } when 'build', 'b' from_root { dispatch(:build, ) } when 'watch', 'w' from_root { dispatch(:watch, ) } when 'server', 's' from_root { dispatch(:server, ) } when 'clean', 'c' from_root { clean } when 'version' version when 'gem:build' from_root { gem_build } when 'gem:install' from_root { gem_install } when 'gem:release' from_root { gem_release } when 'gem:tag' from_root { gem_tag } when 'gem:bump:patch' from_root { gem_bump('patch') } when 'gem:bump:minor' from_root { gem_bump('minor') } when 'gem:bump:major' from_root { gem_bump('major') } else puts "Command `#{[:command]}` not recognized" end end |
#server(options = {}) ⇒ Object
Run rails server and watch assets
150 151 152 153 154 |
# File 'lib/spark_engine/command.rb', line 150 def server(={}) [:port] ||= 3000 @threads << Thread.new { system "#{SparkEngine.rails_path('bin/rails')} server -p #{[:port]}" } watch() if [:watch] end |
#version ⇒ Object
53 54 55 56 57 58 |
# File 'lib/spark_engine/command.rb', line 53 def version spec = SparkEngine.plugin_spec puts "spark_engine v #{SparkEngine::VERSION}" puts " - #{spec.name} v #{spec.version}\n" if spec puts "" end |
#watch(options = {}) ⇒ Object
Watch assets for changes and build
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/spark_engine/command.rb', line 137 def watch(={}) build() require 'listen' trap("SIGINT") { puts "\nspark_engine watcher stopped. Have a nice day!" exit! } @threads.concat SparkEngine.load_plugin.watch() end |