-
-
Notifications
You must be signed in to change notification settings - Fork 591
/
index.ts
124 lines (113 loc) · 3.64 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import yeoman from "yeoman-environment";
import loaderGenerator from "./loader-generator";
import pluginGenerator from "./plugin-generator";
import addonGenerator from "./addon-generator";
import initGenerator from "./init-generator";
class GeneratorsCommand {
// 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: "init [generation-path]",
alias: ["create", "new", "c", "n"],
description: "Initialize a new webpack project.",
argsDescription: {
"generation-path": "Path to the installation directory, e.g. ./projectName",
},
usage: "[generation-path] [options]",
pkg: "@webpack-cli/generators",
},
[
{
name: "template",
alias: "t",
configs: [{ type: "string" }],
description: "Type of template",
defaultValue: "default",
},
{
name: "force",
alias: "f",
configs: [
{
type: "enum",
values: [true],
},
],
description: "Generate without questions (ideally) using default answers",
},
],
async (generationPath, options) => {
options.generationPath = generationPath || ".";
const env = yeoman.createEnv([], {
cwd: options.generationPath,
});
const generatorName = "webpack-init-generator";
env.registerStub(initGenerator, generatorName);
env.run(generatorName, { cli, options }, () => {
cli.logger.success("Project has been initialised with webpack!");
});
},
);
await cli.makeCommand(
{
name: "loader [output-path]",
alias: "l",
description: "Scaffold a loader.",
argsDescription: {
"output-path": "Path to the output directory, e.g. ./loaderName",
},
usage: "[output-path] [options]",
pkg: "@webpack-cli/generators",
},
[
{
name: "template",
alias: "t",
configs: [{ type: "string" }],
description: "Type of template",
defaultValue: "default",
},
],
async (outputPath, options) => {
const env = yeoman.createEnv([], { cwd: outputPath });
const generatorName = "webpack-loader-generator";
env.registerStub(loaderGenerator, generatorName);
env.run(generatorName, { cli, options }, () => {
cli.logger.success("Loader template has been successfully scaffolded.");
});
},
);
await cli.makeCommand(
{
name: "plugin [output-path]",
alias: "p",
description: "Scaffold a plugin.",
argsDescription: {
"output-path": "Path to the output directory, e.g. ./pluginName",
},
usage: "[output-path] [options]",
pkg: "@webpack-cli/generators",
},
[
{
name: "template",
alias: "t",
configs: [{ type: "string" }],
description: "Type of template",
defaultValue: "default",
},
],
async (outputPath, options) => {
const env = yeoman.createEnv([], { cwd: outputPath });
const generatorName = "webpack-plugin-generator";
env.registerStub(pluginGenerator, generatorName);
env.run(generatorName, { cli, options }, () => {
cli.logger.success("Plugin template has been successfully scaffolded.");
});
},
);
}
}
export default GeneratorsCommand;
export { addonGenerator, initGenerator };