-
Notifications
You must be signed in to change notification settings - Fork 210
/
Cakefile
79 lines (65 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
71
72
73
74
75
76
77
78
79
{spawn, exec} = require 'child_process'
fs = require 'fs'
log = console.log
task 'build', ->
build()
task 'test', ->
vendor ->
build ->
token ->
run 'mocha --colors --require test/js/helper.js test/js/*test.js'
task 'webtest', ->
vendor ->
build ->
token ->
webFileServer = require './test/js/web_file_server.js'
webFileServer.openBrowser()
task 'docs', ->
run 'docco src/*.coffee'
task 'vendor', ->
vendor()
task 'token', ->
build ->
token ->
process.exit 0
build = (callback) ->
# Compile without --join for decent error messages.
run 'coffee --output tmp --compile src/*.coffee', ->
run 'coffee --output lib --compile --join dropbox.js src/*.coffee', ->
# Minify the javascript, for browser distribution.
run 'uglifyjs --no-copyright -o lib/dropbox.min.js lib/dropbox.js', ->
run 'coffee --output test/js --compile test/src/*.coffee',
callback
vendor = (callback) ->
# All the files will be dumped here.
unless fs.existsSync
fs.mkdirSync 'test/vendor'
# chai.js ships different builds for browsers vs node.js
download 'http://chaijs.com/chai.js', 'test/vendor/chai.js', ->
download 'http://sinonjs.org/releases/sinon.js', 'test/vendor/sinon.js', ->
download 'http://sinonjs.org/releases/sinon-ie.js',
'test/vendor/sinon-ie.js', callback
token = (callback) ->
TokenStash = require './test/js/token_stash.js'
tokenStash = new TokenStash
(new TokenStash()).get ->
callback() if callback?
run = (args...) ->
for a in args
switch typeof a
when 'string' then command = a
when 'object'
if a instanceof Array then params = a
else options = a
when 'function' then callback = a
command += ' ' + params.join ' ' if params?
cmd = spawn '/bin/sh', ['-c', command], options
cmd.stdout.on 'data', (data) -> process.stdout.write data
cmd.stderr.on 'data', (data) -> process.stderr.write data
process.on 'SIGHUP', -> cmd.kill()
cmd.on 'exit', (code) -> callback() if callback? and code is 0
download = (url, file, callback) ->
if fs.existsSync file
callback() if callback?
return
run "curl -o #{file} #{url}", callback