CakefileでCoffeeScriptをwatchするタスク。
色々なところから拝借したものだけど。
さくっと作ってプロジェクトで環境を共有したいときに。
(なんかそういう用のいいライブラリとかありそうだけど)
{spawn, exec} = require 'child_process'
option '-o', '--output [DIR]', 'Output directory.'
option '-t', '--target [DIR]', 'Watch target directory.'
stdout_handler = (data) ->
console.log data.toString().trim()
build = (watch, output, target) ->
console.log 'Watching coffee scripts'
options = ['-c', '-o', (output || 'js'), (target || '_src/coffee')]
if watch is true
options[0] = '-cw'
coffee = spawn 'coffee', options
coffee.stdout.on 'data', stdout_handler
task 'build', 'build the project', (watch) ->
build watch
task 'watch', 'watch for changes and rebuild', (options) ->
build true, options.output, options.target