Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tnhu/331920 to your computer and use it in GitHub Desktop.
Save tnhu/331920 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import httplib, urllib, sys
import os
import fnmatch
def googleClosureCompiler(rpath, wpath):
f = open(rpath, 'r')
s = f.readlines()
s = "".join(s);
f.close()
params = urllib.urlencode([
('js_code', s),
('compilation_level', 'SIMPLE_OPTIMIZATIONS'),
('output_format', 'text'),
('output_info', 'compiled_code'),
])
f.close();
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
f = open(wpath, 'w')
f.write(data)
f.close()
for top, dirs, files in os.walk('YOUR-JAVASCRIPT-FOLDER'):
for nm in fnmatch.filter(files, '*.js'):
s = os.path.join(top, nm)
if s.find('/test/') == -1: # Ignore /test folder
googleClosureCompiler(s, s.replace('.js', '.min.js'))
@knyga
Copy link

knyga commented Jan 7, 2014

You better use kjscompiler - makes compilation of multiple JavaScript files with Google Closure Compiler application in right order.
https://github.com/knyga/kjscompiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment