@modern-js/repo-generator 2.4.16 → 2.4.17
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/package.json +11 -11
- package/src/index.ts +153 -0
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "2.4.
|
14
|
+
"version": "2.4.17",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"main": "./dist/index.js",
|
17
17
|
"files": [
|
@@ -29,16 +29,16 @@
|
|
29
29
|
"@types/node": "^14",
|
30
30
|
"jest": "^27",
|
31
31
|
"typescript": "^4",
|
32
|
-
"@modern-js/base-generator": "2.4.
|
33
|
-
"@modern-js/generator-common": "2.4.
|
34
|
-
"@modern-js/generator-plugin": "2.4.
|
35
|
-
"@modern-js/generator-utils": "2.4.
|
36
|
-
"@modern-js/module-generator": "2.4.
|
37
|
-
"@modern-js/monorepo-generator": "2.4.
|
38
|
-
"@modern-js/mwa-generator": "2.4.
|
39
|
-
"@modern-js/utils": "1.22.
|
40
|
-
"@scripts/build": "1.22.
|
41
|
-
"@scripts/jest-config": "1.22.
|
32
|
+
"@modern-js/base-generator": "2.4.17",
|
33
|
+
"@modern-js/generator-common": "2.4.17",
|
34
|
+
"@modern-js/generator-plugin": "2.4.17",
|
35
|
+
"@modern-js/generator-utils": "2.4.17",
|
36
|
+
"@modern-js/module-generator": "2.4.17",
|
37
|
+
"@modern-js/monorepo-generator": "2.4.17",
|
38
|
+
"@modern-js/mwa-generator": "2.4.17",
|
39
|
+
"@modern-js/utils": "1.22.6",
|
40
|
+
"@scripts/build": "1.22.6",
|
41
|
+
"@scripts/jest-config": "1.22.6"
|
42
42
|
},
|
43
43
|
"sideEffects": false,
|
44
44
|
"modernConfig": {
|
package/src/index.ts
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
import path from 'path';
|
2
|
+
import { merge } from '@modern-js/utils/lodash';
|
3
|
+
import { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
|
4
|
+
import { AppAPI } from '@modern-js/codesmith-api-app';
|
5
|
+
import {
|
6
|
+
i18n,
|
7
|
+
SolutionSchema,
|
8
|
+
SolutionGenerator,
|
9
|
+
Solution,
|
10
|
+
SolutionDefaultConfig,
|
11
|
+
BaseGenerator,
|
12
|
+
MonorepoNewActionSchema,
|
13
|
+
SubSolution,
|
14
|
+
SubSolutionGenerator,
|
15
|
+
MonorepoNewActionConfig,
|
16
|
+
getSolutionNameFromSubSolution,
|
17
|
+
} from '@modern-js/generator-common';
|
18
|
+
import { GeneratorPlugin } from '@modern-js/generator-plugin';
|
19
|
+
|
20
|
+
const getGeneratorPath = (generator: string, distTag: string) => {
|
21
|
+
if (process.env.CODESMITH_ENV === 'development') {
|
22
|
+
return path.dirname(require.resolve(generator));
|
23
|
+
} else if (distTag) {
|
24
|
+
return `${generator}@${distTag}`;
|
25
|
+
}
|
26
|
+
return generator;
|
27
|
+
};
|
28
|
+
|
29
|
+
const mergeDefaultConfig = (context: GeneratorContext) => {
|
30
|
+
const { defaultSolution } = context.config;
|
31
|
+
|
32
|
+
if (defaultSolution) {
|
33
|
+
merge(
|
34
|
+
context.config,
|
35
|
+
{ solution: defaultSolution },
|
36
|
+
SolutionDefaultConfig[defaultSolution as Solution],
|
37
|
+
);
|
38
|
+
}
|
39
|
+
};
|
40
|
+
|
41
|
+
const getNeedRunPlugin = (
|
42
|
+
context: GeneratorContext,
|
43
|
+
generatorPlugin?: GeneratorPlugin,
|
44
|
+
): boolean => {
|
45
|
+
if (!generatorPlugin) {
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
const { extendPlugin, customPlugin } = generatorPlugin;
|
49
|
+
const { isMonorepo, solution, scenes } = context.config;
|
50
|
+
const pluginSolution = isMonorepo
|
51
|
+
? getSolutionNameFromSubSolution(solution)
|
52
|
+
: solution;
|
53
|
+
if (!scenes || scenes === pluginSolution) {
|
54
|
+
return (
|
55
|
+
extendPlugin?.[pluginSolution] && extendPlugin[pluginSolution].length > 0
|
56
|
+
);
|
57
|
+
}
|
58
|
+
return Boolean(
|
59
|
+
customPlugin[pluginSolution]?.find(plugin => plugin.key === scenes),
|
60
|
+
);
|
61
|
+
};
|
62
|
+
|
63
|
+
const handleTemplateFile = async (
|
64
|
+
context: GeneratorContext,
|
65
|
+
generator: GeneratorCore,
|
66
|
+
appApi: AppAPI,
|
67
|
+
generatorPlugin?: GeneratorPlugin,
|
68
|
+
) => {
|
69
|
+
const { isMonorepo } = context.config;
|
70
|
+
|
71
|
+
const { solution } = await appApi.getInputBySchema(
|
72
|
+
isMonorepo ? MonorepoNewActionSchema : SolutionSchema,
|
73
|
+
{
|
74
|
+
...context.config,
|
75
|
+
customPlugin: generatorPlugin?.customPlugin,
|
76
|
+
},
|
77
|
+
);
|
78
|
+
|
79
|
+
const solutionGenerator =
|
80
|
+
// eslint-disable-next-line no-nested-ternary
|
81
|
+
solution === 'custom'
|
82
|
+
? BaseGenerator
|
83
|
+
: isMonorepo
|
84
|
+
? SubSolutionGenerator[solution as SubSolution]
|
85
|
+
: SolutionGenerator[solution as Solution];
|
86
|
+
|
87
|
+
if (!solution || !solutionGenerator) {
|
88
|
+
generator.logger.error('solution is not valid ');
|
89
|
+
}
|
90
|
+
|
91
|
+
await appApi.runSubGenerator(
|
92
|
+
getGeneratorPath(solutionGenerator, context.config.distTag),
|
93
|
+
undefined,
|
94
|
+
{
|
95
|
+
...(isMonorepo
|
96
|
+
? MonorepoNewActionConfig[solution as SubSolution] || {}
|
97
|
+
: {}),
|
98
|
+
...context.config,
|
99
|
+
hasPlugin: getNeedRunPlugin(context, generatorPlugin),
|
100
|
+
generatorPlugin,
|
101
|
+
},
|
102
|
+
);
|
103
|
+
};
|
104
|
+
|
105
|
+
const handlePlugin = async (
|
106
|
+
context: GeneratorContext,
|
107
|
+
generator: GeneratorCore,
|
108
|
+
) => {
|
109
|
+
const { plugins, registry, locale } = context.config;
|
110
|
+
const generatorPlugin = new GeneratorPlugin(
|
111
|
+
generator.logger,
|
112
|
+
generator.event,
|
113
|
+
locale,
|
114
|
+
);
|
115
|
+
await generatorPlugin.setupPlugin(plugins, registry);
|
116
|
+
return generatorPlugin;
|
117
|
+
};
|
118
|
+
|
119
|
+
export default async (context: GeneratorContext, generator: GeneratorCore) => {
|
120
|
+
process.setMaxListeners(20);
|
121
|
+
|
122
|
+
const appApi = new AppAPI(context, generator);
|
123
|
+
|
124
|
+
const { locale } = context.config;
|
125
|
+
i18n.changeLanguage({ locale });
|
126
|
+
appApi.i18n.changeLanguage({ locale });
|
127
|
+
|
128
|
+
if (!(await appApi.checkEnvironment())) {
|
129
|
+
// eslint-disable-next-line no-process-exit
|
130
|
+
process.exit(1);
|
131
|
+
}
|
132
|
+
|
133
|
+
generator.logger.debug(`start run @modern-js/repo-generator`);
|
134
|
+
generator.logger.debug(`context=${JSON.stringify(context)}`);
|
135
|
+
generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
|
136
|
+
|
137
|
+
mergeDefaultConfig(context);
|
138
|
+
|
139
|
+
let generatorPlugin;
|
140
|
+
if (context.config.plugins?.length > 0) {
|
141
|
+
generatorPlugin = await handlePlugin(context, generator);
|
142
|
+
}
|
143
|
+
|
144
|
+
try {
|
145
|
+
await handleTemplateFile(context, generator, appApi, generatorPlugin);
|
146
|
+
} catch (e) {
|
147
|
+
generator.logger.error(e);
|
148
|
+
// eslint-disable-next-line no-process-exit
|
149
|
+
process.exit(1);
|
150
|
+
}
|
151
|
+
|
152
|
+
generator.logger.debug(`forge @modern-js/repo-generator succeed `);
|
153
|
+
};
|