Module: LuxAssets::Cli
Overview
command line helpers
Instance Method Summary collapse
- #die(text) ⇒ Object
-
#monitor ⇒ Object
monitor for file changes.
- #run(what, cache_file = nil) ⇒ Object
- #warn(text) ⇒ Object
Instance Method Details
#die(text) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/lux_assets/cli.rb', line 6 def die text text = text.red if text.respond_to?(:red) puts text puts caller.slice(0, 10) exit end |
#monitor ⇒ Object
monitor for file changes
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lux_assets/cli.rb', line 38 def monitor puts 'Lux assets - looking for file changes' files = LuxAssets.to_h.values.map(&:values).flatten.map { |it| Pathname.new it } last_change = Time.now while true for file in files if file.mtime > last_change last_change = Time.now LuxAssets.compile file.to_s end end sleep 2 end end |
#run(what, cache_file = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lux_assets/cli.rb', line 18 def run what, cache_file=nil puts what.yellow stdin, stdout, stderr, wait_thread = Open3.popen3(what) error = stderr.gets while line = stderr.gets do error += line end # node-sass prints to stderror on complete error = nil if error && error.include?('Rendering Complete, saving .css file...') if error cache_file.unlink if cache_file && cache_file.exist? warn error end end |
#warn(text) ⇒ Object
13 14 15 16 |
# File 'lib/lux_assets/cli.rb', line 13 def warn text text = text.magenta if text.respond_to?(:magenta) puts text end |