Skip to content

Instantly share code, notes, and snippets.

@ryankshaw
Created May 30, 2010 20:43
Show Gist options
  • Select an option

  • Save ryankshaw/419320 to your computer and use it in GitHub Desktop.

Select an option

Save ryankshaw/419320 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#this script assumes you use jammit (jammit.documentcloud.com) to bundle and compress all of your javascripts
require 'yaml'
require 'rubygems'
require 'tempfile'
verbose = ARGV.include?("-v")
config = YAML::load(IO.read(File.dirname(__FILE__) + '/config/assets.yml'))
common = config['javascripts']['common']
tempfile = Tempfile.new("closure_output.js").path
config['javascripts'].each do |group, filenames|
puts "compiling #{group}" if verbose
command = "java -jar path/to/closure-compiler-20100201.jar #{verbose ? "--warning_level VERBOSE" : "--warning_level QUIET"} --js #{(filenames).join(" --js ")} --externs a_file_where_you_put_all_your_external_variables_like_$.js --js_output_file #{tempfile} 2>&1"
output = `#{command}`
# the "X error(s), Y warning(s)" line will always be at the end
puts results = output.grep(/\d+ warning\(s\)/).to_s if verbose
puts output
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment