Sha256: 5dc9c2b817e2cb853c3e8a45906d062711dc999b6e16e5d9da30d572ecba6905

Contents?: true

Size: 962 Bytes

Versions: 1

Compression:

Stored size: 962 Bytes

Contents

# frozen_string_literal: true

module Nanoc::Webpack
  module Spawn
    require "test-cmd"
    Error = Class.new(RuntimeError)

    ##
    # Spawns a process
    #
    # @param [String] exe
    #  The path to an executable
    #
    # @param [Array<String>] argv
    #  An array of command line arguments
    #
    # @return [Integer]
    #  Returns the exit code of the spawned process
    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nanoc-webpack.rb-0.10.6 lib/nanoc/webpack/spawn.rb