Skip to content

Instantly share code, notes, and snippets.

@fearofcode
Created August 15, 2011 02:11
Show Gist options
  • Save fearofcode/1145600 to your computer and use it in GitHub Desktop.
Save fearofcode/1145600 to your computer and use it in GitHub Desktop.
Sample script to call google closure
import dircache
import os
import os.path
import fnmatch
# change these as needed
js_dirs = ["js/", "js/lib/"]
output_file = "output.js"
jar_path = "lib/java/"
compilation_level = "ADVANCED_OPTIMIZATIONS"
# you generally shouldn't need to change any of this
js_ext = ".js"
def files(dir):
return filter(lambda f: f.endswith(js_ext), map(lambda f: dir + f, dircache.listdir(dir)))
def all_files():
lists = map(files, js_dirs)
return [item for sublist in lists for item in sublist]
cmd_prefix = "java -jar " + jar_path + "compiler.jar"
file_list = all_files()
js_file_str = ' '.join(map(lambda f: "--js " + f, file_list))
cmd = "%s --compilation_level %s %s --js_output_file %s" % (cmd_prefix, compilation_level, js_file_str, output_file)
print cmd
os.system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment