forked from jsdf/coffee-react-transform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
69 lines (55 loc) · 2.18 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
fs = require 'fs'
path = require 'path'
{spawn, exec} = require 'child_process'
# ANSI Terminal Colors.
bold = red = green = reset = ''
unless process.env.NODE_DISABLE_COLORS
bold = '\x1B[0;1m'
red = '\x1B[0;31m'
green = '\x1B[0;32m'
reset = '\x1B[0m'
SOURCEFILES = ['transformer', 'parser', 'serialiser', 'symbols', 'helpers']
TESTFILES = ['test.coffee','output-testcases.txt','eval-testcases.txt']
JSFILES = ['entitydecode.js', 'stringescape.js']
# Log a message with a color.
log = (message, color, explanation) ->
console.log color + message + reset + ' ' + (explanation or '')
# Build transformer from source.
build = (cb) ->
run 'mkdir', ['-p','bin', 'lib'], ->
compile SOURCEFILES, 'src/', 'lib/', ->
copy JSFILES, 'src/', 'lib/', cb
copy = (srcFiles, srcDir, destDir, cb) ->
files = srcFiles.map((filename) -> path.join(srcDir, filename))
run 'cp', files.concat([destDir]), cb
compile = (srcFiles, srcDir, destDir, cb) ->
args = [
'--bare',
'--output', destDir,
'--compile'
].concat srcFiles.map((filename) -> path.join(srcDir, "#{filename}.coffee"))
coffee args, cb
# Run CoffeeScript command
coffee = (args, cb) -> run './node_modules/.bin/coffee', args, cb
run = (executable, args = [], cb) ->
console.log(executable, args...)
proc = spawn executable, args
proc.stdout.on 'data', (buffer) -> log buffer.toString(), green
proc.stderr.on 'data', (buffer) -> log buffer.toString(), red
proc.on 'exit', (status) ->
cb() if typeof cb is 'function'
test = -> coffee ['test/test.coffee']
task 'build', 'build cjsx transformer from source', build
task 'test', 'run tests', -> build test
task 'watch', 'watch and build', ->
SOURCEFILES.forEach (sourcefile) ->
fs.watchFile "src/#{sourcefile}.coffee", interval: 1000, ->
run 'npm', ['run', 'prepublish'], ->
log 'rebuild complete', bold
log "watching..." , green
task 'watch:test', 'watch and run tests', ->
TESTFILES.forEach (testfile) ->
fs.watchFile "test/#{testfile}", interval: 1000, -> run 'npm', ['test']
SOURCEFILES.forEach (sourcefile) ->
fs.watchFile "src/#{sourcefile}.coffee", interval: 1000, -> run 'npm', ['test']
log "watching..." , green