class Guard::WebPacker
Constants
- DEFAULT_PATH
- DEFAULT_SIGNAL
- WEBPACK
- WEBPACK_DEV_SERVER
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
# File lib/guard/webpacker.rb, line 13 def initialize(options = {}) super @pid = nil @path = options[:path] || DEFAULT_PATH @bin = options[:bin] || WEBPACK_DEV_SERVER @stop_signal = options[:stop_signal] || DEFAULT_SIGNAL end
Public Instance Methods
reload()
click to toggle source
Called on Ctrl-Z signal
# File lib/guard/webpacker.rb, line 54 def reload Guard::Compat::UI.info "[Guard::WebPacker] Restarting #{@bin} ..." restart end
restart()
click to toggle source
# File lib/guard/webpacker.rb, line 69 def restart stop start end
run_all()
click to toggle source
Called on Ctrl-/ signal
# File lib/guard/webpacker.rb, line 60 def run_all true end
run_on_changes(_)
click to toggle source
Called on file(s) modifications
# File lib/guard/webpacker.rb, line 65 def run_on_changes(_) restart end
start()
click to toggle source
# File lib/guard/webpacker.rb, line 22 def start unless File.exist?(File.join(@path, @bin)) Guard::Compat::UI.info "[Guard::WebPacker::Error] Could not find #{@bin} at #{@path}." return false end Guard::Compat::UI.info "[Guard::WebPacker] Starting up #{@bin} ..." Guard::Compat::UI.info cmd # launch webpack-dev-server or webpack @pid = spawn({}, cmd) end
stop()
click to toggle source
# File lib/guard/webpacker.rb, line 35 def stop return unless @pid Guard::Compat::UI.info "[Guard::WebPacker] Stopping #{@bin} ..." ::Process.kill @stop_signal, @pid begin Timeout.timeout(15) do ::Process.wait @pid end rescue Timeout::Error Guard::Compat::UI.info "[Guard::WebPacker] Sending SIGKILL to #{@bin}, as it\'s taking too long to shutdown." ::Process.kill :KILL, @pid ::Process.wait @pid end @pid = nil Guard::Compat::UI.info "[Guard::WebPacker] Stopped process #{@bin} ..." end
Private Instance Methods
cmd()
click to toggle source
# File lib/guard/webpacker.rb, line 76 def cmd command = ["bundle exec #{@path}/#{@bin}"] if @bin == WEBPACK command << '--watch' if @options[:watch] command << '--colors' if @options[:colors] command << '--progress' if @options[:progress] command << '--progress' if @options[:progress] command << "--mode #{@options[:mode]}" if @options[:mode] end command.join(' ') end