Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleanup Rakefile

  • Loading branch information...
commit 08116de4f8b9841f7db895671dcc3142d2417963 1 parent d6189b8
@sdball sdball authored
Showing with 21 additions and 6 deletions.
  1. +21 −6 Rakefile
View
27 Rakefile
@@ -2,27 +2,42 @@ require 'rake'
require 'stringio'
require 'coffee-script'
-desc "Watch coffee directory and regenerate JavaScript when files change."
+OUTPUT_JS = 'js/compiled.js'
+COFFEE_DIR = 'coffee'
+
+desc "Watch #{COFFEE_DIR} and regenerate JavaScript when files change."
task :watch do
require 'fssm'
require 'coffee-script'
- puts "Starting to watch CoffeeScript files in /coffee."
- FSSM.monitor("coffee", '**/*.coffee') do
+ puts "Watching CoffeeScript files in /#{COFFEE_DIR}."
+ compile_coffee
+ FSSM.monitor(COFFEE_DIR, '**/*.coffee') do
update { |base, relative| recompile_coffee }
delete { |base, relative| recompile_coffee }
create { |base, relative| recompile_coffee }
end
end
+desc "Recompile CoffeeScript (like rake watch, but just once)"
+task :recompile_coffee do
+ puts "Compiling CoffeeScript files in /#{COFFEE_DIR}"
+ compile_coffee
+ puts "Done. CoffeeScript compiled into #{OUTPUT_JS}"
+end
+
def recompile_coffee
puts "Changes detected, recompiling"
+ compile_coffee
+ puts "Recompiled."
+end
+
+def compile_coffee
code = StringIO.new
- Dir.glob("coffee/**/*.coffee").each do |f|
+ Dir.glob("#{COFFEE_DIR}/**/*.coffee").each do |f|
code << IO.read(f)
end
Dir.mkdir('js') unless Dir.exists? 'js'
- File.open('js/main.js', 'w') do |f|
+ File.open(OUTPUT_JS, 'w') do |f|
f.write CoffeeScript.compile code.string
end
- puts "Recompiled."
end
Please sign in to comment.
Something went wrong with that request. Please try again.