This repository has been archived by the owner on Jan 27, 2018. It is now read-only.
forked from dcodeIO/ClosureCompiler.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ClosureCompiler.min.js
11 lines (11 loc) · 2.84 KB
/
ClosureCompiler.min.js
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 c(b){this.options="object"==typeof b?b:{}}if("undefined"!=typeof window&&window.window||"function"!=typeof require)throw Error("ClosureCompiler.js can only be used within node.js");var h=require("path"),n=require("fs"),r=require("child_process");c.b=function(b,c,m){if(0>m.indexOf(c))throw"Illegal "+b+" value: "+c+" ("+m+" expected)";};c.JAVA_EXT="win32"==process.platform?".exe":"";c.getGlobalJava=function(){var b=null;process.env.JAVA_HOME&&(b=process.env.JAVA_HOME+h.sep+"bin"+
h.sep+"java"+c.JAVA_EXT,n.existsSync(b)||(b=null));b||(b="java");return b};c.getBundledJava=function(){return h.normalize(__dirname+h.sep+"jre"+h.sep+"bin"+h.sep+"java"+c.JAVA_EXT)};c.testJava=function(b,c){r.exec('"'+b+'" -version',{},function(b,h,d){0<=(""+d).indexOf('version "')?c(!0,null):c(!1,b)})};c.compile=function(b,h,m){(new c(h)).compile(b,m)};c.prototype.compile=function(b,p){function m(a,b){require("child_process").exec(a,{c:20971520},b)}function q(a,b){m('"'+a+'" '+b,function(a,b,c){0<
b.length||0<c.length?p(c+"",b+""):p(a,null)})}for(var d={},g=Object.keys(this.options),a=0;a<g.length;a++)d[g[a].toLowerCase()]=this.options[g[a]];delete d.js;delete d.js_output_file;var k='-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=n.statSync(b[a]);if(!e.isFile())throw Error("Source file not found: "+b[a]);k+=' --js "'+b[a]+'"'}d.a||(d.a=[]);d.a instanceof
Array||(d.a=[d.a]);for(var g=[],e,a=0;a<d.a.length;a++){if("string"!=typeof d.a[a]||""==d.a[a])throw Error("Externs directive does not point to a file or directory: "+d.a[a]);"node"==d.a[a].toLowerCase()&&(d.a[a]=__dirname+"/node_modules/closurecompiler-externs");e=n.statSync(d.a[a]);if(e.isDirectory()){var l=n.readdirSync(d.a[a]);for(e=0;e<l.length;e++){var f=d.a[a]+"/"+l[e];n.statSync(f).isFile()&&".js"==h.extname(f).toLowerCase()&&g.push(f)}}else if(e.isFile())g.push(d.a[a]);else throw Error("Externs file not found: "+
d.a[a]);}delete d.externs;for(a=0;a<g.length;a++)k+=' --externs "'+g[a]+'"';g=Object.keys(d);for(a=0;a<g.length;a++){l=g[a];f=d[g[a]];if(!/[a-zA-Z0-9_]+/.test(l))throw Error("Illegal option: "+l);if(!0===f)k+=" --"+l;else if(!1!==f){f instanceof Array||(f=[f]);for(e=0;e<f.length;e++){if(!/[^\s]*/.test(f[e]))throw Error("Illegal value for option "+l+": "+f[e]);k+=" --"+l+" "+f[e]}}}c.testJava(c.getGlobalJava(),function(a){a?q(c.getGlobalJava(),k):c.testJava(c.getBundledJava(),function(a){if(a)q(c.getBundledJava(),
k);else throw Error("Java is not available, neither the bundled nor a global one.");})})};c.prototype.toString=function(){return"ClosureCompiler"};module.exports=c})(this);