-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile
executable file
·41 lines (34 loc) · 1.07 KB
/
compile
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
#!/usr/bin/env python
import httplib, urllib, sys
def compile(code):
"""
Sends the JavaScript to the Google Closure compiler and returns
the transformed output.
"""
# Define the parameters for the POST request and encode them in
# a URL-safe format.
params = urllib.urlencode([
('js_code', code),
('compilation_level', 'SIMPLE_OPTIMIZATIONS'),
('output_format', 'text'),
('output_info', 'compiled_code'),
])
# Always use the following value for the Content-type header.
headers = { "Content-type": "application/x-www-form-urlencoded" }
conn = httplib.HTTPConnection('closure-compiler.appspot.com')
conn.request('POST', '/compile', params, headers)
response = conn.getresponse()
data = response.read()
conn.close()
return data
def main():
source = ""
sourcePath = './src/cobra.js'
file = open(sourcePath, 'r')
source += file.read()
file.close()
output = open('cobra.min.js', 'w')
output.write(compile(source))
output.close()
if __name__ == '__main__':
main()