forked from alexslade/bubbles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCakefile
More file actions
127 lines (108 loc) · 4.08 KB
/
Cakefile
File metadata and controls
127 lines (108 loc) · 4.08 KB
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
fs = require 'fs'
{exec} = require 'child_process'
jsdom = require 'jsdom'
path_to_bin = '/Users/franzseo/bin/'
closure_compiler = path_to_bin+'compiler.jar'
html_compressor = path_to_bin+'htmlcompressor.jar'
yui = path_to_bin+'yui.jar'
#BUGGY
minHtmlReplace = (infile,outfile) ->
jsdom.env({
html: fs.readFileSync(infile)
scripts: ['http://code.jquery.com/jquery-1.8.0.min.js']
done: (errors, window) ->
$ = window.$;
$('link').each((index, element) ->
elem = @
if $(elem).attr('min')
if $(elem).attr('min') is '__REMOVE__'
$(elem).remove()
else
console.log('link replace ')
console.log('href="'+$(elem).attr('href')+'"')
$(elem).attr('href', $(elem).attr('min'))
console.log('with ')
console.log('href="'+$(elem).attr('href')+'"')
$(elem).removeAttr('min')
)
$('script').each((index, element) ->
elem = @
if $(elem).attr('min')
console.log($(elem).attr('min'))
if $(elem).attr('min') is '__REMOVE__'
console.log('in remove!!!!!')
console.log('src="'+$(elem).attr('src')+'"')
$(elem).attr('src', $(elem).attr('min'))
$(elem).removeAttr('src')
$(elem).remove()
else
console.log('script replace ')
console.log('src="'+$(elem).attr('src')+'"')
$(elem).attr('src', $(elem).attr('min'))
console.log('with ')
console.log('src="'+$(elem).attr('src')+'"')
$(elem).removeAttr('min')
)
#remove coffee sources
$('script').each((index, element) ->
elem = @
$(elem).removeAttr('coffee')
)
source=window.document.doctype.toString()+window.document.innerHTML
#console.log(source)
fs.writeFile(outfile, source, (err) ->
if err
console.log(err)
else
console.log("index.html was saved")
)
})
r = []
collectCoffee= (infile) ->
jsdom.env({
html: fs.readFileSync(infile),
scripts: [
'http://code.jquery.com/jquery-1.8.0.min.js'
],
done: (errors, window) ->
r = []
$ = window.$;
$('script').each((index, element) ->
elem = @
if $(elem).attr('coffee')
r.push($(elem).attr('coffee'))
)
})
srcfiles = ["js/src/init.coffee","js/src/InGameObjects.coffee","js/src/Player.coffee","js/src/Explosion.coffee","js/src/Bullet.coffee","js/src/Enemy.coffee","js/src/runtime.coffee","js/src/helper.coffee","js/src/start.coffee"]
#coffee --watch --compile --output js/lib/ js/src/
task 'watch', 'watch and compile coffeescript', ->
exec 'coffee --watch --compile --output js/lib/ js/src/', (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
task 'compile', 'compile coffeescript', ->
exec 'coffee --compile --output js/lib/ js/src/', (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
task 'join', 'join & compile coffeescript', ->
#coff = r #collectCoffee('index.src.html')
#c_string=coff.join(' ')
exec 'coffee --join bubbles.js --compile '+srcfiles.join(' '), (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
#coffee --join bubbles.js --compile $srcfiles
task 'dev', 'set up dev envirement', ->
task 'minjs', 'closure compile the javascript', ->
exec 'java -jar "'+closure_compiler+'" --compilation_level SIMPLE_OPTIMIZATIONS --js js/lib/bubble.js --js_output_file js/lib/bubble.min.js', (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
task 'mincss', 'minify the css', ->
exec "java -jar #{yui} -o css/lib/main.min.css css/src/main.css", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
#task 'minhtml', 'minify the html', ->
# minHtmlReplace('index.src.html', 'index.html')
# exec "java -jar #{html_compressor} -o index.html index.src.html", (err, stdout, stderr) ->
# throw err if err
# console.log stdout + stderr
task 'build', 'build the app', ->
task 'publish', 'publish the app', ->