From 264ca302a92cf3f8c21e1b8d899e3082451ebaec Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sat, 18 Jun 2011 14:41:09 +0100 Subject: add a command to closure compile javascripts --- jarmonbuild/commands.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/jarmonbuild/commands.py b/jarmonbuild/commands.py index 0be6cf0..2fb2a00 100644 --- a/jarmonbuild/commands.py +++ b/jarmonbuild/commands.py @@ -8,6 +8,8 @@ import logging import os import shutil import sys +import httplib +import urllib from optparse import OptionParser from subprocess import check_call, PIPE @@ -15,6 +17,9 @@ from tempfile import gettempdir from urllib2 import urlopen from zipfile import ZipFile, ZIP_DEFLATED +from lxml.cssselect import CSSSelector +from lxml import html + import pkg_resources @@ -261,11 +266,53 @@ class BuildTestDataCommand(BuildCommand): my_rrd.update() +class BuildJavascriptDependenciesCommand(BuildCommand): + """ + Export all source files, generate apidocs and create a zip archive for + upload to Launchpad. + """ + + command_name = 'jsdeps' + + def main(self, argv): +# workingbranch_dir = self.workingbranch_dir + build_dir = self.build_dir + + self.log.debug('Compiling javascript dependencies') + + # Define the parameters for the POST request and encode them in + # a URL-safe format. + sel = CSSSelector('script') + doc = html.parse(os.path.join(self.workingbranch_dir, 'docs/examples/index.html')) + external_scripts = [src for src in [ + e.get('src', '') for e in sel(doc)] if src.startswith('http')] + + params = [('code_url', src) for src in external_scripts] + [ + ('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', urllib.urlencode(params), headers) + response = conn.getresponse() + with open(os.path.join(build_dir, 'dependencies.js'), 'w') as f: + for param in params: + f.write('// %s: %s\n' % param) + f.write(response.read()) + + conn.close + + + # The available subcommands SUBCOMMAND_HANDLERS = [ BuildApidocsCommand, BuildReleaseCommand, BuildTestDataCommand, + BuildJavascriptDependenciesCommand, ] -- cgit v1.1-4-g5e80