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
123 124 125 126 127 128 |
# File 'lib/spark_engine/command.rb', line 123 def build(={}) puts SparkEngine.production? ? 'Building for production…' : 'Building…' require_rails clean if SparkEngine.production? SparkEngine.plugin.build() end |
#clean ⇒ Object
107 108 109 110 111 112 |
# File 'lib/spark_engine/command.rb', line 107 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
116 117 118 119 120 |
# File 'lib/spark_engine/command.rb', line 116 def dispatch(command, *args) @threads = [] send command, *args @threads.each { |thr| thr.join } end |
#from_root(command = nil, &blk) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spark_engine/command.rb', line 150 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
58 59 60 61 62 63 |
# File 'lib/spark_engine/command.rb', line 58 def gem_build @production = true FileUtils.rm_rf('public') dispatch(:build) system "bundle exec rake build" end |
#gem_bump(v) ⇒ Object
94 95 96 97 |
# File 'lib/spark_engine/command.rb', line 94 def gem_bump(v) system "bump #{v} --no-commit" gem_build end |
#gem_install ⇒ Object
65 66 67 68 69 70 |
# File 'lib/spark_engine/command.rb', line 65 def gem_install @production = true FileUtils.rm_rf('public') dispatch(:build) system "bundle exec rake install" end |
#gem_release ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/spark_engine/command.rb', line 72 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
99 100 101 |
# File 'lib/spark_engine/command.rb', line 99 def gem_tag system "git tag v#{SparkEngine.plugin_spec.version}" end |
#production? ⇒ Boolean
54 55 56 |
# File 'lib/spark_engine/command.rb', line 54 def production? @production == true end |
#require_rails ⇒ Object
103 104 105 |
# File 'lib/spark_engine/command.rb', line 103 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 |
# 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 '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 `#{options[:command]}` not recognized" end end |
#server(options = {}) ⇒ Object
Run rails server and watch assets
144 145 146 147 148 |
# File 'lib/spark_engine/command.rb', line 144 def server(={}) [:port] ||= 3000 @threads << Thread.new { system "#{SparkEngine.rails_path('bin/rails')} server -p #{options[:port]}" } watch() if [:watch] end |
#version ⇒ Object
47 48 49 50 51 52 |
# File 'lib/spark_engine/command.rb', line 47 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
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/spark_engine/command.rb', line 131 def watch(={}) build() require 'listen' trap("SIGINT") { puts "\nspark_engine watcher stopped. Have a nice day!" exit! } @threads.concat SparkEngine.load_plugin.watch() end |