forked from cozy/cozy-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
100 lines (91 loc) · 3.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
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
{exec} = require 'child_process'
fs = require 'fs'
logger = require('printit')
date: false
prefix: 'cake'
option '-f', '--file [FILE*]' , 'List of test files to run'
option '-d', '--dir [DIR*]' , 'Directory of test files to run'
option '-e' , '--env [ENV]', 'Run tests with NODE_ENV=ENV. Default is test'
option '' , '--use-js', 'If enabled, tests will run with the built files'
options = # defaults, will be overwritten by command line options
file : no
dir : no
# Grab test files of a directory recursively
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
taskDetails = '(default: ./tests, use -f or -d to specify files and directory)'
task 'tests', "Run tests #{taskDetails}", (opts) ->
logger.options.prefix = 'cake:tests'
files = []
options = opts
if options.dir
dirList = options.dir
files = walk(dir, files) for dir in dirList
if options.file
files = files.concat options.file
unless options.dir or options.file
files = walk "tests"
env = if options['env'] then "NODE_ENV=#{options.env}" else "NODE_ENV=test"
env += " USE_JS=true" if options['use-js']? and options['use-js']
logger.info "Running tests with #{env}..."
command = "#{env} mocha " + files.join(" ") + " --reporter spec --colors "
command += "--compilers coffee:coffee-script/register"
exec command, (err, stdout, stderr) ->
console.log stdout
if err
console.log stderr
logger.error "Running mocha caught exception:\n" + err
setTimeout (=> process.exit 1), 10
else
logger.info "Tests succeeded!"
setTimeout (=> process.exit 0), 10
buildJade = ->
jade = require 'jade'
for file in fs.readdirSync './server/views/'
filename = "./server/views/#{file}"
template = fs.readFileSync filename, 'utf8'
output = """
var jade = require('jade/runtime');\n
module.exports = #{jade.compileClient template, {filename}}
"""
name = file.replace '.jade', '.js'
fs.writeFileSync "./build/server/views/#{name}", output
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/server/views && " + \
"mkdir build/server/views"
exec command, (err, stdout, stderr) ->
if err
console.log stderr
logger.error "An error has occurred while compiling:\n" + err
process.exit 1
else
buildJade()
logger.info "Compilation succeeded."
process.exit 0
task "lint", "Run Coffeelint", ->
process.env.TZ = "Europe/Paris"
command = "coffeelint "
command += " -f coffeelint.json -r server/"
logger.options.prefix = 'cake:lint'
logger.info 'Start linting...'
exec command, (err, stdout, stderr) ->
if err
logger.error err
else
console.log stdout