forked from dcodeIO/ClosureCompiler.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClosureCompiler.min.js
More file actions
11 lines (11 loc) · 3.23 KB
/
ClosureCompiler.min.js
File metadata and controls
11 lines (11 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
/*
ClosureCompiler.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
Released under the Apache License, Version 2.0
see: https://github.com/dcodeIO/ClosureCompiler.js for details
*/
(function(){function d(b){this.options="object"===typeof b&&b?b:{}}if("undefined"!=typeof window&&window.window||"function"!=typeof require)throw Error("ClosureCompiler.js can only be used within node.js");var l=require("path"),h=require("fs"),r=require("child_process"),t=require("bl");h.existsSync||(h.existsSync=l.existsSync);d.b=function(b,d,k){if(0>k.indexOf(d))throw"Illegal "+b+" value: "+d+" ("+k+" expected)";};d.JAVA_EXT="win32"==process.platform?".exe":"";d.getGlobalJava=function(){var b=null;
process.env.JAVA_HOME&&(b=l.join(process.env.JAVA_HOME,"bin","java"+d.JAVA_EXT),h.existsSync(b)||(b=null));b||(b="java");return b};d.getBundledJava=function(){return l.normalize(l.join(__dirname,"jre","bin","java"+d.JAVA_EXT))};d.testJava=function(b,d){r.exec('"'+b+'" -version',{},function(b,h,p){p+="";p.match(/1\.[7-8]+/)?d(!0,null):0<=p.indexOf('version "')?d(!1,Error("Not Java 7")):d(!1,b)})};d.compile=function(b,h,k,l){4>arguments.length&&(l=k,k=null);(new d(h)).compile(b,k,l)};d.prototype.compile=
function(b,q,k){function u(a,b,c,d){var e=t(),f=t();a=r.spawn(a,b,{d:[c||"ignore","pipe","pipe"]});a.stdout.pipe(e);a.stderr.pipe(f);a.on("exit",function(a,b){var c;a&&(c=Error(a),c.code=a,c.c=b);d(c,e,f)})}function p(a,b){u(a,b,q,function(a,b,c){0<b.length||0<c.length?k(c+"",b+""):k(a,null)})}3>arguments.length&&(k=q,q=null);for(var c={},g=Object.keys(this.options),a=0;a<g.length;a++)c[g[a].toLowerCase()]=this.options[g[a]];delete c.js;delete c.js_output_file;var a=c.Xms||null,e=c.Xmx||"1024m";delete c.Xms;
delete c.Xmx;var m=["-XX:+TieredCompilation"];a&&m.push("-Xms"+a);m.push("-Xmx"+e,"-jar",__dirname+"/compiler/compiler.jar");b instanceof Array||(b=[b]);for(a=0;a<b.length;a++){if("string"!=typeof b[a]||0<=b[a].indexOf('"'))throw Error("Illegal source file: "+b[a]);e=h.statSync(b[a]);if(!e.isFile())throw Error("Source file not found: "+b[a]);m.push("--js",b[a])}c.a||(c.a=[]);c.a instanceof Array||(c.a=[c.a]);g=[];for(a=0;a<c.a.length;a++){if("string"!=typeof c.a[a]||""==c.a[a])throw Error("Externs directive does not point to a file or directory: "+
c.a[a]);"node"==c.a[a].toLowerCase()&&(c.a[a]=__dirname+"/node_modules/closurecompiler-externs");e=h.statSync(c.a[a]);if(e.isDirectory())for(var n=h.readdirSync(c.a[a]),e=0;e<n.length;e++){var f=c.a[a]+"/"+n[e];h.statSync(f).isFile()&&".js"==l.extname(f).toLowerCase()&&g.push(f)}else if(e.isFile())g.push(c.a[a]);else throw Error("Externs file not found: "+c.a[a]);}delete c.externs;for(a=0;a<g.length;a++)m.push("--externs",g[a]);g=Object.keys(c);for(a=0;a<g.length;a++){n=g[a];f=c[g[a]];if(!/[a-zA-Z0-9_]+/.test(n))throw Error("Illegal option: "+
n);if(!0===f)m.push("--"+n);else if(!1!==f)for(f instanceof Array||(f=[f]),e=0;e<f.length;e++){if(!/[^\s]*/.test(f[e]))throw Error("Illegal value for option "+n+": "+f[e]);m.push("--"+n,f[e])}}d.testJava(d.getGlobalJava(),function(a){a?p(d.getGlobalJava(),m):d.testJava(d.getBundledJava(),function(a){if(a)p(d.getBundledJava(),m);else throw Error("Java is not available, neither the bundled nor a global one.");})})};d.prototype.toString=function(){return"ClosureCompiler"};module.exports=d})(this);