@modern-js/base-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 +5 -5
- package/src/index.ts +75 -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
|
"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-common": "2.4.
|
|
31
|
-
"@modern-js/generator-utils": "2.4.
|
|
32
|
-
"@scripts/build": "1.22.
|
|
33
|
-
"@scripts/jest-config": "1.22.
|
|
30
|
+
"@modern-js/generator-common": "2.4.17",
|
|
31
|
+
"@modern-js/generator-utils": "2.4.17",
|
|
32
|
+
"@scripts/build": "1.22.6",
|
|
33
|
+
"@scripts/jest-config": "1.22.6"
|
|
34
34
|
},
|
|
35
35
|
"sideEffects": false,
|
|
36
36
|
"modernConfig": {
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
|
|
3
|
+
import { AppAPI } from '@modern-js/codesmith-api-app';
|
|
4
|
+
import { BaseSchema, 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 schema = BaseSchema;
|
|
15
|
+
let inputValue = {};
|
|
16
|
+
|
|
17
|
+
if (hasPlugin) {
|
|
18
|
+
await generatorPlugin.installPlugins('custom', extra);
|
|
19
|
+
schema = generatorPlugin.getInputSchema('custom');
|
|
20
|
+
inputValue = generatorPlugin.getInputValue();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const { packageManager } = await appApi.getInputBySchema(schema, {
|
|
24
|
+
...context.config,
|
|
25
|
+
...inputValue,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
await appApi.forgeTemplate(
|
|
29
|
+
'templates/base-templates/**/*',
|
|
30
|
+
undefined,
|
|
31
|
+
resourceKey =>
|
|
32
|
+
resourceKey
|
|
33
|
+
.replace('templates/base-templates/', '')
|
|
34
|
+
.replace('.handlebars', ''),
|
|
35
|
+
);
|
|
36
|
+
await appApi.forgeTemplate('templates/idea/**/*', undefined, resourceKey =>
|
|
37
|
+
resourceKey.replace('templates/idea/', '.idea/'),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (packageManager === PackageManager.Pnpm) {
|
|
41
|
+
await appApi.forgeTemplate(
|
|
42
|
+
'templates/pnpm-templates/**/*',
|
|
43
|
+
undefined,
|
|
44
|
+
resourceKey =>
|
|
45
|
+
resourceKey
|
|
46
|
+
.replace('templates/pnpm-templates/npmrc', '.npmrc')
|
|
47
|
+
.replace('.handlebars', ''),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fs.chmodSync(path.join(generator.outputPath, '.husky', 'pre-commit'), '755');
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default async (context: GeneratorContext, generator: GeneratorCore) => {
|
|
55
|
+
const appApi = new AppAPI(context, generator);
|
|
56
|
+
const { locale } = context.config;
|
|
57
|
+
appApi.i18n.changeLanguage({ locale });
|
|
58
|
+
|
|
59
|
+
if (!(await appApi.checkEnvironment())) {
|
|
60
|
+
// eslint-disable-next-line no-process-exit
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
generator.logger.debug(`start run @modern-js/base-generator`);
|
|
65
|
+
generator.logger.debug(`context=${JSON.stringify(context)}`);
|
|
66
|
+
generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
|
|
67
|
+
|
|
68
|
+
await handleTemplateFile(context, generator, appApi);
|
|
69
|
+
|
|
70
|
+
if (context.handleForged) {
|
|
71
|
+
await context.handleForged('custom', context, context.config.hasPlugin);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
generator.logger.debug(`forge @modern-js/base-generator succeed `);
|
|
75
|
+
};
|