Sha256: 69196c5f8643fcec3a84c850ee3a8c6e0cee45522132bfa1ffd04ca03a73348b

Contents?: true

Size: 834 Bytes

Versions: 3

Compression:

Stored size: 834 Bytes

Contents

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.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

3 entries across 3 versions & 1 rubygems

Version Path
nanoc-webpack.rb-0.10.4 lib/nanoc/webpack/spawn.rb
nanoc-webpack.rb-0.10.3 lib/nanoc/webpack/spawn.rb
nanoc-webpack.rb-0.10.2 lib/nanoc/webpack/spawn.rb