/
index.ts
88 lines (78 loc) · 2.15 KB
/
index.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import envinfo from "envinfo";
interface Information {
Binaries?: string[];
Browsers?: string[];
Monorepos?: string[];
System?: string[];
npmGlobalPackages?: string[];
npmPackages?: string | string[];
}
const DEFAULT_DETAILS: Information = {
Binaries: ["Node", "Yarn", "npm"],
Browsers: [
"Brave Browser",
"Chrome",
"Chrome Canary",
"Edge",
"Firefox",
"Firefox Developer Edition",
"Firefox Nightly",
"Internet Explorer",
"Safari",
"Safari Technology Preview",
],
Monorepos: ["Yarn Workspaces", "Lerna"],
System: ["OS", "CPU", "Memory"],
npmGlobalPackages: ["webpack", "webpack-cli"],
npmPackages: "*webpack*",
};
class InfoCommand {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
async apply(cli: any): Promise<void> {
await cli.makeCommand(
{
name: "info",
alias: "i",
description: "Outputs information about your system.",
usage: "[options]",
pkg: "@webpack-cli/info",
},
[
{
name: "output",
alias: "o",
configs: [
{
type: "string",
},
],
description: "To get the output in a specified format ( accept json or markdown )",
},
],
async (options) => {
let { output } = options;
const envinfoConfig = {};
if (output) {
// Remove quotes if exist
output = output.replace(/['"]+/g, "");
switch (output) {
case "markdown":
envinfoConfig["markdown"] = true;
break;
case "json":
envinfoConfig["json"] = true;
break;
default:
cli.logger.error(`'${output}' is not a valid value for output`);
process.exit(2);
}
}
let info = await envinfo.run(DEFAULT_DETAILS, envinfoConfig);
info = info.replace(/npmPackages/g, "Packages");
info = info.replace(/npmGlobalPackages/g, "Global Packages");
cli.logger.raw(info);
},
);
}
}
export default InfoCommand;