Skip to content

Instantly share code, notes, and snippets.

@coreyhaines
Created December 9, 2016 18:24
Show Gist options
  • Save coreyhaines/a717ea2db6f578a7d86f6edd38145d36 to your computer and use it in GitHub Desktop.
Save coreyhaines/a717ea2db6f578a7d86f6edd38145d36 to your computer and use it in GitHub Desktop.
Rake task to compile/copy elm
namespace :elm do
Apps = [ "WorkspaceMain", "ManageSubscribersMain", "NotebookMain", "ResponsesMain" ]
JsFileName = "irn_elm.js"
JsOutputDir = "app/assets/javascripts"
desc "Updates packages, compiles the Elm code and copies it to #{JsOutputDir}"
task :compile_and_copy => [:package_install, :make, :copy] do
puts "Updated Packages, Compiled and copied Elm code to #{JsOutputDir}"
end
desc "Compiles the Elm code and copies it to #{JsOutputDir}"
task :offline_compile_and_copy => [:make, :copy] do
puts "Compiled and copied Elm code to #{JsOutputDir}"
end
desc "Runs package install and elm make"
task :compile => [:package_install, :make] do
puts "Updated Packages and Compiled Elm code to #{JsOutputDir}"
end
desc "Runs elm package install"
task :package_install do
Dir.chdir("../elm") do
unless system "elm package install"
puts "Failed to run 'elm package install'"
exit 1
end
end
end
desc "Compiles the Elm code"
task :make do
Dir.chdir("../elm") do
files = Apps.map{|name| "src/#{name}.elm"}.join " "
puts "Compiling #{files} -> #{JsFileName}"
unless system "elm make #{files} --output #{JsFileName}"
puts "Failed to compile elm code #{files}"
exit 1
end
end
end
desc "Copies the compiled Elm code to #{JsOutputDir}"
task :copy do
Dir.chdir("../elm") do
puts "Copying javascript #{JsFileName}"
FileUtils.cp(JsFileName, "../rails/#{JsOutputDir}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment