Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

cleanup Rakefile

  • Loading branch information...
commit 08116de4f8b9841f7db895671dcc3142d2417963 1 parent d6189b8
Stephen Ball sdball authored

Showing 1 changed file with 21 additions and 6 deletions. Show diff stats Hide diff stats

  1. +21 6 Rakefile
27 Rakefile
@@ -2,27 +2,42 @@ require 'rake'
2 2 require 'stringio'
3 3 require 'coffee-script'
4 4
5   -desc "Watch coffee directory and regenerate JavaScript when files change."
  5 +OUTPUT_JS = 'js/compiled.js'
  6 +COFFEE_DIR = 'coffee'
  7 +
  8 +desc "Watch #{COFFEE_DIR} and regenerate JavaScript when files change."
6 9 task :watch do
7 10 require 'fssm'
8 11 require 'coffee-script'
9   - puts "Starting to watch CoffeeScript files in /coffee."
10   - FSSM.monitor("coffee", '**/*.coffee') do
  12 + puts "Watching CoffeeScript files in /#{COFFEE_DIR}."
  13 + compile_coffee
  14 + FSSM.monitor(COFFEE_DIR, '**/*.coffee') do
11 15 update { |base, relative| recompile_coffee }
12 16 delete { |base, relative| recompile_coffee }
13 17 create { |base, relative| recompile_coffee }
14 18 end
15 19 end
16 20
  21 +desc "Recompile CoffeeScript (like rake watch, but just once)"
  22 +task :recompile_coffee do
  23 + puts "Compiling CoffeeScript files in /#{COFFEE_DIR}"
  24 + compile_coffee
  25 + puts "Done. CoffeeScript compiled into #{OUTPUT_JS}"
  26 +end
  27 +
17 28 def recompile_coffee
18 29 puts "Changes detected, recompiling"
  30 + compile_coffee
  31 + puts "Recompiled."
  32 +end
  33 +
  34 +def compile_coffee
19 35 code = StringIO.new
20   - Dir.glob("coffee/**/*.coffee").each do |f|
  36 + Dir.glob("#{COFFEE_DIR}/**/*.coffee").each do |f|
21 37 code << IO.read(f)
22 38 end
23 39 Dir.mkdir('js') unless Dir.exists? 'js'
24   - File.open('js/main.js', 'w') do |f|
  40 + File.open(OUTPUT_JS, 'w') do |f|
25 41 f.write CoffeeScript.compile code.string
26 42 end
27   - puts "Recompiled."
28 43 end

0 comments on commit 08116de

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