unmock-core
Version:
[][npmjs] [](https://circleci.com/gh/unmock/unmock-js) [](h
53 lines • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const boxen_1 = require("boxen");
const console_1 = require("console");
const fp_1 = require("lodash/fp");
const util_1 = require("util");
const chalks_1 = require("./chalks");
const indentRegex = /^(?!\s*$)/gm;
const indentString = (s, count) => s.replace(indentRegex, " ".repeat(count));
function clearLine(stream) {
if (stream.isTTY) {
stream.write("\x1b[999D\x1b[K");
}
}
const boxenOptions = {
padding: 0,
borderStyle: {
topLeft: "-",
topRight: "-",
bottomLeft: "-",
bottomRight: "-",
horizontal: "-",
vertical: " ",
},
};
const formatLogType = (type, message) => fp_1.flow((m) => "unmock: " + m, (m) => (type === "instruct" ? boxen_1.default(m, boxenOptions) : message), (m) => chalks_1.Chalks[type](m))(message);
class CustomConsole extends console_1.Console {
constructor(stdout, stderr) {
super(stdout, stderr);
this.nIndent = 2;
this.stdout = stdout;
this.stderr = stderr;
}
static format(type, message) {
return formatLogType(type, message);
}
instruct(firstArg, ...args) {
this.logMessage("instruct", util_1.format(firstArg, ...args));
}
error(firstArg, ...args) {
this.logError("error", util_1.format(firstArg, ...args));
}
logMessage(type, message) {
clearLine(this.stdout);
super.log(indentString(CustomConsole.format(type, message), this.nIndent));
}
logError(type, message) {
clearLine(this.stderr);
super.error(indentString(CustomConsole.format(type, message), this.nIndent));
}
}
exports.CustomConsole = CustomConsole;
//# sourceMappingURL=console.js.map