@webiny/cli 0.0.0-mt-2 → 0.0.0-unstable.5e7233243f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/utils/log.js CHANGED
@@ -1,28 +1,26 @@
1
1
  const chalk = require("chalk");
2
2
 
3
- const getLogType = type => {
4
- switch (type) {
5
- case "log":
6
- return type;
7
- case "info":
8
- return `${chalk.blueBright(type)}`;
9
- case "error":
10
- return `${chalk.red(type)}`;
11
- case "warning":
12
- return `${chalk.yellow(type)}`;
13
- case "debug":
14
- return `${chalk.gray(type)}`;
15
- case "success":
16
- return `${chalk.green(type)}`;
17
- }
3
+ const logColors = {
4
+ log: v => v,
5
+ info: chalk.blueBright,
6
+ error: chalk.red,
7
+ warning: chalk.yellow,
8
+ debug: chalk.gray,
9
+ success: chalk.green
10
+ };
11
+
12
+ const colorizePlaceholders = (type, string) => {
13
+ return string.replace(/\%[a-zA-Z]/g, match => {
14
+ return logColors[type](match);
15
+ });
18
16
  };
19
17
 
20
18
  const webinyLog = (type, ...args) => {
21
- const prefix = `webiny ${getLogType(type)}: `;
19
+ const prefix = `webiny ${logColors[type](type)}: `;
22
20
 
23
21
  const [first, ...rest] = args;
24
22
  if (typeof first === "string") {
25
- return console.log(prefix + first, ...rest);
23
+ return console.log(prefix + colorizePlaceholders(type, first), ...rest);
26
24
  }
27
25
  return console.log(prefix, first, ...rest);
28
26
  };