-
Notifications
You must be signed in to change notification settings - Fork 39
/
Cakefile
71 lines (58 loc) · 2.19 KB
/
Cakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
fs = require 'fs'
{print} = require 'sys'
child_process = require 'child_process'
watchit = require 'watchit'
_ = require 'underscore'
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
runTests = ->
suite?.kill()
suiteNames = [
'integration'
]
suiteIndex = 0
do runNextTestSuite = ->
return unless suiteName = suiteNames[suiteIndex]
suite = spawn "coffee", ["-e", "{reporters} = require 'nodeunit'; reporters.default.run ['#{suiteName}.coffee']"], cwd: 'test'
suite.stdout.on 'data', (data) -> print data.toString()
suite.stderr.on 'data', (data) -> print data.toString()
suite.on 'exit', -> suiteIndex++; runNextTestSuite()
invoke 'docs' # lest I forget
spawn = ->
arguments[0] += '.cmd' if process.platform is 'win32'
child_process.spawn.apply(child_process, arguments)
task 'docs', 'Generate annotated source code with Docco', ->
fs.readdir 'src', (err, contents) ->
files = ("src/#{file}" for file in contents when /\.coffee$/.test file)
docco = spawn 'docco', files
docco.stdout.on 'data', (data) -> print data.toString()
docco.stderr.on 'data', (data) -> print data.toString()
docco.on 'exit', (status) -> callback?() if status is 0
task 'build', 'Compile CoffeeScript source files', ->
build()
task 'watch', 'Recompile CoffeeScript source files when modified', ->
build true
task 'test', 'Run the test suite once.', ->
build runTests
task 'testwatch', 'Run the test suite (and re-run if anything changes)', ->
suite = null
build ->
runTests()
watchTargets = (targets..., callback) ->
for target in targets
watchit target, include: true, (event) ->
callback() unless event is 'success'
watchTargets 'src', do ->
_.debounce ->
build runTests
, 25
watchTargets 'test', 'Cakefile', do ->
_.debounce runTests, 25