/
index.ts
106 lines (94 loc) · 3.75 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
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> {
const { logger } = cli;
await cli.makeCommand(
{
name: 'init [generation-path]',
alias: ['create', 'new', 'c', 'n'],
description: 'Initialize a new webpack project.',
usage: '[generation-path] [options]',
pkg: '@webpack-cli/generators',
},
[
{
name: 'template',
configs: [{ type: 'string' }],
description: 'Type of template',
defaultValue: 'default',
},
{
name: 'force',
configs: [{ type: 'boolean' }],
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 }, () => {
logger.success('Project has been initialised with webpack!');
});
},
);
await cli.makeCommand(
{
name: 'loader [output-path]',
alias: 'l',
description: 'Scaffold a loader.',
usage: '[output-path] [options]',
pkg: '@webpack-cli/generators',
},
[
{
name: 'template',
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 }, () => {
logger.success('Loader template has been successfully scaffolded.');
});
},
);
await cli.makeCommand(
{
name: 'plugin [output-path]',
alias: 'p',
description: 'Scaffold a plugin.',
usage: '[output-path] [options]',
pkg: '@webpack-cli/generators',
},
[
{
name: 'template',
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 }, () => {
logger.success('Plugin template has been successfully scaffolded.');
});
},
);
}
}
export default GeneratorsCommand;
export { addonGenerator, initGenerator };