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
32
# 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

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.



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

def config
  @config
end

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#last_compilation_messageObject (readonly)

Returns the value of attribute last_compilation_message.



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

def last_compilation_message
  @last_compilation_message
end

#last_statusObject (readonly)

Returns the value of attribute last_status.



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

def last_status
  @last_status
end

#messagesObject (readonly)

Returns the value of attribute messages.



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

def messages
  @messages
end

#progressObject (readonly)

Returns the value of attribute progress.



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

def progress
  @progress
end

Instance Method Details

#in_progress?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/webpack_driver/process.rb', line 50

def in_progress?
    !! ( !@error && @progress && @progress != 1 )
end

#startObject



34
35
36
37
38
39
40
41
42
# 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
    @progress = 0.0
    @listener = listen_for_status_updates
end

#stopObject



44
45
46
47
48
# File 'lib/webpack_driver/process.rb', line 44

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