@wzyjs/cli 0.0.35 → 0.1.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.
@@ -5,7 +5,7 @@ const path_1 = require("path");
5
5
  const fs = tslib_1.__importStar(require("fs-extra"));
6
6
  const umi_1 = require("umi");
7
7
  const hooks_internal_1 = require("@midwayjs/hooks-internal");
8
- const utils_1 = require("./utils");
8
+ const utils_1 = require("../../utils");
9
9
  exports.default = (cli) => {
10
10
  cli.command('build', 'cli工具')
11
11
  .option('--outDir [dir]', `[string] output directory (default: dist)`, {
@@ -21,8 +21,6 @@ exports.default = (cli) => {
21
21
  console.info('正在清理之前的 build 产物...');
22
22
  await fs.promises.rm(outDir, { recursive: true });
23
23
  }
24
- // 项目根目录写个空的 midway.config.js 之后会删除
25
- // const removeConfig = writeConfig(root, {})
26
24
  // 合并用户配置
27
25
  const productionConfig = (0, utils_1.getProductionConfig)(root);
28
26
  console.info('正在打包前端代码...');
@@ -37,13 +35,10 @@ exports.default = (cli) => {
37
35
  (0, utils_1.createRender)((0, path_1.join)(root, outDir));
38
36
  // 写 midway.config.js 到 dist 目录
39
37
  (0, utils_1.writeConfig)(outDir, productionConfig);
40
- // 写 package.json 到 dist 目录
41
- // fs.cpSync(join(root, 'package.json'), join(outDir, 'package.json'))
42
38
  console.info('正在打包后端代码...', root);
43
39
  try {
40
+ (0, utils_1.replaceContentInFile)(process.cwd() + '/tsconfig.json', '/.umi/', '/.umi-production/');
44
41
  const rdBuild = await (0, utils_1.executePromise)((0, utils_1.buildServer)(root, outDir));
45
- // 删除 midway.config.js
46
- // removeConfig()
47
42
  console.info(`打包后端代码成功~ 耗时:` + rdBuild.time / 1000 + 's');
48
43
  }
49
44
  catch (err) {
@@ -1,33 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const fs = tslib_1.__importStar(require("fs"));
5
4
  const path = tslib_1.__importStar(require("path"));
6
- const replaceContentInFile = (filePath, targetContent, replacement) => {
7
- fs.readFile(filePath, 'utf8', (err, data) => {
8
- if (err) {
9
- console.error(`读取文件时发生错误:${err}`);
10
- return;
11
- }
12
- const updatedData = data.replace(targetContent, replacement);
13
- fs.writeFile(filePath, updatedData, 'utf8', (err) => {
14
- if (err) {
15
- console.error(`写入文件时发生错误:${err}`);
16
- }
17
- else {
18
- console.log(`成功替换文件中的内容!`);
19
- }
20
- });
21
- });
22
- };
5
+ const utils_1 = require("../../utils");
23
6
  exports.default = (cli) => {
24
7
  cli.command('hack', 'cli工具')
25
- .action(() => {
26
- const pwd = process.cwd();
27
- console.log(666, path.resolve(__dirname), pwd);
28
- replaceContentInFile(`${pwd}/node_modules/@umijs/preset-umi/dist/libs/scan.js`, 'exportsFields: []', `exportsFields: ['exports'],
8
+ .option('--pwd [dir]', `[string] pwd directory`, {
9
+ default: path.resolve(__dirname, '../../../'),
10
+ })
11
+ .action(options => {
12
+ const { pwd } = options;
13
+ (0, utils_1.replaceContentInFile)(`${pwd}/node_modules/@umijs/preset-umi/dist/libs/scan.js`, 'exportsFields: []', `exportsFields: ['exports'],
29
14
  conditionNames: ["import", "require"]`);
30
- replaceContentInFile(`${pwd}/node_modules/enhanced-resolve/lib/ExportsFieldPlugin.js`, 'paths = fieldProcessor(remainingRequest, this.conditionNames);', `paths = fieldProcessor(remainingRequest, this.conditionNames);
15
+ (0, utils_1.replaceContentInFile)(`${pwd}/node_modules/enhanced-resolve/lib/ExportsFieldPlugin.js`, 'paths = fieldProcessor(remainingRequest, this.conditionNames);', `paths = fieldProcessor(remainingRequest, this.conditionNames)
31
16
  if (paths.length === 0 && remainingRequest === '.' && request.descriptionFileData.name === 'typeorm') {
32
17
  paths = ['./index.mjs']
33
18
  }
@@ -8,3 +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;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executePromise = exports.getProductionConfig = exports.writeConfig = exports.buildServer = exports.createRender = void 0;
3
+ exports.replaceContentInFile = exports.executePromise = exports.getProductionConfig = exports.writeConfig = exports.buildServer = exports.createRender = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const path_1 = require("path");
6
6
  const fs = tslib_1.__importStar(require("fs-extra"));
@@ -61,3 +61,29 @@ const executePromise = async (promise) => {
61
61
  };
62
62
  };
63
63
  exports.executePromise = executePromise;
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 (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) => {
80
+ if (err) {
81
+ console.error(`写入文件时发生错误:${err}`);
82
+ }
83
+ else {
84
+ console.log(`成功替换文件中的内容!`);
85
+ }
86
+ });
87
+ });
88
+ };
89
+ exports.replaceContentInFile = replaceContentInFile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/cli",
3
- "version": "0.0.35",
3
+ "version": "0.1.1",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "license": "ISC",