Class: Antoinette::CompileElm
- Inherits:
-
Object
- Object
- Antoinette::CompileElm
- Defined in:
- lib/antoinette/services/compile_elm.rb
Constant Summary collapse
- ELM_PURE_FUNCS =
%w[F2 F3 F4 F5 F6 F7 F8 F9 A2 A3 A4 A5 A6 A7 A8 A9].freeze
Instance Method Summary collapse
- #compile(elm_app_names) ⇒ Object
-
#initialize(elm_path: "elm", environment: Rails.env.to_s) ⇒ CompileElm
constructor
A new instance of CompileElm.
Constructor Details
#initialize(elm_path: "elm", environment: Rails.env.to_s) ⇒ CompileElm
Returns a new instance of CompileElm.
9 10 11 12 |
# File 'lib/antoinette/services/compile_elm.rb', line 9 def initialize(elm_path: "elm", environment: Rails.env.to_s) @elm_path = elm_path @environment = environment end |
Instance Method Details
#compile(elm_app_names) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/antoinette/services/compile_elm.rb', line 14 def compile(elm_app_names) elm_file_paths = elm_app_names.map { |name| "app/client/#{name}.elm" } output_file = "tmp/elm_compiled.js" optimize_flag = production? ? "--optimize" : "" command = "#{@elm_path} make #{optimize_flag} --output=#{output_file} #{elm_file_paths.join(" ")}".squeeze(" ") system(command) unless Process.last_status.success? raise "Elm compilation failed" end js = File.read(output_file) production? ? minify(js) : js ensure File.delete(output_file) if output_file && File.exist?(output_file) end |