blob: 3d16d9651617b3709f55d9db7b4179a0d204a65d (
plain)
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
|
#!/usr/bin/env python
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# A python script that combines the javascript files needed by jstemplate into
# a single file.
import httplib
import urllib
srcs ="util.js jsevalcontext.js jstemplate.js exports.js".split()
out = "jstemplate_compiled.js"
# Wrap the output in an anonymous function to prevent poluting the global
# namespace.
output_wrapper = "(function(){%s})()"
# Define the parameters for the POST request and encode them in a URL-safe
# format. See http://code.google.com/closure/compiler/docs/api-ref.html for API
# reference.
params = urllib.urlencode(
map(lambda src: ('js_code', file(src).read()), srcs) +
[
('compilation_level', 'ADVANCED_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()
out_file = file(out, 'w')
out_file.write(output_wrapper % response.read())
out_file.close()
conn.close()
|