Skip to content

Commit 298b1d9

Browse files
committed
:feat: update
1 parent baf6dc3 commit 298b1d9

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@micro-app/shared-utils",
3-
"version": "0.0.4",
3+
"version": "0.1.0",
44
"description": "[Shared] shared utilities for micro-app.",
55
"main": "index.js",
66
"scripts": {

src/logger/index.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,36 +55,62 @@ const getNpmlogMethod = function(type) {
5555
return npmlog[type].bind(npmlog);
5656
};
5757

58+
function dyeMessage(type, message) {
59+
switch (type.toLowerCase()) {
60+
case 'debug': {
61+
return chalk.visible(message);
62+
}
63+
case 'warn': {
64+
return chalk.yellowBright(message);
65+
}
66+
case 'error': {
67+
return chalk.redBright(message);
68+
}
69+
case 'info': {
70+
return chalk.blueBright(message);
71+
}
72+
case 'success': {
73+
return chalk.greenBright(message);
74+
}
75+
case 'noise': {
76+
return chalk.magentaBright(message);
77+
}
78+
default: {
79+
return message;
80+
}
81+
}
82+
}
83+
5884
const toString = {
5985
debug() {
6086
const message = utils.format(...(arguments || []));
61-
return `${chalk.bgMagenta(' DEBUG ')} ${message} ${os.EOL}`;
87+
return `${chalk.bgMagenta(' DEBUG ')} ${dyeMessage('debug', message)} ${os.EOL}`;
6288
},
6389
warn() {
6490
const message = utils.format(...(arguments || []));
65-
return `${chalk.bgYellowBright.black(' WARN ')} ${chalk.yellowBright(message)} ${os.EOL}`;
91+
return `${chalk.bgYellowBright.black(' WARN ')} ${dyeMessage('warn', message)} ${os.EOL}`;
6692
},
6793
error() {
6894
const message = utils.format(...(arguments || []));
69-
return `${chalk.bgRed(' ERROR ')} ${chalk.redBright(message)} ${os.EOL}`;
95+
return `${chalk.bgRed(' ERROR ')} ${dyeMessage('error', message)} ${os.EOL}`;
7096
},
7197
info() {
7298
const message = utils.format(...(arguments || []));
73-
return `${chalk.bgBlue(' INFO ')} ${chalk.blueBright(message)} ${os.EOL}`;
99+
return `${chalk.bgBlue(' INFO ')} ${dyeMessage('info', message)} ${os.EOL}`;
74100
},
75101
success() {
76102
const message = utils.format(...(arguments || []));
77-
return `${chalk.bgHex('#007007')(' SUCCESS ')} ${chalk.greenBright(message)} ${os.EOL}`;
103+
return `${chalk.bgHex('#007007')(' SUCCESS ')} ${dyeMessage('success', message)} ${os.EOL}`;
78104
},
79105
};
80106

81107
const getMethod = function(type) {
82108
const logger = getNpmlogMethod(type);
83109
return function(...args) {
84110
if (args.length <= 1) {
85-
return logger(false, ...args);
111+
return logger(false, ...args.map(arg => dyeMessage(type, arg)));
86112
}
87-
return logger(...args);
113+
return logger(args[0], ...args.splice(1).map(arg => dyeMessage(type, arg)));
88114
};
89115
// const logger = getStdoutMethod(type);
90116
// return function(...args) {

0 commit comments

Comments
 (0)