-
Notifications
You must be signed in to change notification settings - Fork 3
/
Cakefile
51 lines (42 loc) · 1.75 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
fs = require 'fs'
{spawn, exec} = require 'child_process'
async = require('async')
build = (watch, callback) ->
if typeof watch is 'function'
callback = watch
watch = false
options = ['-c', '-o', 'lib', 'src']
options.unshift '-w' if watch
coffee = spawn 'node_modules/.bin/coffee', options
coffee.stdout.on 'data', (data) -> console.log data.toString()
coffee.stderr.on 'data', (data) -> console.log data.toString()
coffee.on 'exit', (status) -> callback?() if status is 0
buildTemplates = (callback) ->
eco = require 'eco'
compile = (name) ->
(callback) ->
fs.readFile "src/templates/#{name}.eco", "utf8", (err, data) ->
if err then callback err
else fs.writeFile "lib/templates/#{name}.js", "module.exports = #{eco.precompile(data)}", callback
async.parallel [
compile('resolver')
compile('cx.masq.masqd.plist')
], callback
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 'node_modules/.bin/docco', files
docco.stdout.on 'data', (data) -> console.log data.toString()
docco.stderr.on 'data', (data) -> console.log data.toString()
docco.on 'exit', (status) -> callback?() if status is 0
task 'build', 'Compile CoffeeScript source files', ->
build()
buildTemplates()
task 'watch', 'Recompile CoffeeScript source files when modified', ->
build true
task 'test', 'Run the Masq test suite', ->
build ->
process.env["NODE_ENV"] = "test"
{reporters} = require 'nodeunit'
process.chdir __dirname
reporters.default.run ['test']