Skip to content

Instantly share code, notes, and snippets.

@andrewschaaf
Created July 14, 2011 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewschaaf/1082926 to your computer and use it in GitHub Desktop.
Save andrewschaaf/1082926 to your computer and use it in GitHub Desktop.
fs = require 'fs'
{spawn, exec} = require 'child_process'
closureCompile = (mode, srcPath, destPath, callback = (->)) ->
modeArgs = {
pretty: ['--compilation_level', 'WHITESPACE_ONLY',
'--formatting', 'PRETTY_PRINT'],
simple: ['--compilation_level', 'SIMPLE_OPTIMIZATIONS'],
advanced: ['--compilation_level', 'ADVANCED_OPTIMIZATIONS'],
}[mode]
args = [
'/usr/bin/env',
'java',
'-jar', process.env['CLOSURE_JAR']
]
for x in modeArgs
args.push x
args.push '--create_source_map', "#{destPath}.mapping"
exec "cat #{srcPath} | /usr/bin/env #{args.join(' ')} > #{destPath}", (e, out, err) ->
if e
console.log out
console.log err
callback()
task 'build', () ->
# foo.js
exec "coffee -c .", () ->
# Got cores?
closureCompile 'pretty', 'foo.js', 'foo.pretty.js'
closureCompile 'simple', 'foo.js', 'foo.simple.js', () ->
closureCompile 'pretty', 'foo.simple.js', 'foo.simple.pretty.js'
closureCompile 'advanced', 'foo.js', 'foo.advanced.js', () ->
closureCompile 'pretty', 'foo.advanced.js', 'foo.advanced.pretty.js'
(function() {
var doubler, f, g;
doubler = function(x) {
return 2 * x;
};
g = function() {
return JSON.parse("Ceci n'est pas JSON");
};
f = function() {
var x, y;
x = 1 + 2 + 3;
y = 4 + g() + doubler(1);
return x + y;
};
if (typeof window !== "undefined" && window !== null) {
window.x = f();
} else {
exports.x = f();
}
}).call(this);
(function(){var b,a,c;b=function(a){return 2*a};c=function(){return JSON.parse("Ceci n'est pas JSON")};a=function(){return 6+(4+c()+b(1))};typeof window!=="undefined"&&window!==null?window.x=a():exports.x=a()}).call(this);
{
"version":2,
"file":"foo.simple.js.mapping",
"lineCount":1,
"lineMaps":["gCEBQBABA/ACA+ADECA/cCABABA/ACUBEBA/ACA9EFA/cCEBABUBQDU/A/!AUDA9A+EHA/cCEBABUBEBE/ACA+AEE/A9AGA/ACA+A7A/YKYBI+oDE9UEI8MFA7UHE/A6AJE/A4YLE/A2ANE/B/QA+Q/A/NA2B/K"],
"mappings":[[0,20,7],
[0,20,1,0],
[0,1,9],
[0,1,9],
[0,1,12],
[0,2,6,1],
[0,2,15,2],
[0,2,18,3],
[0,3,2],
[0,3,2,1],
[0,3,20,1],
[0,3,20],
[0,3,21,4],
[0,3,24],
[0,4,4],
[0,4,11],
[0,4,15,4],
[0,6,2],
[0,6,2,3],
[0,6,14,3],
[0,6,14],
[0,6,17],
[0,7,4],
[0,7,21],
[0,7,11,5],
[0,7,11,6],
[0,7,22],
[0,9,2],
[0,9,2,2],
[0,9,14,2],
[0,9,14],
[0,9,17],
[0,13,4],
[0,11,14,4],
[0,12,8],
[0,12,13],
[0,12,12,3],
[0,12,25],
[0,12,18,1],
[0,12,26],
[0,15,2],
[0,15,6],
[0,15,13,7],
[0,15,24],
[0,15,39,7],
[0,15,50],
[0,16,4,4],
[0,16,4,7],
[0,16,16],
[0,16,15,2],
[0,18,4,4],
[0,18,4,8],
[0,18,17],
[0,18,16,2],
[0,20,8],
],
"sources":["stdin"],
"names":["call","doubler","f","g","x","parse","JSON","window","exports"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment