@wzyjs/cli 0.1.6 → 0.1.8
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/dist/commands/build/index.js +2 -2
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +26 -19
- package/package.json +1 -1
|
@@ -21,10 +21,10 @@ exports.default = (cli) => {
|
|
|
21
21
|
console.info('正在清理之前的 build 产物...');
|
|
22
22
|
await fs.promises.rm(outDir, { recursive: true });
|
|
23
23
|
}
|
|
24
|
+
await (0, utils_1.replaceContentInFile)(process.cwd() + '/tsconfig.json', '"extends": "./src/.umi/tsconfig.json",', '');
|
|
25
|
+
await (0, utils_1.replaceContentInFile)(process.cwd() + '/tsconfig.json', '"./src/.umi/typings"', '');
|
|
24
26
|
// 合并用户配置
|
|
25
27
|
const productionConfig = (0, utils_1.getProductionConfig)(root);
|
|
26
|
-
(0, utils_1.replaceContentInFile)(process.cwd() + '/tsconfig.json', '"extends": "./src/.umi/tsconfig.json",', '');
|
|
27
|
-
(0, utils_1.replaceContentInFile)(process.cwd() + '/tsconfig.json', '"./src/.umi/typings"', '');
|
|
28
28
|
console.info('正在打包前端代码...');
|
|
29
29
|
const feBuild = await (0, utils_1.executePromise)((0, umi_1.run)({
|
|
30
30
|
presets: [require.resolve('../../plugins/preset')],
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export declare const executePromise: (promise: Promise<any>) => Promise<{
|
|
|
8
8
|
result: any;
|
|
9
9
|
time: number;
|
|
10
10
|
}>;
|
|
11
|
-
export declare const replaceContentInFile: (filePath: string, targetContent: string, replacement: string) => void
|
|
11
|
+
export declare const replaceContentInFile: (filePath: string, targetContent: string, replacement: string) => Promise<void>;
|
package/dist/utils/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const command_core_1 = require("@midwayjs/command-core");
|
|
|
8
8
|
const cli_plugin_build_1 = require("@midwayjs/cli-plugin-build");
|
|
9
9
|
const hooks_internal_1 = require("@midwayjs/hooks-internal");
|
|
10
10
|
const createRender = (dist) => {
|
|
11
|
-
const code = `exports.default = require('@midwayjs/serve').Serve('/*', { dir: '_client', isKit: true })
|
|
11
|
+
const code = `exports.default = require('@midwayjs/serve').Serve('/*', { dir: '_client', isKit: true })`;
|
|
12
12
|
const file = (0, path_1.join)(dist, '_serve/index.js');
|
|
13
13
|
fs.ensureFileSync(file);
|
|
14
14
|
fs.writeFileSync(file, code, 'utf-8');
|
|
@@ -62,27 +62,34 @@ const executePromise = async (promise) => {
|
|
|
62
62
|
};
|
|
63
63
|
exports.executePromise = executePromise;
|
|
64
64
|
const replaceContentInFile = (filePath, targetContent, replacement) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
console.error(`读取文件时发生错误:${err}`);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (data.includes(replacement)) {
|
|
71
|
-
console.error(`已替换过:${filePath}`);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (!data.includes(targetContent)) {
|
|
75
|
-
console.error(`不包含目标内容:${targetContent}`);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const updatedData = data.replaceAll(targetContent, replacement);
|
|
79
|
-
fs.writeFile(filePath, updatedData, 'utf8', (err) => {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
fs.readFile(filePath, 'utf8', (err, data) => {
|
|
80
67
|
if (err) {
|
|
81
|
-
console.error(
|
|
68
|
+
console.error(`读取文件时发生错误:${err}`);
|
|
69
|
+
reject(err);
|
|
70
|
+
return;
|
|
82
71
|
}
|
|
83
|
-
|
|
84
|
-
console.
|
|
72
|
+
if (replacement && data.includes(replacement)) {
|
|
73
|
+
console.error(`已替换过:${filePath}`);
|
|
74
|
+
resolve();
|
|
75
|
+
return;
|
|
85
76
|
}
|
|
77
|
+
if (!data.includes(targetContent)) {
|
|
78
|
+
console.error(`不包含目标内容:${targetContent}`);
|
|
79
|
+
reject(`不包含目标内容:${targetContent}`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const updatedData = data.replaceAll(targetContent, replacement);
|
|
83
|
+
fs.writeFile(filePath, updatedData, 'utf8', (err) => {
|
|
84
|
+
if (err) {
|
|
85
|
+
console.error(`写入文件时发生错误:${err}`);
|
|
86
|
+
reject(err);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
console.log(`成功替换文件中的内容!`);
|
|
90
|
+
resolve();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
86
93
|
});
|
|
87
94
|
});
|
|
88
95
|
};
|