forked from amir20/phantomjs-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
57 lines (44 loc) · 1.46 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
{spawn} = require 'child_process'
Promise = require 'bluebird'
bin = "./node_modules/.bin"
sh = "/bin/sh"
_runCmd = (prev, current) ->
prev.then ->
new Promise (resolve, reject) ->
args = ['-c', current]
child = spawn sh, args, {stdio: 'inherit'}
child.on 'error', reject
child.on 'exit', (code) ->
if (code or 0) is 0 then resolve() else reject()
run = (cmds...) ->
seq = cmds.reduce _runCmd, Promise.resolve()
seq.error (err) -> console.log 'Failed.', err
cleanup = ->
run "rm -rf .test .shim.js"
exit = (code = 0) ->
process.exit code
callbacks =
success: -> console.log 'Great Success!'
error: -> console.error 'Task failed.'
option '', '--test-regex [TEST_RE]', 'Run tests matching TEST_RE.'
task "clean", "cleanup build and test artifacts", ->
cleanup().then -> console.log 'All clean.'
task "build", "coffee-compile and browserify phantom", ->
run(
"#{bin}/coffee -c phantom.coffee"
"#{bin}/browserify -t coffeeify shim.coffee -o .shim.js"
"cat pre_shim.js .shim.js > shim.js"
)
.then(callbacks.success, callbacks.error)
.finally cleanup
task "test", "run phantom's unit tests", (options) ->
invoke('build').then ->
batch = run(
"#{bin}/coffee -o .test -c test/*.coffee"
"cp test/*.gif test/*.js .test/"
"#{bin}/vows --spec .test/#{options['test-regex'] ? '*'}.js"
)
batch
.then(callbacks.success, callbacks.error)
.then(cleanup)
.catch -> exit(1)