Class: WebpackDriver::Process

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/webpack_driver/process.rb

Direct Known Subclasses

Compile, DevServer

Constant Summary collapse

READ_CHUNK_SIZE =
1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script, config) ⇒ Process

Returns a new instance of Process.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/webpack_driver/process.rb', line 18

def initialize(script, config)
    self.reset!
    @config = config
    args = ["./node_modules/.bin/#{script}"] + config.flags

    @proc = ::ChildProcess.build(*args)

    @proc.environment.merge!(
        config.environment
    )
    puts "ENV"
    p config.environment
    @proc.cwd = config.directory
end

Instance Attribute Details

#assetsObject (readonly)

Returns the value of attribute assets.



15
16
17
# File 'lib/webpack_driver/process.rb', line 15

def assets
  @assets
end

#configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/webpack_driver/process.rb', line 16

def config
  @config
end

#messagesObject (readonly)

Returns the value of attribute messages.



15
16
17
# File 'lib/webpack_driver/process.rb', line 15

def messages
  @messages
end

Instance Method Details

#startObject



33
34
35
36
37
38
39
40
# File 'lib/webpack_driver/process.rb', line 33

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

#stopObject



42
43
44
45
46
# File 'lib/webpack_driver/process.rb', line 42

def stop
    @proc.stop
    @output.close unless @output.closed?
    @listener.join
end

#valid?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/webpack_driver/process.rb', line 48

def valid?
    last_compilation_message['operation'] == 'emit'
end