-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmake.py
More file actions
51 lines (40 loc) · 1.49 KB
/
make.py
File metadata and controls
51 lines (40 loc) · 1.49 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
import os.path
import httplib
import urllib
import subprocess
def main():
# Get the dirname of the Simrou trunk
filename = os.path.realpath(__file__)
dirname = os.path.dirname(filename)
# Compile coffeescript to javascript
subprocess.call('coffee --output "%s/build" --compile "%s/src/simrou.coffee"' % (dirname, dirname), shell=True)
# Read the main javascript file
inputFile = open('%s/build/simrou.js' % dirname, 'r');
code = inputFile.read()
inputFile.close()
# Get the parameters ready
params = urllib.urlencode([
('js_code', code),
('compilation_level', 'SIMPLE_OPTIMIZATIONS'),
('output_info', 'compiled_code'),
('output_format', 'text'),
])
headers = { 'Content-type': 'application/x-www-form-urlencoded' }
# Send request to the Closure Compiler API
conn = httplib.HTTPConnection('closure-compiler.appspot.com')
conn.request('POST', '/compile', params, headers)
# Store the response in a variable
response = conn.getresponse()
compiledCode = response.read()
conn.close()
# Did an error occur? (= empty string got returned)
if not compiledCode.strip():
print 'Error'
# Save the uncompiled code instead
compiledCode = code
# Write the compiled data to the disc
outputFile = open('%s/build/simrou.min.js' % dirname, 'w')
outputFile.write(compiledCode)
outputFile.close()
if __name__ == '__main__':
main()