Created
November 27, 2010 00:57
-
-
Save mcculloughsean/717422 to your computer and use it in GitHub Desktop.
Compiles coffeescripts to js in the background, preserving directory structure
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
# Run me with: | |
# $ watchr compile.watchr | |
# -------------------------------------------------- | |
# Rules | |
# -------------------------------------------------- | |
watch( '^Resources/cs/(.*\.coffee)' ) { |m| coffee m } | |
# -------------------------------------------------- | |
# Signal Handling | |
# -------------------------------------------------- | |
Signal.trap('INT' ) { abort("\n") } # Ctrl-C | |
Signal.trap('QUIT' ) { coffee everything } # Ctrl-\ | |
# -------------------------------------------------- | |
# Helpers | |
# -------------------------------------------------- | |
def coffee(*paths) | |
if paths[0].is_a?(Array) | |
paths = paths[0] | |
end | |
paths.each do |i| | |
if (i.is_a?(MatchData)) | |
input = i[0].to_s | |
output_dir = i[0].to_s | |
else | |
puts "#{i}\n" | |
input = i.clone | |
output_dir = i.clone | |
end | |
output_dir.sub!(/\/(\w*\.coffee)/, '') | |
output_dir.sub!(/cs/, 'js') | |
FileUtils.mkdir_p output_dir | |
run "coffee -c -o #{output_dir} #{input}" | |
end | |
end | |
def everything | |
scripts = Dir['Resources/cs/**/*.coffee'] | |
scripts.flatten | |
end | |
def run( cmd ) | |
puts cmd | |
puts system cmd | |
end |
I was using 0.9.4! Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The latest stable CoffeeScript (0.9.5 at this time) preserves the structure in
--watch
mode. Just tried it with the tree above:Give it a spin and if it still isn't working, post an issue on Github perhaps? I am sure it is can be fixed.