@modern-js/repo-generator 0.0.0-next-20241015033921 → 0.0.0-next-20241015072043
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/dist/index.js +37169 -22754
- package/package.json +3 -13
- package/src/index.ts +11 -124
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "0.0.0-next-
|
|
18
|
+
"version": "0.0.0-next-20241015072043",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"main": "./dist/index.js",
|
|
21
21
|
"files": [
|
|
@@ -23,21 +23,11 @@
|
|
|
23
23
|
"/dist/index.js"
|
|
24
24
|
],
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@modern-js/codesmith-utils": "2.6.0",
|
|
27
26
|
"@modern-js/codesmith": "2.6.0",
|
|
28
|
-
"@modern-js/codesmith-api-app": "2.6.0",
|
|
29
|
-
"@types/jest": "^29",
|
|
30
27
|
"@types/node": "^14",
|
|
31
|
-
"jest": "^29",
|
|
32
28
|
"typescript": "^5",
|
|
33
|
-
"@modern-js/
|
|
34
|
-
"@
|
|
35
|
-
"@modern-js/generator-utils": "0.0.0-next-20241015033921",
|
|
36
|
-
"@modern-js/module-generator": "0.0.0-next-20241015033921",
|
|
37
|
-
"@modern-js/generator-common": "0.0.0-next-20241015033921",
|
|
38
|
-
"@scripts/build": "0.0.0-next-20241015033921",
|
|
39
|
-
"@modern-js/mwa-generator": "0.0.0-next-20241015033921",
|
|
40
|
-
"@scripts/jest-config": "0.0.0-next-20241015033921"
|
|
29
|
+
"@modern-js/repo-next-generator": "0.0.0-next-20241015072043",
|
|
30
|
+
"@scripts/build": "0.0.0-next-20241015072043"
|
|
41
31
|
},
|
|
42
32
|
"sideEffects": false,
|
|
43
33
|
"publishConfig": {
|
package/src/index.ts
CHANGED
|
@@ -1,136 +1,23 @@
|
|
|
1
|
-
import type { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
|
|
2
|
-
import { AppAPI } from '@modern-js/codesmith-api-app';
|
|
3
|
-
import { merge } from '@modern-js/codesmith-utils/lodash';
|
|
4
1
|
import {
|
|
5
|
-
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
getScenesSchema,
|
|
10
|
-
getSolutionSchema,
|
|
11
|
-
i18n,
|
|
12
|
-
} from '@modern-js/generator-common';
|
|
13
|
-
import { GeneratorPlugin } from '@modern-js/generator-plugin';
|
|
14
|
-
import { getGeneratorPath } from '@modern-js/generator-utils';
|
|
15
|
-
|
|
16
|
-
const mergeDefaultConfig = (context: GeneratorContext) => {
|
|
17
|
-
const { defaultSolution } = context.config;
|
|
18
|
-
|
|
19
|
-
if (defaultSolution) {
|
|
20
|
-
merge(
|
|
21
|
-
context.config,
|
|
22
|
-
{ solution: defaultSolution },
|
|
23
|
-
SolutionDefaultConfig[defaultSolution as Solution],
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const getNeedRunPlugin = (
|
|
29
|
-
context: GeneratorContext,
|
|
30
|
-
generatorPlugin?: GeneratorPlugin,
|
|
31
|
-
): boolean => {
|
|
32
|
-
if (!generatorPlugin) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
const { extendPlugin, customPlugin } = generatorPlugin;
|
|
36
|
-
const { solution, scenes } = context.config;
|
|
37
|
-
if (!scenes || scenes === solution) {
|
|
38
|
-
return extendPlugin?.[solution] && extendPlugin[solution].length > 0;
|
|
39
|
-
}
|
|
40
|
-
return Boolean(customPlugin[solution]?.find(plugin => plugin.key === scenes));
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const handleTemplateFile = async (
|
|
44
|
-
context: GeneratorContext,
|
|
45
|
-
generator: GeneratorCore,
|
|
46
|
-
appApi: AppAPI,
|
|
47
|
-
generatorPlugin?: GeneratorPlugin,
|
|
48
|
-
) => {
|
|
49
|
-
const { solution } = await appApi.getInputBySchemaFunc(getSolutionSchema, {
|
|
50
|
-
...context.config,
|
|
51
|
-
customPlugin: generatorPlugin?.customPlugin,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
await appApi.getInputBySchemaFunc(getScenesSchema, context.config);
|
|
55
|
-
|
|
56
|
-
const solutionGenerator =
|
|
57
|
-
solution === 'custom'
|
|
58
|
-
? BaseGenerator
|
|
59
|
-
: SolutionGenerator[solution as Solution];
|
|
60
|
-
|
|
61
|
-
if (!solution || !solutionGenerator) {
|
|
62
|
-
generator.logger.error(`🔴 [Check Solution]: ${solution} is not support`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
await appApi.runSubGenerator(
|
|
66
|
-
getGeneratorPath(solutionGenerator, context.config.distTag, [__dirname]),
|
|
67
|
-
undefined,
|
|
68
|
-
{
|
|
69
|
-
...context.config,
|
|
70
|
-
hasPlugin: getNeedRunPlugin(context, generatorPlugin),
|
|
71
|
-
generatorPlugin,
|
|
72
|
-
},
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const handlePlugin = async (
|
|
77
|
-
context: GeneratorContext,
|
|
78
|
-
generator: GeneratorCore,
|
|
79
|
-
) => {
|
|
80
|
-
const { plugins, registry, locale } = context.config;
|
|
81
|
-
const generatorPlugin = new GeneratorPlugin(
|
|
82
|
-
generator.logger,
|
|
83
|
-
generator.event,
|
|
84
|
-
locale,
|
|
85
|
-
);
|
|
86
|
-
await generatorPlugin.setupPlugin(plugins, registry);
|
|
87
|
-
return generatorPlugin;
|
|
88
|
-
};
|
|
2
|
+
CodeSmith,
|
|
3
|
+
type GeneratorContext,
|
|
4
|
+
type GeneratorCore,
|
|
5
|
+
} from '@modern-js/codesmith';
|
|
89
6
|
|
|
90
7
|
export default async (context: GeneratorContext, generator: GeneratorCore) => {
|
|
91
8
|
process.setMaxListeners(20);
|
|
92
9
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// avoid create tools version is older
|
|
96
|
-
await generator.prepareGlobal();
|
|
97
|
-
await generator.prepareGenerators([
|
|
98
|
-
`@modern-js/repo-generator@${distTag || 'latest'}`,
|
|
99
|
-
`@modern-js/base-generator@${distTag || 'latest'}`,
|
|
100
|
-
`@modern-js/mwa-generator@${distTag || 'latest'}`,
|
|
101
|
-
`@modern-js/entry-generator@${distTag || 'latest'}`,
|
|
102
|
-
`@modern-js/module-generator@${distTag || 'latest'}`,
|
|
103
|
-
]);
|
|
104
|
-
|
|
105
|
-
const appApi = new AppAPI(context, generator);
|
|
106
|
-
|
|
107
|
-
const { locale } = context.config;
|
|
108
|
-
i18n.changeLanguage({ locale });
|
|
109
|
-
appApi.i18n.changeLanguage({ locale });
|
|
10
|
+
// check prepare global
|
|
110
11
|
|
|
111
|
-
if (!(
|
|
112
|
-
|
|
12
|
+
if (!(global as any).codesmith) {
|
|
13
|
+
generator.logger.warn(
|
|
14
|
+
'🟡 Please use the latest @modern-js/create version to run generator',
|
|
15
|
+
);
|
|
16
|
+
const codesmith = new CodeSmith({});
|
|
17
|
+
await codesmith.prepareGlobal();
|
|
113
18
|
}
|
|
114
19
|
|
|
115
20
|
generator.logger.debug(`🚀 [Start Run Repo Generator]`);
|
|
116
|
-
generator.logger.debug(
|
|
117
|
-
'💡 [Current Config]:',
|
|
118
|
-
JSON.stringify(context.config),
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
mergeDefaultConfig(context);
|
|
122
|
-
|
|
123
|
-
let generatorPlugin;
|
|
124
|
-
if (context.config.plugins?.length > 0) {
|
|
125
|
-
generatorPlugin = await handlePlugin(context, generator);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
await handleTemplateFile(context, generator, appApi, generatorPlugin);
|
|
130
|
-
} catch (e) {
|
|
131
|
-
generator.logger.error(`🔴 [Handle Repo Template Error]:`, e);
|
|
132
|
-
process.exit(1);
|
|
133
|
-
}
|
|
134
21
|
|
|
135
22
|
generator.logger.debug(`🚀 [End Run Repo Generator]`);
|
|
136
23
|
};
|