just-build
Version:
A simple task runner that doesn't bloat your package
49 lines (43 loc) • 1.71 kB
JavaScript
var ref = require('stream');
var Transform = ref.Transform;
var clr = require('./console-colors');
var ERROR_COLOR = clr.RED;
var WARNING_COLOR = clr.YELLOW + clr.BOLD;
var STDERR_COLOR = clr.LIGHT_RED;
var ColorTransform = (function (Transform) {
function ColorTransform (isStdErr) {
Transform.call(this, {});
this.isStdErr = isStdErr;
}
if ( Transform ) ColorTransform.__proto__ = Transform;
ColorTransform.prototype = Object.create( Transform && Transform.prototype );
ColorTransform.prototype.constructor = ColorTransform;
ColorTransform.prototype._transform = function _transform (chunk, encoding, callback) {
try {
if (chunk && chunk.toString) {
var ref =
typeof chunk === 'string' ?
[chunk, encoding] :
[chunk.toString("utf-8"), "utf-8"];
var strChunk = ref[0];
var strEnc = ref[1];
if (/error(\s|\:)/i.test(strChunk)) {
this.push(ERROR_COLOR+strChunk+clr.RESET, strEnc);
} else if (/warning(\s|\:)/i.test(strChunk)) {
this.push(WARNING_COLOR+strChunk+clr.RESET, strEnc);
} else if (this.isStdErr) {
this.push(STDERR_COLOR+strChunk+clr.RESET, strEnc);
} else {
this.push(chunk, encoding);
}
} else {
this.push(chunk, encoding);
}
} catch(err) {
this.push(chunk, encoding);
}
callback();
};
return ColorTransform;
}(Transform));
module.exports = { ColorTransform: ColorTransform };