-
-
Notifications
You must be signed in to change notification settings - Fork 669
Expand file tree
/
Copy pathlogger.ts
More file actions
54 lines (49 loc) · 1.69 KB
/
logger.ts
File metadata and controls
54 lines (49 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { normalize, relative } from "node:path";
import { type Color, blue, blueBright, cyan, green, greenBright, red, yellow } from "colorette";
import {
type Logger,
type PlopActionHooksChanges,
type PlopActionHooksFailures,
} from "../types.js";
const prefix: string = blueBright("create-webpack");
const getLogger = (): Logger => ({
error: (val) => console.error(`[${prefix}] ⛔${red(val)}`),
warn: (val) => console.warn(`[${prefix}] ⚠️${yellow(val)}`),
info: (val) => console.info(`[${prefix}] ℹ️ ${cyan(val)}`),
success: (val) => console.log(`[${prefix}] ✅ ${green(val)}`),
log: (val) => console.log(`[${prefix}] 📃${val}`),
raw: (val) => console.log(val),
});
const logger = getLogger();
const typeDisplay: Record<string, Color | string> = {
function: yellow("-> "),
add: green("create "),
addMany: green("create "),
modify: `${blue("modify")}${green("+")}${red("- ")}`,
overwrite: red("overwrite "),
append: green("append_+ "),
skip: yellow("skip "),
identical: greenBright("identical "),
create: green("create "),
};
function onSuccessHandler(change: PlopActionHooksChanges): void {
switch (change.type) {
case "generate-files": {
for (const line of change.path.split("\n")) {
const [operationType = "", renderPath = ""] = line.split("|");
console.log(
`\t${typeDisplay[operationType]} ${normalize(relative(process.cwd(), renderPath))}`,
);
}
break;
}
case "install-dependencies": {
logger.success(change.path);
break;
}
}
}
function onFailureHandler(failure: PlopActionHooksFailures): void {
throw new Error(failure.error);
}
export { logger, onFailureHandler, onSuccessHandler };