Created
April 10, 2015 16:06
-
-
Save kuon/7bf6d718fe1e322aa72d to your computer and use it in GitHub Desktop.
Rakefile for js project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'config/commands' | |
root = File.expand_path('..', __FILE__) | |
ENV['PATH'] = "#{File.join(root, 'node_modules', '.bin')}:#{ENV['PATH']}" | |
scss_dir = File.join(root, 'app', 'css') | |
css_dir = File.join(root, 'build', 'css') | |
image_dir = File.join(root, 'app', 'images') | |
js_dir = File.join(root, 'app', 'js') | |
app_ts = File.join(root, 'app', 'js', 'app.ts') | |
app_js = File.join(root, 'build', 'js', 'app.js') | |
compass_options = "--sass-dir #{scss_dir} --css-dir #{css_dir} --images-dir #{image_dir} --javascripts-dir #{js_dir}" | |
browserify_options = '-p [ tsify --noImplicitAny ] -t [envify --NODE_ENV production]' | |
desc 'Install' | |
task :install do | |
sh 'npm install' | |
sh 'bundle install' | |
end | |
task :build_folder do | |
sh "mkdir -p #{File.join(root, 'build', 'js')}" | |
end | |
desc 'Server' | |
task :server => :build_folder do | |
sh 'bundle exec rackup -o 0.0.0.0 -p 9292' | |
end | |
desc 'Cleanup build' | |
task :clean do | |
sh "rm -fr #{File.join(root, 'build')}" | |
end | |
desc 'Build app' | |
task :build => [:clean, :build_folder] do | |
sh "browserify #{app_ts} #{browserify_options} | uglifyjs -cm > #{app_js}" | |
sh "compass compile #{compass_options} -s compressed" | |
end | |
desc 'Watch files and recompile on change' | |
task :watch do | |
js_watch = "watchify -v -d #{app_ts} #{browserify_options} -o #{app_js}" | |
css_watch = "compass watch #{compass_options}" | |
js_pid = Process.spawn(js_watch) | |
css_pid = Process.spawn(css_watch) | |
at_exit do | |
Process.kill('TERM', js_pid) if js_pid | |
Process.kill('TERM', css_pid) if css_pid | |
end | |
Process.waitpid(js_pid) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment