@modern-js/base-generator 3.0.3 → 3.0.5

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 CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "3.0.3",
14
+ "version": "3.0.5",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./src/index.ts",
17
17
  "main": "./dist/index.js",
@@ -27,10 +27,10 @@
27
27
  "@types/node": "^14",
28
28
  "jest": "^27",
29
29
  "typescript": "^4",
30
- "@modern-js/generator-utils": "3.0.3",
31
- "@scripts/jest-config": "2.1.0",
32
- "@modern-js/generator-common": "3.0.3",
33
- "@scripts/build": "2.1.0"
30
+ "@modern-js/generator-utils": "3.0.5",
31
+ "@modern-js/generator-common": "3.0.5",
32
+ "@scripts/jest-config": "2.3.0",
33
+ "@scripts/build": "2.3.0"
34
34
  },
35
35
  "sideEffects": false,
36
36
  "publishConfig": {
package/src/index.ts ADDED
@@ -0,0 +1,82 @@
1
+ import path from 'path';
2
+ import { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
3
+ import { AppAPI } from '@modern-js/codesmith-api-app';
4
+ import { getBaseSchema, PackageManager } from '@modern-js/generator-common';
5
+ import { fs } from '@modern-js/generator-utils';
6
+
7
+ const handleTemplateFile = async (
8
+ context: GeneratorContext,
9
+ generator: GeneratorCore,
10
+ appApi: AppAPI,
11
+ ) => {
12
+ const { hasPlugin, generatorPlugin, ...extra } = context.config;
13
+
14
+ let ans: Record<string, unknown> = {};
15
+ if (hasPlugin) {
16
+ await generatorPlugin.installPlugins('custom', extra);
17
+ const schema = generatorPlugin.getInputSchema();
18
+ const inputValue = generatorPlugin.getInputValue();
19
+ ans = await appApi.getInputBySchema(
20
+ schema,
21
+ 'formily',
22
+ {
23
+ ...context.config,
24
+ ...inputValue,
25
+ },
26
+ {},
27
+ {},
28
+ );
29
+ } else {
30
+ ans = await appApi.getInputBySchemaFunc(getBaseSchema, context.config);
31
+ }
32
+
33
+ const { packageManager } = ans;
34
+
35
+ await appApi.forgeTemplate(
36
+ 'templates/base-templates/**/*',
37
+ undefined,
38
+ resourceKey =>
39
+ resourceKey
40
+ .replace('templates/base-templates/', '')
41
+ .replace('.handlebars', ''),
42
+ );
43
+ await appApi.forgeTemplate('templates/idea/**/*', undefined, resourceKey =>
44
+ resourceKey.replace('templates/idea/', '.idea/'),
45
+ );
46
+
47
+ if (packageManager === PackageManager.Pnpm) {
48
+ await appApi.forgeTemplate(
49
+ 'templates/pnpm-templates/**/*',
50
+ undefined,
51
+ resourceKey =>
52
+ resourceKey
53
+ .replace('templates/pnpm-templates/npmrc', '.npmrc')
54
+ .replace('.handlebars', ''),
55
+ );
56
+ }
57
+
58
+ fs.chmodSync(path.join(generator.outputPath, '.husky', 'pre-commit'), '755');
59
+ };
60
+
61
+ export default async (context: GeneratorContext, generator: GeneratorCore) => {
62
+ const appApi = new AppAPI(context, generator);
63
+ const { locale } = context.config;
64
+ appApi.i18n.changeLanguage({ locale });
65
+
66
+ if (!(await appApi.checkEnvironment())) {
67
+ // eslint-disable-next-line no-process-exit
68
+ process.exit(1);
69
+ }
70
+
71
+ generator.logger.debug(`start run @modern-js/base-generator`);
72
+ generator.logger.debug(`context=${JSON.stringify(context)}`);
73
+ generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
74
+
75
+ await handleTemplateFile(context, generator, appApi);
76
+
77
+ if (context.handleForged) {
78
+ await context.handleForged('custom', context, context.config.hasPlugin);
79
+ }
80
+
81
+ generator.logger.debug(`forge @modern-js/base-generator succeed `);
82
+ };
@@ -40,3 +40,7 @@ log/
40
40
  .changeset/pre.json
41
41
 
42
42
  .pnpm-store/
43
+
44
+ modern.config.local.ts
45
+ modern.config.local.js
46
+ modern.config.local.mjs