|
|
|
@ -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(`<File "${shortPath}>" <Buffer ${hexify(firstBytes).join(" ")} ${suffix} >>`);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|