@modern-js/repo-generator 0.0.0-next-20241015055635 → 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.
Files changed (3) hide show
  1. package/dist/index.js +35944 -85649
  2. package/package.json +4 -16
  3. package/src/index.ts +12 -112
package/package.json CHANGED
@@ -15,31 +15,19 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "0.0.0-next-20241015055635",
18
+ "version": "0.0.0-next-20241015072043",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "main": "./dist/index.js",
21
21
  "files": [
22
22
  "/templates",
23
23
  "/dist/index.js"
24
24
  ],
25
- "dependencies": {
26
- "@modern-js/utils": "0.0.0-next-20241015055635"
27
- },
28
25
  "devDependencies": {
29
- "@modern-js/codesmith": "2.5.2",
30
- "@modern-js/codesmith-api-app": "2.5.2",
31
- "@types/jest": "^29",
26
+ "@modern-js/codesmith": "2.6.0",
32
27
  "@types/node": "^14",
33
- "jest": "^29",
34
28
  "typescript": "^5",
35
- "@modern-js/base-generator": "0.0.0-next-20241015055635",
36
- "@modern-js/generator-common": "0.0.0-next-20241015055635",
37
- "@modern-js/module-generator": "0.0.0-next-20241015055635",
38
- "@modern-js/generator-utils": "0.0.0-next-20241015055635",
39
- "@modern-js/mwa-generator": "0.0.0-next-20241015055635",
40
- "@modern-js/generator-plugin": "0.0.0-next-20241015055635",
41
- "@scripts/build": "0.0.0-next-20241015055635",
42
- "@scripts/jest-config": "0.0.0-next-20241015055635"
29
+ "@modern-js/repo-next-generator": "0.0.0-next-20241015072043",
30
+ "@scripts/build": "0.0.0-next-20241015072043"
43
31
  },
44
32
  "sideEffects": false,
45
33
  "publishConfig": {
package/src/index.ts CHANGED
@@ -1,123 +1,23 @@
1
- import type { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
2
- import { AppAPI } from '@modern-js/codesmith-api-app';
3
1
  import {
4
- BaseGenerator,
5
- type Solution,
6
- SolutionDefaultConfig,
7
- SolutionGenerator,
8
- getScenesSchema,
9
- getSolutionSchema,
10
- i18n,
11
- } from '@modern-js/generator-common';
12
- import { GeneratorPlugin } from '@modern-js/generator-plugin';
13
- import { getGeneratorPath } from '@modern-js/generator-utils';
14
- import { merge } from '@modern-js/utils/lodash';
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
- const appApi = new AppAPI(context, generator);
94
-
95
- const { locale } = context.config;
96
- i18n.changeLanguage({ locale });
97
- appApi.i18n.changeLanguage({ locale });
10
+ // check prepare global
98
11
 
99
- if (!(await appApi.checkEnvironment())) {
100
- process.exit(1);
101
- }
102
- generator.logger.debug(`🚀 [Start Run Repo Generator]`);
103
- generator.logger.debug(
104
- '💡 [Current Config]:',
105
- JSON.stringify(context.config),
106
- );
107
-
108
- mergeDefaultConfig(context);
109
-
110
- let generatorPlugin;
111
- if (context.config.plugins?.length > 0) {
112
- generatorPlugin = await handlePlugin(context, generator);
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
- try {
116
- await handleTemplateFile(context, generator, appApi, generatorPlugin);
117
- } catch (e) {
118
- generator.logger.error(`🔴 [Handle Repo Template Error]:`, e);
119
- process.exit(1);
120
- }
20
+ generator.logger.debug(`🚀 [Start Run Repo Generator]`);
121
21
 
122
22
  generator.logger.debug(`🚀 [End Run Repo Generator]`);
123
23
  };