Sha256: 4d5bde223c6816adc98721348f8978a465167fce386ae9df734192a445920834

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

require "open3"

module Snowball
  EXECUTABLE = Pathname.new(__FILE__).join("../../../", "bin/roll.js").realpath
  class RollError < Exception; end

  class Roller
    def self.roll(entry, opts)
      args = []

      ignores = opts[:ignores].dup
      ignores.unshift *%w(jsdom xmlhttprequest location navigator)
      ignores.uniq!

      args << ignores.map { |node_module| "--ignore #{node_module}" }.join(" ")
      args << opts[:includes].map { |node_module| "--require #{node_module}" }.join(" ")
      args << "--prelude #{!!opts[:prelude]}"
      args << "--entry #{entry}"
      args << "--raw" if opts[:raw]

      args += (opts[:env] || {}).map do |k,v|
        "--env #{k}=#{v}"
      end

      cmd = "node #{EXECUTABLE} #{args.join(" ")}"

      Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
        source = stdout.read
        unless wait_thr.value.success?
          raise RollError.new "Got error while executing \"#{cmd}\" command: #{stderr.read}"
        end
        return source
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
snowball-0.1.22 lib/snowball/roller.rb
snowball-0.1.20 lib/snowball/roller.rb
snowball-0.1.9 lib/snowball/roller.rb
snowball-0.1.8 lib/snowball/roller.rb
snowball-0.1.7 lib/snowball/roller.rb
snowball-0.1.6 lib/snowball/roller.rb