forked from dgf/express-sequelize-session
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
50 lines (37 loc) · 1.59 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
fs = require 'fs'
{spawn} = require 'child_process'
mocha = './node_modules/mocha/bin/mocha'
lint = './node_modules/coffeelint/bin/coffeelint'
files = 'Cakefile coffeelint.opts coverage.js package.json ./src ./test'
# ANSI Terminal Colors
green = '\x1b[32m'
reset = '\x1b[0m'
red = '\x1b[31m'
log = (message, color) -> console.log color + message + reset
call = (name, options, callback) ->
proc = spawn name, options.split(' ')
proc.stdout.on 'data', (data) ->
str = data.toString()
str = str.substr(0, str.length - 1)
if str.length > 0 then console.log str
proc.stderr.on 'data', (data) ->
log data.toString(), red
proc.on 'exit', callback
# calls a process and redirects the stdout in to a file
callOUT = (file) -> (cmd, options, done) ->
logFile = fs.openSync file, 'w+', '660'
proc = spawn cmd, options.split(' '), stdio: ['ignore', logFile]
proc.stderr.on 'data', (data) -> console.log data.toString()
proc.on 'exit', (code, signal) ->
fs.closeSync logFile
done code, signal
build = (callback) -> call 'coffee', '-c -o lib src', callback
spec = (callback) -> call mocha, 'test/*.spec.coffee', callback
clint = (callback) -> call lint, '-f coffeelint.opts ' + files, callback
coverage = (callback) ->
callOUT('coverage.html') mocha, '--require coverage.js --reporter html-cov test/*.spec.coffee', callback
logSuccess = (status) -> log ":)", green if status is 0
task 'build', 'build coffee', -> build logSuccess
task 'coverage', 'run coverage', -> coverage logSuccess
task 'lint', 'run lint', -> clint logSuccess
task 'spec', 'run specifications', -> spec logSuccess