-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathCakefile
104 lines (86 loc) · 3.03 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
# Build script adpated from http://github.com/jashkenas/coffee-script/Cakefile
# ==============================================================================
fs = require 'fs'
sys = require 'sys'
CoffeeScript = require 'coffee-script'
{helpers} = require 'coffee-script/lib/helpers'
{spawn, exec} = require 'child_process'
# ANSI terminal colors.
red = '\033[0;31m'
green = '\033[0;32m'
reset = '\033[0m'
# Commands
compressionCmd = 'java -jar ./lib/compiler.jar --js unveil.js --js_output_file unveil.min.js'
# Unveil.js source files
files = [
'src/intro.js'
'src/uv.js'
'src/scene/matrix.js'
'src/scene/actor.js'
'src/scene/traverser.js'
'src/scene/behaviors.js'
'src/scene/display.js'
'src/scene/commands.js'
'src/scene/scene.js'
'src/scene/tween.js'
'src/scene/actors/rect.js'
'src/scene/actors/label.js'
'src/scene/actors/circle.js'
'src/scene/actors/path.js'
'src/outro.js'
]
# Run a CoffeeScript through the node/coffee interpreter.
run = (args) ->
proc = spawn 'bin/coffee', args
proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
proc.on 'exit', (status) -> process.exit(1) if status != 0
# Log a message with a color.
log = (message, color, explanation) ->
console.log "#{color or ''}#{message}#{reset} #{explanation or ''}"
# Build from source
build = ->
content = ''
content += fs.readFileSync(file)+'\n' for file in files
fs.writeFileSync('./unveil.js', content, encoding='utf8')
# Watch a source file for changes
watch = (file) ->
fs.watchFile file, {persistent: true, interval: 300}, (curr, prev) ->
return if curr.mtime.getTime() is prev.mtime.getTime()
build()
log "Sucessfully rebuilt ./unveil.js at #{curr.mtime}", green
task 'build:continuously', 'Build continuously (during development)', ->
watch(file) for file in files
task 'build', 'Rebuild from source', ->
build()
log 'Sucessfully built ./unveil.js', green
task 'build:full', 'Rebuild and create a compressed version', ->
build()
exec compressionCmd, (err, stdout, stderr) ->
throw err if err
log 'Sucessfully built ./unveil.js and ./unveil.min.js', green
task 'test', 'run the test suite', ->
helpers.extend global, require 'assert'
passedTests = failedTests = 0
startTime = new Date
originalOk = ok
helpers.extend global, {
ok: (args...) -> passedTests += 1; originalOk(args...)
CoffeeScript: CoffeeScript
}
process.on 'exit', ->
time = ((new Date - startTime) / 1000).toFixed(2)
message = "passed #{passedTests} tests in #{time} seconds#{reset}"
if failedTests
log "failed #{failedTests} and #{message}", red
else
log message, green
fs.readdir 'test', (err, files) ->
files.forEach (file) ->
return unless file.match(/\.coffee$/i)
fileName = path.join 'test', file
fs.readFile fileName, (err, code) ->
try
CoffeeScript.run code.toString(), {fileName}
catch err
failedTests += 1
log "failed #{fileName}", red, '\n' + err.stack.toString()