feat: refactoring project
This commit is contained in:
63
node_modules/webpack/lib/node/nodeConsole.js
generated
vendored
63
node_modules/webpack/lib/node/nodeConsole.js
generated
vendored
@@ -19,7 +19,7 @@ const truncateArgs = require("../logging/truncateArgs");
|
||||
*/
|
||||
module.exports = ({ colors, appendOnly, stream }) => {
|
||||
/** @type {string[] | undefined} */
|
||||
let currentStatusMessage = undefined;
|
||||
let currentStatusMessage;
|
||||
let hasStatusMessage = false;
|
||||
let currentIndent = "";
|
||||
let currentCollapsed = 0;
|
||||
@@ -38,17 +38,17 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
||||
return (
|
||||
prefix +
|
||||
colorPrefix +
|
||||
str.replace(/\n/g, colorSuffix + "\n" + prefix + colorPrefix) +
|
||||
str.replace(/\n/g, `${colorSuffix}\n${prefix}${colorPrefix}`) +
|
||||
colorSuffix
|
||||
);
|
||||
} else {
|
||||
return prefix + str.replace(/\n/g, "\n" + prefix);
|
||||
}
|
||||
|
||||
return prefix + str.replace(/\n/g, `\n${prefix}`);
|
||||
};
|
||||
|
||||
const clearStatusMessage = () => {
|
||||
if (hasStatusMessage) {
|
||||
stream.write("\x1b[2K\r");
|
||||
stream.write("\u001B[2K\r");
|
||||
hasStatusMessage = false;
|
||||
}
|
||||
};
|
||||
@@ -58,8 +58,8 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
||||
const l = /** @type {TODO} */ (stream).columns || 40;
|
||||
const args = truncateArgs(currentStatusMessage, l - 1);
|
||||
const str = args.join(" ");
|
||||
const coloredStr = `\u001b[1m${str}\u001b[39m\u001b[22m`;
|
||||
stream.write(`\x1b[2K\r${coloredStr}`);
|
||||
const coloredStr = `\u001B[1m${str}\u001B[39m\u001B[22m`;
|
||||
stream.write(`\u001B[2K\r${coloredStr}`);
|
||||
hasStatusMessage = true;
|
||||
};
|
||||
|
||||
@@ -67,10 +67,11 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
||||
* @param {string} prefix prefix
|
||||
* @param {string} colorPrefix color prefix
|
||||
* @param {string} colorSuffix color suffix
|
||||
* @returns {(function(...any[]): void)} function to write with colors
|
||||
* @returns {(function(...EXPECTED_ANY[]): void)} function to write with colors
|
||||
*/
|
||||
const writeColored = (prefix, colorPrefix, colorSuffix) => {
|
||||
return (...args) => {
|
||||
const writeColored =
|
||||
(prefix, colorPrefix, colorSuffix) =>
|
||||
(...args) => {
|
||||
if (currentCollapsed > 0) return;
|
||||
clearStatusMessage();
|
||||
const str = indent(
|
||||
@@ -79,34 +80,33 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
||||
colorPrefix,
|
||||
colorSuffix
|
||||
);
|
||||
stream.write(str + "\n");
|
||||
stream.write(`${str}\n`);
|
||||
writeStatusMessage();
|
||||
};
|
||||
};
|
||||
|
||||
const writeGroupMessage = writeColored(
|
||||
"<-> ",
|
||||
"\u001b[1m\u001b[36m",
|
||||
"\u001b[39m\u001b[22m"
|
||||
"\u001B[1m\u001B[36m",
|
||||
"\u001B[39m\u001B[22m"
|
||||
);
|
||||
|
||||
const writeGroupCollapsedMessage = writeColored(
|
||||
"<+> ",
|
||||
"\u001b[1m\u001b[36m",
|
||||
"\u001b[39m\u001b[22m"
|
||||
"\u001B[1m\u001B[36m",
|
||||
"\u001B[39m\u001B[22m"
|
||||
);
|
||||
|
||||
return {
|
||||
log: writeColored(" ", "\u001b[1m", "\u001b[22m"),
|
||||
log: writeColored(" ", "\u001B[1m", "\u001B[22m"),
|
||||
debug: writeColored(" ", "", ""),
|
||||
trace: writeColored(" ", "", ""),
|
||||
info: writeColored("<i> ", "\u001b[1m\u001b[32m", "\u001b[39m\u001b[22m"),
|
||||
warn: writeColored("<w> ", "\u001b[1m\u001b[33m", "\u001b[39m\u001b[22m"),
|
||||
error: writeColored("<e> ", "\u001b[1m\u001b[31m", "\u001b[39m\u001b[22m"),
|
||||
info: writeColored("<i> ", "\u001B[1m\u001B[32m", "\u001B[39m\u001B[22m"),
|
||||
warn: writeColored("<w> ", "\u001B[1m\u001B[33m", "\u001B[39m\u001B[22m"),
|
||||
error: writeColored("<e> ", "\u001B[1m\u001B[31m", "\u001B[39m\u001B[22m"),
|
||||
logTime: writeColored(
|
||||
"<t> ",
|
||||
"\u001b[1m\u001b[35m",
|
||||
"\u001b[39m\u001b[22m"
|
||||
"\u001B[1m\u001B[35m",
|
||||
"\u001B[39m\u001B[22m"
|
||||
),
|
||||
group: (...args) => {
|
||||
writeGroupMessage(...args);
|
||||
@@ -123,18 +123,21 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
||||
groupEnd: () => {
|
||||
if (currentCollapsed > 0) currentCollapsed--;
|
||||
else if (currentIndent.length >= 2)
|
||||
currentIndent = currentIndent.slice(0, currentIndent.length - 2);
|
||||
currentIndent = currentIndent.slice(0, -2);
|
||||
},
|
||||
profile: console.profile && (name => console.profile(name)),
|
||||
profileEnd: console.profileEnd && (name => console.profileEnd(name)),
|
||||
clear:
|
||||
!appendOnly &&
|
||||
console.clear &&
|
||||
(() => {
|
||||
clearStatusMessage();
|
||||
console.clear();
|
||||
writeStatusMessage();
|
||||
}),
|
||||
/** @type {() => void} */
|
||||
(
|
||||
!appendOnly &&
|
||||
console.clear &&
|
||||
(() => {
|
||||
clearStatusMessage();
|
||||
console.clear();
|
||||
writeStatusMessage();
|
||||
})
|
||||
),
|
||||
status: appendOnly
|
||||
? writeColored("<s> ", "", "")
|
||||
: (name, ...args) => {
|
||||
|
||||
Reference in New Issue
Block a user