@modern-js/dependence-generator 3.7.0 → 3.7.1
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 +10 -10
- package/src/index.ts +0 -140
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "3.7.
|
|
18
|
+
"version": "3.7.1",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"main": "./dist/index.js",
|
|
21
21
|
"files": [
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
"/dist/index.js"
|
|
24
24
|
],
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@modern-js/codesmith": "2.6.
|
|
27
|
-
"@modern-js/codesmith-utils": "2.6.
|
|
28
|
-
"@modern-js/codesmith-api-app": "2.6.
|
|
29
|
-
"@modern-js/codesmith-api-json": "2.6.
|
|
26
|
+
"@modern-js/codesmith": "2.6.5",
|
|
27
|
+
"@modern-js/codesmith-utils": "2.6.5",
|
|
28
|
+
"@modern-js/codesmith-api-app": "2.6.5",
|
|
29
|
+
"@modern-js/codesmith-api-json": "2.6.5",
|
|
30
30
|
"@types/jest": "^29",
|
|
31
31
|
"@types/node": "^14",
|
|
32
32
|
"jest": "^29",
|
|
33
33
|
"typescript": "^5",
|
|
34
|
-
"@modern-js/generator-common": "3.7.
|
|
35
|
-
"@modern-js/generator-utils": "3.7.
|
|
36
|
-
"@
|
|
37
|
-
"@scripts/
|
|
38
|
-
"@
|
|
34
|
+
"@modern-js/generator-common": "3.7.1",
|
|
35
|
+
"@modern-js/generator-utils": "3.7.1",
|
|
36
|
+
"@scripts/build": "2.60.5",
|
|
37
|
+
"@scripts/jest-config": "2.60.5",
|
|
38
|
+
"@modern-js/plugin-i18n": "2.60.5"
|
|
39
39
|
},
|
|
40
40
|
"sideEffects": false,
|
|
41
41
|
"publishConfig": {
|
package/src/index.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import type { 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 as commonI18n } from '@modern-js/generator-common';
|
|
6
|
-
import { fs, chalk, getModernConfigFile } from '@modern-js/generator-utils';
|
|
7
|
-
import { i18n, localeKeys } from './locale';
|
|
8
|
-
|
|
9
|
-
export const handleTemplateFile = async (
|
|
10
|
-
context: GeneratorContext,
|
|
11
|
-
generator: GeneratorCore,
|
|
12
|
-
) => {
|
|
13
|
-
const jsonAPI = new JsonAPI(generator);
|
|
14
|
-
const {
|
|
15
|
-
devDependencies,
|
|
16
|
-
dependencies,
|
|
17
|
-
peerDependencies,
|
|
18
|
-
appendTypeContent,
|
|
19
|
-
sourceTypeFile,
|
|
20
|
-
projectPath,
|
|
21
|
-
} = context.config;
|
|
22
|
-
|
|
23
|
-
const setJSON: Record<string, Record<string, string>> = {};
|
|
24
|
-
Object.keys(devDependencies || {}).forEach(key => {
|
|
25
|
-
setJSON[`devDependencies.${key}`] = devDependencies[key];
|
|
26
|
-
});
|
|
27
|
-
Object.keys(dependencies || {}).forEach(key => {
|
|
28
|
-
setJSON[`dependencies.${key}`] = dependencies[key];
|
|
29
|
-
});
|
|
30
|
-
Object.keys(peerDependencies || {}).forEach(key => {
|
|
31
|
-
setJSON[`peerDependencies.${key}`] = peerDependencies[key];
|
|
32
|
-
});
|
|
33
|
-
if (Object.keys(setJSON).length > 0) {
|
|
34
|
-
await jsonAPI.update(
|
|
35
|
-
context.materials.default.get(
|
|
36
|
-
path.join(projectPath || '', 'package.json'),
|
|
37
|
-
),
|
|
38
|
-
{
|
|
39
|
-
query: {},
|
|
40
|
-
update: { $set: setJSON },
|
|
41
|
-
},
|
|
42
|
-
true,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const appDir = context.materials.default.basePath;
|
|
47
|
-
const isTs = fs.existsSync(
|
|
48
|
-
path.join(appDir, projectPath || '', 'tsconfig.json'),
|
|
49
|
-
);
|
|
50
|
-
if (appendTypeContent && isTs) {
|
|
51
|
-
const typePath = path.join(
|
|
52
|
-
appDir,
|
|
53
|
-
projectPath || '',
|
|
54
|
-
'src',
|
|
55
|
-
sourceTypeFile || 'modern-app-env.d.ts',
|
|
56
|
-
);
|
|
57
|
-
if (fs.existsSync(typePath)) {
|
|
58
|
-
const npmrc = fs.readFileSync(typePath, 'utf-8');
|
|
59
|
-
if (!npmrc.includes(appendTypeContent)) {
|
|
60
|
-
fs.writeFileSync(typePath, `${appendTypeContent}\n${npmrc}`, 'utf-8');
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
fs.ensureFileSync(typePath);
|
|
64
|
-
fs.writeFileSync(typePath, appendTypeContent, 'utf-8');
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export default async (context: GeneratorContext, generator: GeneratorCore) => {
|
|
70
|
-
const appApi = new AppAPI(context, generator);
|
|
71
|
-
|
|
72
|
-
// when use new command, listeners will create more than 10
|
|
73
|
-
process.setMaxListeners(20);
|
|
74
|
-
|
|
75
|
-
const { locale } = context.config;
|
|
76
|
-
commonI18n.changeLanguage({ locale });
|
|
77
|
-
i18n.changeLanguage({ locale });
|
|
78
|
-
appApi.i18n.changeLanguage({ locale });
|
|
79
|
-
|
|
80
|
-
if (!(await appApi.checkEnvironment())) {
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
generator.logger.debug(`🚀 [Start Run Dependence Generator]`);
|
|
85
|
-
generator.logger.debug(
|
|
86
|
-
'💡 [Current Config]:',
|
|
87
|
-
JSON.stringify(context.config),
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
await handleTemplateFile(context, generator);
|
|
91
|
-
|
|
92
|
-
if (!context.config.isSubGenerator) {
|
|
93
|
-
await appApi.runInstall(undefined, { ignoreScripts: true });
|
|
94
|
-
if (!context.config.pluginName) {
|
|
95
|
-
appApi.showSuccessInfo();
|
|
96
|
-
} else {
|
|
97
|
-
const appDir = context.materials.default.basePath;
|
|
98
|
-
const configFile = await getModernConfigFile(appDir);
|
|
99
|
-
const isTS = configFile.endsWith('ts');
|
|
100
|
-
const { pluginName, pluginDependence, shouldUsePluginNameExport } =
|
|
101
|
-
context.config;
|
|
102
|
-
console.info(
|
|
103
|
-
chalk.green(`\n[INFO]`),
|
|
104
|
-
`${i18n.t(localeKeys.success)}`,
|
|
105
|
-
chalk.yellow.bold(`${configFile}`),
|
|
106
|
-
':',
|
|
107
|
-
'\n',
|
|
108
|
-
);
|
|
109
|
-
if (shouldUsePluginNameExport) {
|
|
110
|
-
console.info(
|
|
111
|
-
chalk.yellow.bold(
|
|
112
|
-
`import { ${pluginName} } from '${pluginDependence}';`,
|
|
113
|
-
),
|
|
114
|
-
);
|
|
115
|
-
} else {
|
|
116
|
-
console.info(
|
|
117
|
-
chalk.yellow.bold(`import ${pluginName} from '${pluginDependence}';`),
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (isTS) {
|
|
122
|
-
console.info(`
|
|
123
|
-
export default defineConfig({
|
|
124
|
-
...,
|
|
125
|
-
plugins: [..., ${chalk.yellow.bold(`${pluginName}()`)}],
|
|
126
|
-
});
|
|
127
|
-
`);
|
|
128
|
-
} else {
|
|
129
|
-
console.info(`
|
|
130
|
-
module.exports = {
|
|
131
|
-
...,
|
|
132
|
-
plugins: [..., ${chalk.yellow.bold(`${pluginName}()`)}],
|
|
133
|
-
};
|
|
134
|
-
`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
generator.logger.debug(`🌟 [End Run Dependence Generator]`);
|
|
140
|
-
};
|