From 9d013a10af0e9842ce1e9913ee475f0f91420e05 Mon Sep 17 00:00:00 2001 From: Pavol Bielik Date: Mon, 26 Jan 2015 21:31:12 +0100 Subject: [PATCH] Add support for colored output (disabled by default) --- bin/unuglifyjs | 24 +++++++++++++++++++++++- package.json | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/bin/unuglifyjs b/bin/unuglifyjs index 34b3736e..16405699 100755 --- a/bin/unuglifyjs +++ b/bin/unuglifyjs @@ -7,7 +7,6 @@ var UglifyJS = require("../tools/node"); var sys = require("util"); var yargs = require("yargs"); var fs = require("fs"); -var colors = require("colors"); var http = require('http'); var ARGS = yargs @@ -23,6 +22,7 @@ var ARGS = yargs "FNAMES - function names to internal calls,\n" + "FSCOPE - add variable scope constraints.") .describe("package", "Build itself (UnuglifyJS) as a library") + .describe("colored", "Add colors to the output") .describe("V", "Print version number and exit.") //.demand(1) .alias("V", "version") @@ -36,6 +36,7 @@ var ARGS = yargs .boolean("nice_formatting") .boolean("package") .boolean("V") + .boolean("colors") .string("features") .string("nice2predict_server") .wrap(80) @@ -49,6 +50,27 @@ var ARGS = yargs normalize(ARGS); +if (ARGS.colors){ + require("colors"); +} else { + // in case we dont use colors simply return the string + var addProperty = function (color, func) { + String.prototype.__defineGetter__(color, func); + }; + + addProperty('red', function () { + return this; + }); + + addProperty('green', function () { + return this; + }); + + addProperty('yellow', function () { + return this; + }); +} + if (ARGS.version || ARGS.V) { var json = require("../package.json"); sys.puts(json.name + ' ' + json.version); diff --git a/package.json b/package.json index e3ac8d4d..73096be0 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "JavaScript tool that renames variables and parameters to names based on statistical model learnt from thousands of open source projects", "homepage": "https://github.com/eth-srl/UnuglifyJS", "main": "tools/node.js", - "version": "0.9.1", + "version": "0.9.2", "engines": { "node" : ">=0.4.0" }, "maintainers": [{ "name": "Pavol Bielik",