class Guard::Webpack::Runner
Attributes
options[RW]
thread[RW]
Public Class Methods
new(options)
click to toggle source
# File lib/guard/webpack/runner.rb, line 4 def initialize(options) @options = options end
Public Instance Methods
restart()
click to toggle source
# File lib/guard/webpack/runner.rb, line 8 def restart; stop; start; end
start()
click to toggle source
# File lib/guard/webpack/runner.rb, line 10 def start unless_running do @thread = Thread.new { run_webpack } ::Guard::UI.info "Webpack watcher started." end end
stop()
click to toggle source
# File lib/guard/webpack/runner.rb, line 17 def stop if_running do @thread.kill ::Guard::UI.info "Webpack watcher stopped." end end
Private Instance Methods
global_webpack()
click to toggle source
# File lib/guard/webpack/runner.rb, line 31 def global_webpack system("command -v webpack >/dev/null") && 'webpack' end
if_running() { || ... }
click to toggle source
# File lib/guard/webpack/runner.rb, line 69 def if_running yield if @thread && @thread.alive? end
local_webpack()
click to toggle source
# File lib/guard/webpack/runner.rb, line 26 def local_webpack bin = File.join(Dir.pwd,'node_modules/webpack/bin/webpack.js') File.exists?(bin) && bin end
no_webpack()
click to toggle source
# File lib/guard/webpack/runner.rb, line 35 def no_webpack # TODO: This is a bad error. raise 'Webpack binary not found' end
option_flags()
click to toggle source
# File lib/guard/webpack/runner.rb, line 44 def option_flags output = "" output += " -d" if @options[:d] output += " --colors" if @options[:colors] output += " --progress" if @options[:progress] output += " --config #{@options[:config]}" if @options[:config] output end
run_webpack()
click to toggle source
# File lib/guard/webpack/runner.rb, line 53 def run_webpack begin pid = fork{ exec("#{webpack_bin} --watch #{option_flags}") } Process.wait(pid) rescue # TODO: Be more discerning. ::Guard::UI.error "Webpack unable to start (are you sure it's installed?)" ensure Process.kill('TERM',pid) end end
unless_running() { || ... }
click to toggle source
# File lib/guard/webpack/runner.rb, line 65 def unless_running yield if !@thread || !@thread.alive? end
webpack_bin()
click to toggle source
# File lib/guard/webpack/runner.rb, line 40 def webpack_bin local_webpack || global_webpack || no_webpack end