@wzyjs/cli 0.1.7 → 0.2.0

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.
@@ -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 replaceContentInFile(process.cwd() + '/tsconfig.json', '"extends": "./src/.umi/tsconfig.json",', '')
25
+ // await 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')],
@@ -37,7 +37,7 @@ exports.default = (cli) => {
37
37
  (0, utils_1.createRender)((0, path_1.join)(root, outDir));
38
38
  // 写 midway.config.js 到 dist 目录
39
39
  (0, utils_1.writeConfig)(outDir, productionConfig);
40
- console.info('正在打包后端代码...', root);
40
+ console.info('正在打包后端代码...', root, outDir);
41
41
  try {
42
42
  const rdBuild = await (0, utils_1.executePromise)((0, utils_1.buildServer)(root, outDir));
43
43
  console.info(`打包后端代码成功~ 耗时:` + rdBuild.time / 1000 + 's');
@@ -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>;
@@ -62,27 +62,34 @@ const executePromise = async (promise) => {
62
62
  };
63
63
  exports.executePromise = executePromise;
64
64
  const replaceContentInFile = (filePath, targetContent, replacement) => {
65
- fs.readFile(filePath, 'utf8', (err, data) => {
66
- if (err) {
67
- console.error(`读取文件时发生错误:${err}`);
68
- return;
69
- }
70
- if (replacement && 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(`写入文件时发生错误:${err}`);
68
+ console.error(`读取文件时发生错误:${err}`);
69
+ reject(err);
70
+ return;
82
71
  }
83
- else {
84
- console.log(`成功替换文件中的内容!`);
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/cli",
3
- "version": "0.1.7",
3
+ "version": "0.2.0",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "license": "ISC",
@@ -44,5 +44,5 @@
44
44
  "type": "git",
45
45
  "url": "https://gitee.com/wang-zhenyu/app.git"
46
46
  },
47
- "gitHead": "1b21293a5dceaf179fb8c038beca93e048bdec8c"
47
+ "gitHead": "9db7e1b57099008c0b7be8d611bbc91f502f2daf"
48
48
  }