-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCakefile
100 lines (85 loc) · 3.45 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
94
95
96
97
98
99
100
fs = require 'fs'
{exec} = require 'child_process'
logger = require('printit')
date: false
prefix: 'cake'
option '-f' , '--file [FILE*]' , 'test file to run'
option '' , '--dir [DIR*]' , 'directory where to grab test files'
option '-e' , '--env [ENV]' , 'run with NODE_ENV=ENV. Default is test'
options = # defaults, will be overwritten by command line options
file : no
dir : no
# Grab test files of a directory
walk = (dir, excludeElements = []) ->
fileList = []
list = fs.readdirSync dir
if list
for file in list
if file and file not in excludeElements
filename = "#{dir}/#{file}"
stat = fs.statSync filename
if stat and stat.isDirectory()
fileList2 = walk filename, excludeElements
fileList = fileList.concat fileList2
else if filename.substr(-6) is "coffee"
fileList.push filename
return fileList
task 'tests', 'run server tests, ./test is parsed by default, otherwise use -f or --dir', (opts) ->
options = opts
testFiles = []
if options.dir
dirList = options.dir
testFiles = testFiles.concat walk dir for dir in dirList
if options.file
testFiles = testFiles.concat options.file
if not(options.dir or options.file)
testFiles = walk "tests"
runTests testFiles
runTests = (fileList) ->
# Prevent error if the user hasn't installed mocha globally
testCommand = "mocha --version"
exec testCommand, (err, stdout, stderr) ->
if err or stderr
command = "./node_modules/mocha/bin/mocha"
else
command = "mocha"
if options['env']
env = "NODE_ENV=#{options.env}"
else
env = "NODE_ENV=test"
console.log "Running tests with #{env}..."
command = "#{env} #{command}"
command += " #{fileList.join(" ")} "
command += " --reporter spec --require should --compilers coffee:coffee-script/register --colors"
exec command, (err, stdout, stderr) ->
console.log stdout
if err
console.log "Running mocha caught exception: \n" + err
task "lint", "Run coffeelint on source files", ->
lintFiles = walk '.', ['node_modules', 'tests']
# if installed globally, output will be colored
testCommand = "coffeelint -v"
exec testCommand, (err, stdout, stderr) ->
if err or stderr
command = "./node_modules/coffeelint/bin/coffeelint"
else
command = "coffeelint"
command += " -f coffeelint.json -r " + lintFiles.join " "
exec command, (err, stdout, stderr) ->
console.log stderr
console.log stdout
task 'build', 'Build CoffeeScript to Javascript', ->
logger.options.prefix = 'cake:build'
logger.info "Start compilation..."
command = "coffee -cb --output build/server server && " + \
"coffee -cb --output build/ server.coffee && " + \
"rm -rf build/client && mkdir build/client && " + \
"cd client/ && brunch build --production && cd .. && " + \
"cp -R client/public build/client/"
exec command, (err, stdout, stderr) ->
if err
logger.error "An error has occurred while compiling:\n" + err
process.exit 1
else
logger.info "Compilation succeeded."
process.exit 0