-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathCakeFile
82 lines (64 loc) · 1.84 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
### Build file for CoffeePhysics. ###
fs = require 'fs'
uglify = require 'uglify-js'
{exec, spawn} = require 'child_process'
config =
compiled: 'compiled'
deploy: 'deploy'
source: 'source'
output =
'physics': [
'base'
'math/Random'
'math/Vector'
'engine/Particle'
'engine/Spring'
'engine/Physics'
'engine/integrator/Integrator'
'engine/integrator/Euler'
'engine/integrator/ImprovedEuler'
'engine/integrator/Verlet'
'behaviour/Behaviour'
'behaviour/Attraction'
'behaviour/Collision'
'behaviour/ConstantForce'
'behaviour/EdgeBounce'
'behaviour/EdgeWrap'
'behaviour/Wander'
]
grr = (message = '') ->
options = {
title: 'CoffeeScript'
image: '/Users/justin/node_modules/growl/lib/CoffeeScript.png'
}
try require('growl')(message, options)
task 'watch', 'Watch & compile changes in source dir', ->
watch = exec "coffee -o #{config.compiled}/ -cwb #{config.source}/"
watch.stdout.on 'data', (data) ->
process.stdout.write data
#grr "#{data}"
task 'build', '', ->
for target, files of output
# Map filenames.
mapped = files.map (file) ->
file = "#{config.source}/#{file}.coffee"
# Concatenated file.
file = "#{config.deploy}/#{target}.js"
# Concatenate and compile.
exec "coffee -j #{file} -cb #{(mapped.join ' ')}"
console.log "coffee -j #{file} -cb #{(mapped.join ' ')}"
# Uglify.
jsp = uglify.parser
pro = uglify.uglify
fs.readFile file, 'utf8', (err, data) ->
# Parse code and get the initial AST.
ast = jsp.parse data
# Get a new AST with mangled names.
ast = pro.ast_mangle ast
# Get an AST with compression optimizations.
ast = pro.ast_squeeze ast
# Compressed code.
code = pro.gen_code ast
# Write to file.
fs.writeFile "#{config.deploy}/#{target}.min.js", code
grr "Minfied: #{config.deploy}/#{target}.min.js"