#!/usr/bin/python

import httplib, urllib, subprocess, sys, config

# Read all the Javascript files.
js_code = [('js_code', open(f).read()) for f in config.js_in_files]

# Read all the CSS files and concatenate them.
css_code = ''.join(open(f).read() for f in config.css_in_files)

# Define the parameters for the POST request and encode them in
# a URL-safe format.
params = urllib.urlencode(js_code + [
  ('language', 'ECMASCRIPT5'),
  ('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

if response.status != 200:
  print sys.stderr, "error returned from JS compile service: %d" % response.status
  sys.exit(1)

open(config.js_out_file, 'wt').write(data)
print 'Generated %s.  Check the file to see if errors occured!' % config.js_out_file

yuic_args = ['yui-compressor', '--type', 'css', '-o', config.css_out_file]
p = subprocess.Popen(yuic_args, stdin=subprocess.PIPE)
p.communicate(input=css_code)
if p.wait() != 0:
  print 'Failed to generate %s.' % config.css_out_file
  sys.exit(1)

print 'Generated %s.' % config.css_out_file

@@ -14,16 +14,19 @@
 thon
+2.6
 %0A%0Aimport
  htt
@@ -21,16 +21,24 @@
 %0A%0Aimport
+ config,
  httplib
@@ -38,16 +38,22 @@
 httplib,
+ json,
  urllib,
@@ -68,24 +68,16 @@
 ess, sys
-, config
 %0A%0A# Read
@@ -512,12 +512,41 @@
 ', '
-text
+json'),%0A  ('output_info', 'errors
 '),%0A
@@ -1019,113 +1019,441 @@
 1)%0A%0A
-open(config.js_out_file, 'wt').write(data)%0Aprint 'G
+result = json.loads(data)%0Aif 'errors' in result:%0A  for e in result%5B'errors'%5D:%0A    filenum = int(e%5B'file'%5D%5B6:%5D)%0A    filename = js_in_files%5Bfilenum%5D%0A    lineno = e%5B'lineno'%5D%0A    charno = e%5B'charno'%5D%0A    err = e%5B'error'%5D%0A    print '%25s:%25d:%25d: %25s' %25 (filename, lineno, charno, err)%0A  print 'Failed to g
 enerate
-d
  %25s.
-  Check the file to see if errors occured!
+' %25 config.js_out_file%0A  sys.exit(1)%0A%0Aopen(config.js_out_file, 'wt').write(result%5B'compiledCode'%5D + '%5Cn')%0Aprint 'Generated %25s
 ' %25 
@@ -1739,17 +1739,16 @@
 rated %25s
-.
 ' %25 conf

check for errors when compiling JS