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' +