Module: ElmSprockets::Compiler

Defined in:
lib/elm_sprockets/compiler.rb

Class Method Summary collapse

Class Method Details

.compile(pathname, output_file, dir_options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/elm_sprockets/compiler.rb', line 5

def self.compile(pathname, output_file, dir_options = {})
  @cmd ||= "#{`npm bin`.strip}/elm-make"
  puts @cmd
  puts output_file.path

  # need to specify LANG or else build will fail on jenkins
  # with error "elm-make: elm-stuff/build-artifacts/NoRedInk/NoRedInk/1.0.0/Quiz-QuestionStore.elmo: hGetContents: invalid argument (invalid byte sequence)"
  Open3.popen3(
      {'LANG' => 'en_US.UTF-8'},
      @cmd, pathname.to_s,
      "--yes", "--output",
      output_file.path, dir_options) do |_stdin, _stdout, stderr, wait_thr|
    compiler_err = stderr.gets(nil)
    stderr.close

    process_status = wait_thr.value

    if process_status.exitstatus != 0
      fail compiler_err
    end
  end
end