-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cakefile
255 lines (186 loc) · 7.14 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
241
242
243
244
245
246
247
248
249
250
251
#
#
#
# Adapted from pwnall's dropship cakefile
#
#
#
async = require 'async'
{spawn, exec} = require 'child_process'
fs = require 'fs-extra'
glob = require 'glob'
log = console.log
path = require 'path'
remove = require 'remove'
coffeebin = "coffee" #"node_modules/coffee-script/bin/coffee"
# Node 0.6 compatibility hack.
unless fs.existsSync
fs.existsSync = (filePath) -> path.existsSync filePath
task 'build', ->
vendor ->
build()
task 'release', ->
vendor ->
build ->
release()
task 'vendor', ->
vendor()
task 'test', ->
build ->
test()
task 'clean', ->
clean()
release = (callback) ->
commands = []
commands.push "echo 'run: cd build/; python -m SimpleHTTPServer 8000'"
commands.push "cp lib/gg.js public/js/"
commands.push "cp build/js/prettify.js public/js/"
commands.push "cp lib/gg.css public/css/"
commands.push "cp -r build/vendor public/"
#commands.push "slimerjs vendor/js/rasterize.js http://localhost:8000/html/release.html docs/imgs/screenshot.png"
commands.push "slimerjs vendor/js/rasterize.js http://localhost:8000/html/gallery.html docs/imgs/screenshot.png"
async.forEachSeries commands, run, ->
callback() if callback
build = (callback) ->
create_build_dirs()
commands = []
commands.push 'toaster -dc'
commands.push 'ls build/compiled/*'
commands.push 'cp -r build/compiled/ build/js/'
# commands.push 'cp src/manifest.json build/'
commands.push 'cp -r src/html build/'
commands.push 'cp -r src/js build/'
commands.push 'cp -r src/data build/'
# TODO: consider optipng
#commands.push 'cp -r src/images build/'
compile_less commands
copy_vendor commands
#commands.push "#{coffeebin} --output build/js --compile src/gg/*.coffee"
commands.push "#{coffeebin} --output test/js --compile test/gg/*.coffee"
commands.push 'cp build/js/ggplotjs2.js lib/'
commands.push "./node_modules/browserify/bin/cmd.js -e lib/ggplotjs2.js > build/js/gg.js"
commands.push "echo 'compiled build/js/gg.js'"
# copy final sources into lib/
commands.push "cp build/js/gg.js lib/gg-client.js"
commands.push "cp build/js/gg.js lib/gg.js"
commands.push "cp build/js/ggplotjs2.js lib/gg-server.js"
commands.push "cp build/css/gg.css lib/"
async.forEachSeries commands, run, ->
callback() if callback
clean = (callback) ->
fs.remove 'build', ->
fs.remove 'test/js/*', ->
fs.remove 'release', ->
fs.remove 'lib/gg*.js', ->
callback() if callback
test = (callback) ->
commands = []
commands.push "node_modules/vows/bin/vows"
async.forEachSeries commands, run, ->
vendor = (callback) ->
dirs = ['vendor', 'vendor/js', 'vendor/less', 'vendor/font', 'vendor/tmp']
for dir in dirs
fs.mkdirSync dir unless fs.existsSync dir
downloads = [
# D3
['http://d3js.org/d3.v3.min.js', 'vendor/js/d3.min.js'],
# Zepto.js is a small subset of jQuery.
['http://code.jquery.com/jquery-1.9.0.min.js', 'vendor/js/jquery.min.js'],
# Humanize for user-readable sizes.
['https://raw.github.com/taijinlee/humanize/0a97f11503e3844115cfa3dc365cf9884e150e4b/humanize.js',
'vendor/js/humanize.js'],
# JSON2
['https://raw.github.com/douglascrockford/JSON-js/master/json2.js',
'vendor/js/json2.js'],
# underscore.js
['http://underscorejs.org/underscore-min.js', 'vendor/js/underscore.min.js'],
# FontAwesome for icons.
['https://github.com/FortAwesome/Font-Awesome/archive/v3.0.1.zip',
'vendor/tmp/font_awesome.zip'],
# SeedRandom (http://davidbau.com/archives/2010/01/30/random_seeds_coded_hints_and_quintillions.html)
['http://davidbau.com/encode/seedrandom.js', 'vendor/js/seedrandom.js'],
# rasterize for rendering html pages
["https://raw.github.com/ariya/phantomjs/master/examples/rasterize.js", "vendor/js/rasterize.js"],
# Require.js
#['http://requirejs.org/docs/release/2.1.5/minified/require.js', 'vendor/js/require.js'],
# science
["https://raw.github.com/jasondavies/science.js/master/science.v1.js", "vendor/js/science.js"]
]
async.forEachSeries downloads, download, ->
commands = []
# Minify humanize.
unless fs.existsSync 'vendor/js/humanize.min.js'
commands.push 'node_modules/uglify-js/bin/uglifyjs --compress ' +
'--mangle --output vendor/js/humanize.min.js vendor/js/humanize.js'
# Unpack fontawesome.
unless fs.existsSync 'vendor/tmp/Font-Awesome-3.0.1/'
commands.push 'unzip -qq -d vendor/tmp vendor/tmp/font_awesome'
# Patch fontawesome inplace.
commands.push 'sed -i -e "/^@FontAwesomePath:/d" ' +
'vendor/tmp/Font-Awesome-3.0.1/less/font-awesome.less'
async.forEachSeries commands, run, ->
commands = []
# Copy fontawesome to vendor/.
for inFile in glob.sync 'vendor/tmp/Font-Awesome-3.0.1/less/*.less'
outFile = inFile.replace /^vendor\/tmp\/Font-Awesome-3\.0\.1\/less\//,
'vendor/less/'
unless fs.existsSync outFile
commands.push "cp #{inFile} #{outFile}"
for inFile in glob.sync 'vendor/tmp/Font-Awesome-3.0.1/font/*'
outFile = inFile.replace /^vendor\/tmp\/Font-Awesome-3\.0\.1\/font\//,
'vendor/font/'
unless fs.existsSync outFile
commands.push "cp #{inFile} #{outFile}"
async.forEachSeries commands, run, ->
callback() if callback
create_build_dirs = ->
for dir in [
'build',
'build/data',
'build/compiled',
'build/css',
'build/font',
'build/html',
'build/images',
'build/js',
'build/vendor',
'build/vendor/font',
'build/vendor/js',
'test/js']
fs.mkdirSync dir unless fs.existsSync dir
compile_less = (commands) ->
# compile LESS
for inFile in glob.sync 'src/less/**/*.less'
continue if path.basename(inFile).match /^_/
outFile = inFile.replace(/^src\/less\//, 'build/css/').
replace(/\.less$/, '.css')
commands.push "node_modules/less/bin/lessc " +
"--strict-imports #{inFile} " +
"> #{outFile}"
copy_vendor = (commands) ->
for inFile in glob.sync 'vendor/js/*.js'
#continue if inFile.match /\.min\.js$/
outFile = 'build/' + inFile
commands.push "cp #{inFile} #{outFile}"
for inFile in glob.sync 'vendor/font/*'
outFile = 'build/' + inFile
commands.push "cp #{inFile} #{outFile}"
run = (args...) ->
for a in args
switch typeof a
when 'string' then command = a
when 'object'
if a instanceof Array then params = a
else options = a
when 'function' then callback = a
command += ' ' + params.join ' ' if params?
cmd = spawn '/bin/sh', ['-c', command], options
cmd.stdout.on 'data', (data) -> process.stdout.write data
cmd.stderr.on 'data', (data) -> process.stderr.write data
process.on 'SIGHUP', -> cmd.kill()
cmd.on 'exit', (code) -> callback() if callback? and code is 0
download = ([url, file], callback) ->
if fs.existsSync file
callback() if callback?
return
run "curl -L -o #{file} #{url}", callback