-
Notifications
You must be signed in to change notification settings - Fork 28
/
Cakefile
55 lines (42 loc) · 1.58 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
fs = require 'fs'
path = require 'path'
{spawn, exec} = require 'child_process'
{DEBUG} = process.env
COFFEE_EXECUTABLE = require.resolve('coffee-script/bin/coffee')
# 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'
# Log a message with a color.
log = (message, color, explanation) ->
console.log color + message + reset + ' ' + (explanation or '')
# Build transformer from source.
build = (cb) ->
files = fs.readdirSync('./src')
.filter((f) -> /\.coffee$/.test(f))
.map(((f) -> path.basename(f, '.coffee')))
run 'mkdir', ['-p','bin', 'lib'], ->
compile files, 'src/', 'lib/', cb
compile = (srcFiles, srcDir, destDir, cb) ->
srcFilePaths = srcFiles.map (filename) -> path.join(srcDir, "#{filename}.coffee")
args = ['--bare', '-o', destDir, '--compile'].concat srcFilePaths
coffee args, cb
# Run CoffeeScript command
coffee = (args, cb) -> run COFFEE_EXECUTABLE, args, cb
run = (executable, args = [], cb) ->
console.log "#{path.basename executable} #{args.join(' ')}" if DEBUG
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(status) if typeof cb is 'function'
test = ->
run 'tap', ['test/*.coffee'], (status) ->
if status == 0
log 'pass', green
else
log 'fail', red
task 'build', 'build coffee-react from source', build
task 'test', 'test coffee-react', test