Skip to content
Browse files

first version of 'rake watch'

  • Loading branch information...
1 parent df0366b commit d1662e5874edde71d84c5e49e527c981658a3b12 @sdball sdball committed Feb 14, 2012
Showing with 28 additions and 0 deletions.
  1. +27 −0 Rakefile
  2. +1 −0 coffee/main.coffee
View
27 Rakefile
@@ -0,0 +1,27 @@
+require 'rake'
+require 'stringio'
+require 'coffee-script'
+
+desc "Watch coffee directory 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
+ update { |base, relative| recompile_coffee }
+ delete { |base, relative| recompile_coffee }
+ create { |base, relative| recompile_coffee }
+ end
+end
+
+def recompile_coffee
+ puts "Changes detected, recompiling"
+ code = StringIO.new
+ Dir.glob("coffee/**/*.coffee").each do |f|
+ code << IO.read(f)
+ end
+ f = File.new('main.js', 'w')
+ f.write CoffeeScript.compile code.string
+ f.close
+ puts "Recompiled."
+end
View
1 coffee/main.coffee
@@ -0,0 +1 @@
+alert('Hello from coffee-taster.')

0 comments on commit d1662e5

Please sign in to comment.
Something went wrong with that request. Please try again.