-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCakefile
58 lines (50 loc) · 1.78 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
fs = require 'fs'
util = require 'util'
{exec} = require 'child_process'
exit = process.exit
Q = require 'q'
option '-o', '--output [DIR]', 'directory for compiled code'
get_browser = ->
d = Q.defer()
browsers = ["sensible-browser", "xdg-open", "x-www-browser"]
browsers_q = browsers.map (browser) -> Q.nfcall(exec, "which #{browser}")
Q.allResolved(browsers_q).then (promises) ->
for promise in promises
if promise.isFulfilled()
browser = promise.valueOf()[0].replace(/\n$/, '')
d.resolve(browser)
return
d.reject()
d.promise
compile_library = (options) ->
dir = options.output or 'gen'
d = Q.nfcall(exec, "coffee -o #{dir}/ -c src/")
d.then (stdout, stderr) ->
util.log "Compiled HydrateJS into #{dir}/"
.fail (error) ->
util.error error
d
task 'build', 'build the main asset', (options) ->
compile_library(options).fail -> exit 1
task 'build:legacy-browser', 'build the main asset with legacy browser support', ->
util.error("This task isn't implemented yet. For now, define Array.prototype.indexOf and JSON.* methods manually")
exit 1
task 'test', 'execute tests', (options) ->
util.error("Use `npm test` to run unit tests")
exit 1
task 'test:prepare', 'prepare the main `npm test` task', (options) ->
compile_library(options).fail -> exit 1
task 'test:browser', 'execute tests in the browser', (options) ->
compile_library(options).then ->
get_browser().then (browser) ->
util.log "Executing `#{browser} spec/SpecRunner.html`"
Q.nfcall(exec, "#{browser} spec/SpecRunner.html").then (stdout, stderr) ->
util.log stdout
util.error stderr
.fail (err) ->
util.err err
.fail ->
util.err "Couldn't open browser; navigate to spec/SpecRunner.html"
exit 1
.fail ->
exit 1