@modern-js/repo-generator 2.4.16 → 2.4.18

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 +0 -4
  2. package/package.json +13 -13
  3. package/src/index.ts +153 -0
package/dist/index.js CHANGED
@@ -52422,7 +52422,6 @@ var require_downloadPackage = __commonJSMin((exports) => {
52422
52422
  if (response.status !== 200) {
52423
52423
  throw new Error(`download tar package get bad status code: ${response.status}`);
52424
52424
  }
52425
- const contentLength = Number(response.headers["content-length"]);
52426
52425
  const randomId = Math.floor(Math.random() * 1e4);
52427
52426
  const tempTgzFilePath = `${_os.default.tmpdir()}/temp-${randomId}.tgz`;
52428
52427
  const dest = _utils.fs.createWriteStream(tempTgzFilePath);
@@ -52435,9 +52434,6 @@ var require_downloadPackage = __commonJSMin((exports) => {
52435
52434
  resolve();
52436
52435
  });
52437
52436
  });
52438
- if ((await _utils.fs.stat(tempTgzFilePath)).size !== contentLength) {
52439
- throw new Error("download tar package get bad content length");
52440
- }
52441
52437
  await new Promise((resolve, reject) => {
52442
52438
  _utils.fs.createReadStream(tempTgzFilePath).pipe(_tar.default.x({
52443
52439
  strip: 1,
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.4.16",
14
+ "version": "2.4.18",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "main": "./dist/index.js",
17
17
  "files": [
@@ -23,22 +23,22 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "@babel/runtime": "^7.18.0",
26
- "@modern-js/codesmith": "1.6.3",
27
- "@modern-js/codesmith-api-app": "1.6.3",
26
+ "@modern-js/codesmith": "1.6.4",
27
+ "@modern-js/codesmith-api-app": "1.6.4",
28
28
  "@types/jest": "^27",
29
29
  "@types/node": "^14",
30
30
  "jest": "^27",
31
31
  "typescript": "^4",
32
- "@modern-js/base-generator": "2.4.16",
33
- "@modern-js/generator-common": "2.4.16",
34
- "@modern-js/generator-plugin": "2.4.16",
35
- "@modern-js/generator-utils": "2.4.16",
36
- "@modern-js/module-generator": "2.4.16",
37
- "@modern-js/monorepo-generator": "2.4.16",
38
- "@modern-js/mwa-generator": "2.4.16",
39
- "@modern-js/utils": "1.22.5",
40
- "@scripts/build": "1.22.5",
41
- "@scripts/jest-config": "1.22.5"
32
+ "@modern-js/base-generator": "2.4.18",
33
+ "@modern-js/generator-common": "2.4.18",
34
+ "@modern-js/generator-plugin": "2.4.18",
35
+ "@modern-js/generator-utils": "2.4.18",
36
+ "@modern-js/module-generator": "2.4.18",
37
+ "@modern-js/monorepo-generator": "2.4.18",
38
+ "@modern-js/mwa-generator": "2.4.18",
39
+ "@modern-js/utils": "1.22.7",
40
+ "@scripts/build": "1.22.7",
41
+ "@scripts/jest-config": "1.22.7"
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
+ };