Class: Opal::CliRunners::Chrome

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/cli_runners/chrome.rb

Constant Summary collapse

SCRIPT_PATH =
File.expand_path('chrome.js', __dir__).freeze
DEFAULT_CHROME_HOST =
'localhost'
DEFAULT_CHROME_PORT =
9222

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Chrome

Returns a new instance of Chrome.


22
23
24
25
26
27
28
29
30
31
32
33
# File 'opal/lib/opal/cli_runners/chrome.rb', line 22

def initialize(data)
  builder = data[:builder]
  options = data[:options]
  argv    = data[:argv]

  if argv && argv.any?
    warn "warning: ARGV is not supported by the Chrome runner #{argv.inspect}"
  end

  @output = options.fetch(:output, $stdout)
  @builder = builder
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.


35
36
37
# File 'opal/lib/opal/cli_runners/chrome.rb', line 35

def builder
  @builder
end

#exit_statusObject (readonly)

Returns the value of attribute exit_status.


35
36
37
# File 'opal/lib/opal/cli_runners/chrome.rb', line 35

def exit_status
  @exit_status
end

#outputObject (readonly)

Returns the value of attribute output.


35
36
37
# File 'opal/lib/opal/cli_runners/chrome.rb', line 35

def output
  @output
end

Class Method Details

.call(data) ⇒ Object


16
17
18
19
20
# File 'opal/lib/opal/cli_runners/chrome.rb', line 16

def self.call(data)
  runner = new(data)
  runner.run
  runner.exit_status
end

Instance Method Details

#runObject


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'opal/lib/opal/cli_runners/chrome.rb', line 37

def run
  mktmpdir do |dir|
    with_chrome_server do
      cmd = [
        'env',
        "CHROME_HOST=#{chrome_host}",
        "CHROME_PORT=#{chrome_port}",
        'node',
        '--require', "#{__dir__}/source-map-support",
        SCRIPT_PATH
      ]

      prepare_files_in(dir)

      IO.popen(cmd, 'w', out: output) do |io|
        io.write dir
      end
    end

    @exit_status = $?.exitstatus
  end
end