fs = require 'fs' {print} = require 'sys' {spawn, exec} = require 'child_process' sh = (command, callback) -> exec command, (err, stdout, stderr) -> if err console.error stderr callback err else callback() build = (watch, callback) -> if typeof watch is 'function' callback = watch watch = false options = ['-c', '-o', 'lib', 'src'] options.unshift '-w' if watch coffee = spawn 'coffee', options coffee.stdout.on 'data', (data) -> print data.toString() coffee.stderr.on 'data', (data) -> print data.toString() coffee.on 'exit', (status) -> callback?() if status is 0 task 'build', 'Compile CoffeeScript source files', -> sh "rm -rf lib", -> build -> console.log "ok" task 'watch', 'Recompile CoffeeScript source files when modified', -> build true