-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCakefile
executable file
·89 lines (69 loc) · 2.85 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
fs = require 'fs'
path = require 'path'
coffee = require 'coffee-script'
{puts} = require 'util'
sourceDir = 'src'
targetDir = 'js'
mainFile = 'sai.coffee'
VERBOSE = true
inform = (msg) -> puts msg if VERBOSE
# this does a dependency-based topological sort of the different chart modules
tsort = (edges, callback) ->
ts = require('child_process').exec('tsort')
ts.stdout.on('data', callback)
ts.stdin.write(edges.join(' '))
ts.stdin.end()
gclosure = (dirs) ->
try
args = ["-jar", "compiler.jar", "--js", path.join(targetDir, "sai.js")]
for component in ['prims', 'plots', 'charts']
for d in dirs when d
filename = path.join(targetDir, d, "#{component#}.js")
try
fs.statSync filename
args.push "--js"
args.push filename
args.push("--js_output_file")
args.push("sai-min.js")
#args.push("--compilation_level")
#args.push("ADVANCED_OPTIMIZATIONS")
#args.push("--externs")
#args.push("externs.js")
gclosure = require('child_process').spawn("java", args)
gclosure.stderr.setEncoding('utf8')
gclosure.on(
'exit',
(code, signal) ->
if code
inform "Google Closure finished with code=#{code} and signal=#{signal}"
else
try
inform "built minified JS, size is " + fs.statSync('sai-min.js').size
catch err
puts "something went wrong: #{err}"
)
catch err
puts "Error generating minified JavaScript: #{err}"
task 'build', 'build Sai', ->
combine_and_minify = ->
# collect dependencies
dependencies = []
files = fs.readdirSync sourceDir
for file in files
stats = fs.statSync path.join(sourceDir, file)
if stats.isDirectory()
for dependency in fs.readFileSync(path.join(sourceDir, file, 'dependencies'), 'ascii').split(/\s+/)
if dependency
dependencies.push(dependency)
dependencies.push(file)
# sort the modules and then combine and minify them with Google Closure
tsort(dependencies, (data) ->
gclosure data.split(/\s+/)
)
compile_coffeescript = require('child_process').spawn("coffee", ['-o', targetDir, '-c', sourceDir])
compile_coffeescript.stderr.on('data', (data) -> puts data)
compile_coffeescript.on('exit', combine_and_minify)
task 'clean', 'clean up intermediate JS', ->
# sadly, fs.rmdir is non-recursive and fails if the directory isn't empty
rm = require('child_process').exec("rm -rf #{targetDir}")
rm.on('exit', -> inform 'cleaned')