class WebpackDriver::Process
Constants
- READ_CHUNK_SIZE
Attributes
assets[R]
config[R]
error[R]
last_compilation_message[R]
last_status[R]
messages[R]
Public Class Methods
new(script, config)
click to toggle source
# File lib/webpack_driver/process.rb, line 18 def initialize(script, config) self.reset! @config = config args = ["./node_modules/.bin/#{script}"] + config.flags config.logger.info("Starting webpack using command:\n#{args.join(' ')}") @proc = ::ChildProcess.build(*args) @proc.environment.merge!( config.environment ) if config.directory config.logger.info("In directory: #{config.directory}") @proc.cwd = config.directory end end
Public Instance Methods
in_progress?()
click to toggle source
# File lib/webpack_driver/process.rb, line 49 def in_progress? @last_status == 'compiling' end
start()
click to toggle source
# File lib/webpack_driver/process.rb, line 34 def start self.reset! @output, w = IO.pipe @proc.io.stdout = @proc.io.stderr = w @proc.start w.close @listener = listen_for_status_updates end
stop()
click to toggle source
# File lib/webpack_driver/process.rb, line 43 def stop @proc.stop @output.close unless @output.closed? @listener.join end
Protected Instance Methods
listen_for_status_updates()
click to toggle source
# File lib/webpack_driver/process.rb, line 90 def listen_for_status_updates Thread.new do @output.each_line do | l | begin match = l.match(/^STATUS: (.*)/) if match record_message(JSON.parse(match[1])) else config.logger.info(l.chomp) end rescue => e config.logger.error "Exception #{e} encountered while processing line #{l}" end end end end
record_error(error)
click to toggle source
# File lib/webpack_driver/process.rb, line 61 def record_error(error) @error = error config.logger.error( "#{error['name']}: #{error['resource']}\n#{error['message']}" ) end
record_message(msg)
click to toggle source
# File lib/webpack_driver/process.rb, line 72 def record_message(msg) unless msg['type'] == 'compile' @messages << msg config.logger.debug(msg) end case msg['type'] when 'status' record_status(msg['value']) when 'asset' Asset.record(@assets, msg['value']) when 'error' record_error(msg['value']) when 'config' config.output_path = Pathname.new(msg['value']['output_path']) end end
record_status(status)
click to toggle source
# File lib/webpack_driver/process.rb, line 68 def record_status(status) @last_status = status end
reset!()
click to toggle source
# File lib/webpack_driver/process.rb, line 55 def reset! @assets = Concurrent::Map.new @messages = Concurrent::Array.new @last_compilation_message = {} end