diff --git a/lib/index.js b/lib/index.js index 19d4c85..cdf2b52 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,6 @@ 'use strict'; +var path = require("path"); var chalk = require("chalk"); var spy = require("through2-spy"); var fancyLog = require("fancy-log"); @@ -13,7 +14,19 @@ var typeColors = { debug: "gray" }; +function hexify(buff) { + var bytes = []; + + for (var i = 0; i < buff.length; i++) { + bytes.push(buff.toString("hex", i, i + 1)); + } + + return bytes; +} + module.exports = function namedLog(name) { + var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + var prefix = "[" + chalk.green(name) + "]"; function createLog(type) { @@ -45,7 +58,27 @@ module.exports = function namedLog(name) { var _this = this; return spy.obj(function (file) { - _this.info(file.path, file.contents); + var shortPath = void 0, + firstBytes = void 0, + suffix = void 0; + + var byteLimit = options.byteLimit != null ? options.byteLimit : 20; + + if (options.basePath != null) { + shortPath = path.relative(options.basePath, file.path); + } else { + shortPath = path.basename(file.path); + } + + if (file.contents.length <= byteLimit) { + firstBytes = file.contents; + suffix = ""; + } else { + firstBytes = file.contents.slice(0, byteLimit); + suffix = " ..."; + } + + _this.info("\" >"); }); } }; diff --git a/src/index.js b/src/index.js index b19700a..b4123c7 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ 'use strict'; +const path = require("path"); const chalk = require("chalk"); const spy = require("through2-spy"); const fancyLog = require("fancy-log"); @@ -13,7 +14,17 @@ const typeColors = { debug: "gray" } -module.exports = function namedLog(name) { +function hexify(buff) { + let bytes = []; + + for (let i = 0; i < buff.length; i++) { + bytes.push(buff.toString("hex", i, i + 1)); + } + + return bytes; +} + +module.exports = function namedLog(name, options = {}) { let prefix = `[${chalk.green(name)}]`; function createLog(type) { @@ -39,7 +50,25 @@ module.exports = function namedLog(name) { log: createLog(), stream: function() { return spy.obj((file) => { - this.info(file.path, file.contents); + let shortPath, firstBytes, suffix; + + let byteLimit = (options.byteLimit != null) ? options.byteLimit : 20; + + if (options.basePath != null) { + shortPath = path.relative(options.basePath, file.path); + } else { + shortPath = path.basename(file.path); + } + + if (file.contents.length <= byteLimit) { + firstBytes = file.contents; + suffix = ""; + } else { + firstBytes = file.contents.slice(0, byteLimit); + suffix = " ..." + } + + this.info(`" >`); }); } }