Created
August 15, 2011 18:06
-
-
Save rubyist/1147332 to your computer and use it in GitHub Desktop.
coffee compiling rakefile
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 'coffee_script' | |
require 'rake/clean' | |
def coffee_to_js(coffee) | |
File.join(BUILDDIR, File.dirname(coffee.split('/')[1..-1].join('/')), File.basename(coffee).ext('js')) | |
end | |
JSFILE = 'app.js' | |
JSPATH = "_attachments/js/app/#{JSFILE}" | |
COFFEE = FileList['coffeescript/**/*.coffee'] | |
BUILDDIR = 'js' | |
JS = COFFEE.collect { |fn| coffee_to_js(fn) } | |
CLEAN.include(JS, BUILDDIR) | |
CLOBBER.include(JSPATH) | |
task :build => [JSFILE] | |
file JSFILE => JS do | |
puts "assembling #{JSFILE}" | |
`cat #{JS.join(' ')} > #{JSPATH}` | |
end | |
directory BUILDDIR | |
rule '.js' => lambda { |objfile| find_source(objfile) } do |t| | |
Rake::Task[BUILDDIR].invoke | |
outfile = coffee_to_js(t.source) | |
mkdir_p File.dirname(outfile) | |
puts "#{t.source} -> #{outfile}" | |
f = open(outfile, 'w') | |
f.write(CoffeeScript.compile(open(t.source))) | |
f.flush | |
f.close | |
end | |
def find_source(objfile) | |
base = File.basename(objfile, '.js') | |
COFFEE.find { |s| File.basename(s, '.coffee') == base } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment