UNPKG

836 BPlain TextView Raw
1fs = require 'fs'
2{print} = require 'sys'
3{spawn, exec} = require 'child_process'
4
5sh = (command, callback) ->
6 exec command, (err, stdout, stderr) ->
7 if err
8 console.error stderr
9 callback err
10 else
11 callback()
12
13build = (watch, callback) ->
14 if typeof watch is 'function'
15 callback = watch
16 watch = false
17 options = ['-c', '-o', 'lib', 'src']
18 options.unshift '-w' if watch
19
20 coffee = spawn 'coffee', options
21 coffee.stdout.on 'data', (data) -> print data.toString()
22 coffee.stderr.on 'data', (data) -> print data.toString()
23 coffee.on 'exit', (status) -> callback?() if status is 0
24
25task 'build', 'Compile CoffeeScript source files', ->
26 sh "rm -rf lib", ->
27 build ->
28 console.log "ok"
29
30task 'watch', 'Recompile CoffeeScript source files when modified', ->
31 build true