forked from maxtaco/node-framed-msgpack-rpc
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Cakefile
59 lines (52 loc) · 1.7 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
{spawn, exec} = require 'child_process'
fs = require 'fs'
path = require 'path'
LIB = "lib/"
task 'build', 'build the whole jam', (cb) ->
console.log "Building"
files = fs.readdirSync 'src'
files = ('src/' + file for file in files when file.match(/\.iced$/))
await clearLibJs defer()
await runIced [ '-I', 'node', '-c', '-o', LIB ].concat(files), defer()
await writeVersion defer()
console.log "Done building."
cb() if typeof cb is 'function'
runIced = (args, cb) ->
proc = spawn 'node_modules/.bin/iced', args
proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
proc.stdout.on 'data', (buffer) -> console.log buffer.toString().trim()
await proc.on 'exit', defer status
process.exit(1) if status != 0
cb()
clearLibJs = (cb) ->
files = fs.readdirSync 'lib'
files = ("lib/#{file}" for file in files when file.match(/\.js$/))
fs.unlinkSync f for f in files
cb()
task 'test', "run the test suite", (cb) ->
await runIced [ "test/all.iced"], defer()
cb() if typeof cb is 'function'
task 'vtest', "run the test suite, w/ verbosity", (cb) ->
await runIced [ "test/all.iced", '-d'], defer()
cb() if typeof cb is 'function'
writeVersion = (cb) ->
infile = "package.json"
stem = "version.js"
outfile = path.join LIB, stem
await fs.readFile infile, defer err, data
ok = false
if err
console.log "Error reading #{infile}: #{err}"
else
try
obj = JSON.parse data
v = obj.version
code = "exports.version = \"#{v}\";"
await fs.writeFile outfile, code, defer err
if err
console.log "Error writing #{outfile}: #{err}"
else
ok = true
catch e
console.log "JSON parse error: #{e}"
cb ok