forked from evanw/rapt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·81 lines (66 loc) · 2 KB
/
build.py
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
#!/usr/bin/python
import os, sys, time, subprocess
release = 'release' in sys.argv
print
if release:
print 'mode: release (run once and compress)'
else:
print 'mode: debug (constantly monitor files)'
print ' use "python build.py release" to run once instead'
print
def foreground(command):
os.system(command)
def background(command):
subprocess.Popen(command, shell=True)
op = foreground if release else background
suffix = ' inline release' if release else ''
op('cd editor && python build.py' + suffix)
op('cd game && python build.py' + suffix)
def compile(a, b):
compile = ' '.join([
'java -jar ./closure_compiler/compiler.jar',
'--compilation_level ADVANCED_OPTIMIZATIONS',
# '--formatting PRETTY_PRINT',
'--externs ./closure_compiler/jquery-1.4.4.externs.js',
'--externs ./closure_compiler/jquery.mousewheel.externs.js',
'--externs ./closure_compiler/editor.externs.js',
'--externs ./closure_compiler/rapt.externs.js',
'--js "%s"',
'--js_output_file "%s"'
])
os.system(compile % (a, b))
print 'built %s (%.2f%%)' % (b, 100.0 * len(open(b).read()) / len(open(a).read()))
def copy(a, b):
os.system('cp "%s" "%s"' % (a, b))
print 'copied %s to %s' % (a, b)
js_op = compile if release else copy
sources = {
'./editor/www/editor.js': [js_op, './rails/public/javascripts/editor.js'],
'./game/www/rapt.js': [js_op, './rails/public/javascripts/rapt.js'],
'./editor/www/style.css': [copy, './rails/public/stylesheets/editor.css'],
'./game/www/style.css': [copy, './rails/public/stylesheets/game.css']
}
oldStat = None
def build():
global oldStat
newStat = stat()
for source in sources:
if oldStat and oldStat[source] == newStat[source]:
continue
operation, destination = sources[source]
operation(source, destination)
oldStat = newStat
def stat():
return dict((file, os.stat(file).st_mtime) for file in sources)
def monitor():
a = stat()
while True:
time.sleep(0.5)
b = stat()
if a != b:
a = b
build()
if __name__ == '__main__':
build()
if not release:
monitor()