From f444fb9e383ae7327d0a04e28f133335a82daf02 Mon Sep 17 00:00:00 2001 From: Matthew Beale Date: Fri, 29 Jul 2011 09:36:22 +0200 Subject: [PATCH] Add a `cake watch` task --- Cakefile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Cakefile b/Cakefile index 345876e..355ade6 100644 --- a/Cakefile +++ b/Cakefile @@ -15,15 +15,24 @@ run = (cmd, args, cb) -> process.exit(1) if status != 0 cb() if typeof cb is 'function' +coffescript_files = -> + 'coffee/' + file for file in (fs.readdirSync 'coffee') when file.match(/\.coffee$/) + # Build Chosen. Requires `coffee` and `uglifyjs`. # task 'build', 'build Chosen from source', build = (cb) -> - files = fs.readdirSync 'coffee' - files = ('coffee/' + file for file in files when file.match(/\.coffee$/)) - run 'coffee', ['-c', '-o', 'chosen'].concat(files), -> + run 'coffee', ['-c', '-o', 'chosen'].concat(coffescript_files()), -> cb() if typeof cb is 'function' unless process.env.MINIFY is 'false' for javascript in javascripts uglified = javascript.replace /\.js$/, '.min.js' run 'uglifyjs', ['-o', uglified, javascript], cb +task 'watch', 'watch coffee/ for changes and build Chosen', -> + console.log "Watching for changes in coffee/" + for file in coffescript_files() + fs.watchFile file, (curr, prev) -> + if +curr.mtime isnt +prev.mtime + console.log "Saw change in #{file}" + invoke 'build' +