Add colored console output
This commit is contained in:
parent
1e3d236aed
commit
ff5757d187
|
|
@ -7,6 +7,7 @@ var UglifyJS = require("../tools/node");
|
|||
var sys = require("util");
|
||||
var yargs = require("yargs");
|
||||
var fs = require("fs");
|
||||
var colors = require("colors");
|
||||
|
||||
var ARGS = yargs
|
||||
.usage("$0 input1.js \n")
|
||||
|
|
@ -37,23 +38,23 @@ if (ARGS.h || ARGS.help) {
|
|||
var files = ARGS._.slice();
|
||||
if (files.length > 1) {
|
||||
sys.error("WARNING: expected only single input file. Processing file '" + files[0] + "' while the rest is ignored.");
|
||||
};
|
||||
}
|
||||
|
||||
if (ARGS.features === true) {
|
||||
sys.error("ERROR: empty set of features.");
|
||||
process.exit(1);
|
||||
};
|
||||
}
|
||||
|
||||
var features = ARGS.features.split(",");
|
||||
for (var i = 0; i < features.length; i++) {
|
||||
if (features[i] != "FNAMES" && features[i] != "ASTREL" && features[i] != "FSCOPE") {
|
||||
sys.error("WARNING: ignoring not supported feature '" + features[i] + "'.");
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
processFile(files[i], ARGS.print_ast, ARGS.features, ARGS.json_formatting, ARGS.skip_minified);
|
||||
};
|
||||
}
|
||||
|
||||
function stripInterpreter(code){
|
||||
if (code.slice(0,2) != "#!"){
|
||||
|
|
@ -69,14 +70,27 @@ function processFile(file, print_ast, features, json_formatting, skip_minified)
|
|||
code = fs.readFileSync(file, "utf-8");
|
||||
}
|
||||
catch (ex) {
|
||||
sys.error("ERROR: can't read file: " + file);
|
||||
sys.error("ERROR:".red + " can't read file '" + file + "'");
|
||||
return;
|
||||
}
|
||||
|
||||
//if it is a script, the UglifyJS parser will fail to parse it
|
||||
code = stripInterpreter(code);
|
||||
|
||||
var output = UglifyJS.extractFeatures(code, file, print_ast, features, skip_minified);
|
||||
|
||||
try {
|
||||
var output = UglifyJS.extractFeatures(code, file, print_ast, features, skip_minified);
|
||||
} catch (ex){
|
||||
if (ex instanceof UglifyJS.JS_Parse_Error){
|
||||
sys.error("ERROR: ".red + "cannot parse file '" + file + "'");
|
||||
} else if (ex instanceof UglifyJS.JS_Minified_Error){
|
||||
sys.error("WARN: ".yellow + "skipping minified file '" + file + "'");
|
||||
} else {
|
||||
sys.error("ERROR: ".red + "'" + file + "'" + e);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (output == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -88,13 +102,17 @@ function processFile(file, print_ast, features, json_formatting, skip_minified)
|
|||
//validate JSON
|
||||
try {
|
||||
JSON.parse(output);
|
||||
} catch (e) {
|
||||
} catch (e) {
|
||||
sys.error("ERROR: ".red + "output is not valid JSON " + "'" + file + "'");
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (removeWhitespace(output) != '{"query":[],"assign":[]}') {
|
||||
console.log(output);
|
||||
}
|
||||
sys.error("OK: ".green + "'" + file + "'");
|
||||
} else {
|
||||
sys.error("EMPTY: ".yellow + "'" + file + "'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,14 +58,14 @@ function replaceMangled(code, file) {
|
|||
return stream.toString();
|
||||
}
|
||||
|
||||
function JS_Minified_Error(message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
function extractFeatures(code, file, print_ast, features, skip_minified) {
|
||||
var toplevel;
|
||||
try {
|
||||
toplevel = parseFile(code, file);
|
||||
} catch (e) {
|
||||
console.warn("Cannot parse file: '%s'", file);
|
||||
return null;
|
||||
}
|
||||
|
||||
toplevel = parseFile(code, file);
|
||||
|
||||
extendAst(toplevel);
|
||||
|
||||
|
|
@ -74,8 +74,9 @@ function extractFeatures(code, file, print_ast, features, skip_minified) {
|
|||
}
|
||||
|
||||
if (skip_minified && isMinified(toplevel, code, file)){
|
||||
console.warn("Skipping minified file: '%s'", file);
|
||||
return null;
|
||||
throw new JS_Minified_Error("Skipping minified file");
|
||||
//console.warn("Skipping minified file: '%s'", file);
|
||||
//return null;
|
||||
}
|
||||
|
||||
var feature_outputter = new FeatureJsonOutputter();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@
|
|||
"acorn": "~0.6.0",
|
||||
"escodegen": "~1.3.3",
|
||||
"esfuzz": "~0.3.1",
|
||||
"estraverse": "~1.5.1"
|
||||
"estraverse": "~1.5.1",
|
||||
"colors": "~1.0.3"
|
||||
},
|
||||
"browserify": {
|
||||
"transform": [ "uglify-to-browserify" ]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user