forked from twilson63/express-coffee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
52 lines (40 loc) · 1.56 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
fs = require 'fs'
{print} = require 'sys'
{spawn, exec} = require 'child_process'
# ANSI Terminal Colors
bold = '\033[0;1m'
green = '\033[0;32m'
reset = '\033[0m'
red = '\033[0;31m'
package = JSON.parse fs.readFileSync('./package.json')
testCmd = package.scripts.test
startCmd = package.scripts.start
log = (message, color, explanation) ->
console.log color + message + reset + ' ' + (explanation or '')
build = (watch, callback) ->
if typeof watch is 'function'
callback = watch
watch = false
options = ['-c', '-o', 'lib', 'src']
options.unshift '-w' if watch
coffee = spawn 'coffee', options
coffee.stdout.on 'data', (data) -> print data.toString()
coffee.stderr.on 'data', (data) -> log data.toString(), red
coffee.on 'exit', (status) -> callback?() if status is 0
spec = (callback) ->
options = ['spec', '--coffee']
spec = spawn 'jasmine-node', options
spec.stdout.on 'data', (data) -> print data.toString()
spec.stderr.on 'data', (data) -> log data.toString(), red
spec.on 'exit', (status) -> callback?() if status is 0
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 'docco', files
docco.stdout.on 'data', (data) -> print data.toString()
docco.stderr.on 'data', (data) -> log data.toString(), red
docco.on 'exit', (status) -> callback?() if status is 0
task 'build', ->
build -> log ":)", green
task 'spec', 'Run Jasmine-Node', ->
build -> spec -> log ":)", green