forked from cozy/cozy-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
111 lines (101 loc) · 4.21 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
101
102
103
104
105
106
107
108
109
110
111
{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 "test"
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']
env += " PORT=4444"
logger.info "Running tests with #{env}..."
command = "#{env} mocha " + files.join(" ") + " --reporter spec --colors "
command += "--globals setImmediate,clearImmediate "
command += "--compilers coffee:coffee-script/register"
exec command, (err, stdout, stderr) ->
console.log stdout
console.log stderr
if err
err = err
logger.error "Running mocha caught exception:\n" + err
process.exit 1
else
logger.info "Tests succeeded!"
process.exit 0
task "lint", "Run Coffeelint", ->
process.env.TZ = "Europe/Paris"
command = "coffeelint "
files = walk 'server/'
files = files.concat walk 'client/app', ['fr.coffee', 'en.coffee']
command += " -f coffeelint.json #{files.join ' '}"
logger.options.prefix = 'cake:lint'
logger.info 'Start linting...'
exec command, (err, stdout, stderr) ->
if err
logger.error err
else
logger.info stdout
buildJade = ->
jade = require 'jade'
jadeFile = new RegExp '\.jade$'
for file in fs.readdirSync './client/'when jadeFile.test file
filename = "./client/#{file}"
template = fs.readFileSync filename, 'utf8'
output = "var jade = require('jade/runtime');\n"
output += "module.exports = " + jade.compileClient template, {filename}
name = file.replace '.jade', '.js'
fs.writeFileSync "./build/client/#{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/mails/en && " + \
"rm -rf build/server/mails/fr && " + \
"mkdir build/server/mails/en && " + \
"mkdir build/server/mails/fr && " + \
"cp server/mails/fr/*.jade build/server/mails/fr/ && " + \
"cp server/mails/en/*.jade build/server/mails/en/ && " + \
"rm -rf build/client && mkdir build/client && " + \
"coffee -cb --output build/client/app/locales client/app/locales && " + \
"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
buildJade()
logger.info "Compilation succeeded."
process.exit 0