-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCakefile
240 lines (212 loc) · 6.58 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
require 'colors'
fs = require 'fs'
glob = require 'glob'
jade = require 'jade'
path = require 'path'
{exec, spawn} = require 'child_process'
{print} = require 'util'
Q = require 'q'
SPECTACULAR_ROOT = path.resolve __dirname
version = require('./package.json').version
badge = (str) -> " #{str.toUpperCase()} ".inverse
done = (str) -> '\n ' + badge('done').green + ' ' + str.yellow.bold
fail = (str) -> '\n ' + badge('error').red + ' ' + str
exeHandle = (p,f) ->
[p,f] = [f,p] if typeof p is 'function'
(err, stdout, stderr) ->
return p.reject stdout + err + stderr if err?
print stdout if stdout? and stdout.length > 0
f stdout
run = (command) -> ->
console.log " run #{command.cyan}"
defer = Q.defer()
exec command, exeHandle defer, -> defer.resolve()
defer.promise
globPath = (p) ->
defer = Q.defer()
glob p, (err, res) ->
return defer.reject err if err
defer.resolve res
defer.promise
globPaths= (globs) ->
Q.all(globPath p for p in globs).then (results) =>
paths = []
results.forEach (a) -> paths = paths.concat a
paths
compileTemplates = ->
globPaths([path.resolve SPECTACULAR_ROOT, 'templates/formatters/*.jade'])
.then (tpls) ->
res = ''
for p in tpls
n = p.split('/')
n = n[n.length - 1]
n = n.split('.')[0]
tpl = jade.compile(fs.readFileSync(p), client: true, compileDebug: false).toString()
res += "\nspectacular.templates['#{n}'] = #{tpl}\n"
res
compileSpectacularNode = ->
options = [
"--compile"
"--bare"
"--output"
"lib/"
"--join"
"lib/spectacular.js"
"src/extensions.coffee"
"src/module.coffee"
"src/utils.coffee"
"src/errors.coffee"
"src/mixins.coffee"
"src/factories.coffee"
"src/promises.coffee"
"src/examples.coffee"
"src/dom.coffee"
"src/runner.coffee"
"src/environment.coffee"
"src/matchers.coffee"
"src/formatters.coffee"
"src/formatters/console.coffee"
"src/formatters/console/*.coffee"
"src/reporters/console.coffee"
]
run("./node_modules/.bin/coffee #{options.join ' '}")()
compileBrowserPart = ->
options = [
"--compile"
"--bare"
"--output"
"lib/"
"--join"
"lib/browser_reporter.js"
"src/formatters/browser.coffee"
"src/formatters/browser/*.coffee"
"src/reporters/browser.coffee"
"src/reporters/browser/*.coffee"
"src/reporters/browser_bootstrap.coffee"
]
run("./node_modules/.bin/coffee #{options.join ' '}")()
compileNode = ->
compileSpectacularNode()
.then(compileBrowserPart)
.then ->
options = [
"--compile"
"--bare"
"--output"
"lib/"
"src/cli.coffee"
"src/server.coffee"
"src/spectacular_bin.coffee"
"src/spectacular_phantomjs.coffee"
"src/spectacular_slimerjs.coffee"
]
run("./node_modules/.bin/coffee #{options.join ' '}")()
.then(run "echo '#!/usr/bin/env node' > bin/spectacular")
.then(run "cat lib/spectacular_bin.js >> bin/spectacular")
.then(run "chmod +x bin/spectacular")
.then(run "rm lib/spectacular_bin.js")
compileTests = ->
options = [
"--compile"
"--output"
"docs/js/"
"--join"
"docs/js/specs.js"
"specs/support/factories/*.coffee"
"specs/support/matchers/*.coffee"
"specs/support/helpers/*.coffee"
"specs/units/*.coffee"
"specs/units/formatters/console/*.coffee"
"specs/units/formatters/browser/*.coffee"
]
run("./node_modules/.bin/coffee #{options.join ' '}")()
.then(run 'cp -r ./specs/support/fixtures ./docs/js')
compileBrowser = ->
options = [
"--compile"
"--output"
"docs/build/js"
"--join"
"docs/build/js/spectacular.js"
"src/extensions.coffee"
"src/module.coffee"
"src/utils.coffee"
"src/errors.coffee"
"src/mixins.coffee"
"src/factories.coffee"
"src/promises.coffee"
"src/examples.coffee"
"src/dom.coffee"
"src/runner.coffee"
"src/environment.coffee"
"src/matchers.coffee"
"src/formatters.coffee"
"src/formatters/console.coffee"
"src/formatters/console/*.coffee"
"src/formatters/browser.coffee"
"src/formatters/browser/*.coffee"
"src/reporters/console.coffee"
"src/reporters/browser.coffee"
"src/reporters/browser/*.coffee"
"src/reporters/browser_bootstrap.coffee"
]
run("./node_modules/.bin/coffee #{options.join ' '}")()
.then ->
compileTemplates()
.then (res) ->
fs.writeFileSync 'docs/build/js/templates.js', res
.then ->
opts = '-o docs/build/js/spectacular.min.js docs/build/js/spectacular.js'
run("./node_modules/.bin/uglifyjs #{opts}")()
.then ->
opts = '-o docs/build/js/templates.min.js docs/build/js/templates.js'
run("./node_modules/.bin/uglifyjs #{opts}")()
.then(compileTests)
.then(run "./node_modules/.bin/stylus css/spectacular.styl")
.then(run "cp css/spectacular.css docs/build/css/spectacular.css")
.then(run "cp vendor/source-map.js docs/build/vendor/source-map.js")
.then(run "cp vendor/source-map.min.js docs/build/vendor/source-map.min.js")
.then(run "cp vendor/snap.js docs/build/vendor/snap.js")
.then(run "cp vendor/jade.js docs/build/vendor/jade.js")
.then(run "cd ./docs/build; zip -r ../spectacular-#{version}.zip *")
.then(run """echo "---
title: ChangeLog
date: #{new Date()}
author: Cédric Néhémie <[email protected]>
template: page.jade
----" > docs/changelog.md""")
.then(run 'cat CHANGELOG.md | sed s/^#/##/ >> docs/changelog.md')
task 'compile', 'Compiles the project sources', ->
compileNode()
.then ->
console.log done 'Nodejs files compiled'
.fail (err) ->
console.log fail err
task 'build', 'Build the project for node and the browser with docs', ->
compileNode()
.then ->
console.log done 'Nodejs files compiled'
.then(compileBrowser)
.then ->
console.log done 'Browser files compiled and documentation ready for build'
.fail (err) ->
console.log fail err
task 'server', 'Compiles and run the server', ->
compileNode()
.then ->
exe = spawn './bin/spectacular', ['server', '--profile', '--coffee', 'specs/units/**/*.spec.*']
exe.stdout.on 'data', (data) -> print data.toString()
exe.stderr.on 'data', (data) -> print data.toString()
exe.on 'exit', (status) -> process.exit status
.fail (err) ->
console.log fail err
task 'phantomjs', 'Run specs on phantomjs', ->
compileNode()
.then(run './bin/spectacular phantomjs --coffee --profile specs/units/**/*.spec.*')
.fail (err) ->
console.log fail err
task 'slimerjs', 'Run specs on slimerjs', ->
compileNode()
.then(run './bin/spectacular slimerjs --coffee --profile specs/units/**/*.spec.*')
.fail (err) ->
console.log fail err