This repository has been archived by the owner on Aug 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Cakefile
127 lines (115 loc) · 4.75 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{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", ['photo-set']
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 += " NAME=home TOKEN=token"
logger.info "Running tests with #{env}..."
command = "#{env} mocha " + files.join(" ") + " --reporter spec --colors "
command += "--globals encode,decode "
command += "--compilers coffee:coffee-script/register "
command += "--timeout 10000 " # longer timeout before test failure
exec command, (err, stdout, stderr) ->
console.log stdout
if err?
console.log "Running mocha caught exception:\n#{err}"
setTimeout (-> process.exit 1), 100
else if stderr?.length > 0
console.log "Errors output to stderr during tests:\n#{stderr}"
setTimeout (-> process.exit 1), 100
else
console.log "Tests 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
buildJade = ->
jade = require 'jade'
path = require 'path'
for file in fs.readdirSync './server/views/'
return unless path.extname(file) is '.jade'
filename = "./server/views/#{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/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/client/public && " + \
"mkdir -p build/client/public/ && " + \
"mkdir -p build/server/locales/ && " + \
# does not work when brunch is not launched
"cp -rf client/public/* build/client/public && " + \
"cp -rf server/locales/*.json build/server/locales && " + \
"mkdir -p build/server/views/"
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
SVGIMAGES = 'client/app/assets/img/apps'
task 'build-icons', "Sprite the icons in #{SVGIMAGES}", ->
try Iconizr = require 'iconizr'
catch err
return console.log """
iconizr is not compatible with node 4 and therefore not included
in dependencies. You need to run `npm install iconizr` before
using the `build-icons` script.
"""
out = 'client/app/assets/app-icons'
Iconizr.createIconKit SVGIMAGES, out,
render: css: true
, (err, result) ->
console.log err if err
console.log result