@modern-js/dependence-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 +95 -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
|
"main": "./dist/index.js",
|
|
17
17
|
"files": [
|
|
@@ -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,95 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
|
|
3
|
+
import { AppAPI } from '@modern-js/codesmith-api-app';
|
|
4
|
+
import { JsonAPI } from '@modern-js/codesmith-api-json';
|
|
5
|
+
import { i18n } from '@modern-js/generator-common';
|
|
6
|
+
import { fs } from '@modern-js/generator-utils';
|
|
7
|
+
|
|
8
|
+
export const handleTemplateFile = async (
|
|
9
|
+
context: GeneratorContext,
|
|
10
|
+
generator: GeneratorCore,
|
|
11
|
+
) => {
|
|
12
|
+
const jsonAPI = new JsonAPI(generator);
|
|
13
|
+
const {
|
|
14
|
+
devDependencies,
|
|
15
|
+
dependencies,
|
|
16
|
+
peerDependencies,
|
|
17
|
+
appendTypeContent,
|
|
18
|
+
sourceTypeFile,
|
|
19
|
+
projectPath,
|
|
20
|
+
} = context.config;
|
|
21
|
+
|
|
22
|
+
const setJSON: Record<string, Record<string, string>> = {};
|
|
23
|
+
Object.keys(devDependencies || {}).forEach(key => {
|
|
24
|
+
setJSON[`devDependencies.${key}`] = devDependencies[key];
|
|
25
|
+
});
|
|
26
|
+
Object.keys(dependencies || {}).forEach(key => {
|
|
27
|
+
setJSON[`dependencies.${key}`] = dependencies[key];
|
|
28
|
+
});
|
|
29
|
+
Object.keys(peerDependencies || {}).forEach(key => {
|
|
30
|
+
setJSON[`peerDependencies.${key}`] = peerDependencies[key];
|
|
31
|
+
});
|
|
32
|
+
if (Object.keys(setJSON).length > 0) {
|
|
33
|
+
await jsonAPI.update(
|
|
34
|
+
context.materials.default.get(
|
|
35
|
+
path.join(projectPath || '', 'package.json'),
|
|
36
|
+
),
|
|
37
|
+
{
|
|
38
|
+
query: {},
|
|
39
|
+
update: { $set: setJSON },
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const appDir = context.materials.default.basePath;
|
|
45
|
+
const isTs = fs.existsSync(
|
|
46
|
+
path.join(appDir, projectPath || '', 'tsconfig.json'),
|
|
47
|
+
);
|
|
48
|
+
if (appendTypeContent && isTs) {
|
|
49
|
+
const typePath = path.join(
|
|
50
|
+
appDir,
|
|
51
|
+
projectPath || '',
|
|
52
|
+
'src',
|
|
53
|
+
sourceTypeFile || 'modern-app-env.d.ts',
|
|
54
|
+
);
|
|
55
|
+
if (fs.existsSync(typePath)) {
|
|
56
|
+
const npmrc = fs.readFileSync(typePath, 'utf-8');
|
|
57
|
+
if (!npmrc.includes(appendTypeContent)) {
|
|
58
|
+
fs.writeFileSync(typePath, `${appendTypeContent}\n${npmrc}`, 'utf-8');
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
fs.ensureFileSync(typePath);
|
|
62
|
+
fs.writeFileSync(typePath, appendTypeContent, 'utf-8');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default async (context: GeneratorContext, generator: GeneratorCore) => {
|
|
68
|
+
const appApi = new AppAPI(context, generator);
|
|
69
|
+
|
|
70
|
+
// when use new command, listeners will create more than 10
|
|
71
|
+
process.setMaxListeners(20);
|
|
72
|
+
|
|
73
|
+
const { locale } = context.config;
|
|
74
|
+
i18n.changeLanguage({ locale });
|
|
75
|
+
appApi.i18n.changeLanguage({ locale });
|
|
76
|
+
|
|
77
|
+
if (!(await appApi.checkEnvironment())) {
|
|
78
|
+
// eslint-disable-next-line no-process-exit
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
generator.logger.debug(`start run @modern-js/dependence-generator`);
|
|
83
|
+
generator.logger.debug(`context=${JSON.stringify(context)}`);
|
|
84
|
+
generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
|
|
85
|
+
|
|
86
|
+
await handleTemplateFile(context, generator);
|
|
87
|
+
|
|
88
|
+
if (!context.config.isSubGenerator) {
|
|
89
|
+
await appApi.runInstall(undefined, { ignoreScripts: true });
|
|
90
|
+
|
|
91
|
+
appApi.showSuccessInfo();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
generator.logger.debug(`forge @modern-js/dependence-generator succeed `);
|
|
95
|
+
};
|