-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
93 lines (70 loc) · 2.35 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
fs = require 'fs'
{print} = require 'util'
{spawn, exec} = require 'child_process'
# ANSI Terminal Colors
bold = '\x1B[0;1m'
red = '\x1B[0;31m'
green = '\x1B[0;32m'
reset = '\x1B[0m'
pkg = JSON.parse fs.readFileSync('./package.json')
testCmd = pkg.scripts.test
startCmd = pkg.scripts.start
spawned_processes = []
cleanup = (e) ->
console.log e.message if e?.message?
while spawned_processes.length > 0
{spawned, command} = spawned_processes.shift()
spawned.kill()
console.log "Killed #{command}"
process.on 'SIGINT', cleanup
process.on 'exit', cleanup
process.on 'uncaughtException', cleanup
log = (message, color, explanation) ->
console.log color + message + reset + ' ' + (explanation or '')
spawn_with_stdout = (command, args, callback) ->
spawned = spawn command, args
spawned.stdout.pipe process.stdout
spawned.stderr.pipe process.stderr
if callback?
spawned.on 'exit', callback
spawned_processes.push {command, spawned}
spawned
# Compiles app.coffee and src directory to the app directory
build = (callback) ->
spawn_with_stdout 'coffee', ['-c','-b', '-o', 'app', 'src'], callback
# mocha test
test = (callback) ->
try
spawn_with_stdout 'mocha', [
'--compilers'
'coffee:coffee-script'
'--colors'
'--require'
'should'
'--require'
'./server'
], callback
catch err
log err.message, red
log 'Mocha is not installed - try npm install mocha -g', red
build_redis = (callback) ->
spawn_with_stdout 'make', ['-C', 'redis'], callback
run_redis = (callback) ->
build_redis (err) ->
if not err
spawn_with_stdout './redis/src/redis-server', ['--port', 6300], callback
task 'build', ->
build -> log "Built!", green
task 'test', 'Run Mocha tests', ->
build -> test -> log "Tests Complete!", green
task 'make-redis', 'Build the redis install', ->
build_redis -> log "Built redis!", green
task 'redis', 'Run the redis server', ->
run_redis -> log "Redis has finished", green
task 'go', 'Start dev server/compilation', ->
# watch_coffee
coffee = spawn_with_stdout 'coffee' , ['-c', '-b', '-w', '-o', 'app', 'src']
log 'Watching coffee files', green
# watch_js
spawn_with_stdout 'node', ['./node_modules/supervisor/lib/cli-wrapper.js','-w','app,views', '-e', 'js|jade', 'server']
log 'Watching js files and running server', green