Module: Nanoc::Webpack::Spawn

Included in:
Filter
Defined in:
lib/nanoc/webpack/spawn.rb

Constant Summary collapse

Error =
Class.new(RuntimeError)

Instance Method Summary collapse

Instance Method Details

#spawn(exe, argv) ⇒ Integer

Spawns a process

Parameters:

  • exe (String)

    The path to an executable

  • argv (Array<String>)

    An array of command line arguments

Returns:

  • (Integer)

    Returns the exit code of the spawned process



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nanoc/webpack/spawn.rb', line 19

def spawn(exe, argv)
  r = cmd(exe, *argv)
  if r.not_found?
    raise Nanoc::Tidy::Error, "The #{exe} executable was not found"
  elsif r.success?
    r.exit_status
  else
    raise Error,
          "#{File.basename(exe)} exited unsuccessfully\n" \
          "(item: #{item.identifier})\n" \
          "(exit code: #{r.exit_status})\n" \
          "(stdout: #{r.stdout.gsub(Dir.getwd, "")[1..]&.chomp})\n" \
          "(stderr: #{r.stderr.gsub(Dir.getwd, "")[1..]&.chomp})\n",
          []
  end
end