@wzyjs/cli 0.0.31 → 0.0.32
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 +29 -22
- package/dist/commands/build/utils.d.ts +5 -1
- package/dist/commands/build/utils.js +19 -3
- package/dist/commands/hack/index.d.ts +3 -0
- package/dist/commands/hack/index.js +35 -0
- package/dist/commands/start/index.js +3 -3
- package/dist/index.js +3 -1
- package/package.json +7 -5
|
@@ -3,11 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
6
|
-
|
|
6
|
+
// import { run } from 'umi'
|
|
7
|
+
// @ts-ignore
|
|
7
8
|
const internal_1 = require("@midwayjs/hooks/internal");
|
|
8
|
-
const utils_1 = require("
|
|
9
|
-
const utils_2 = require("./utils");
|
|
10
|
-
const { consola } = require('@wzyjs/utils');
|
|
9
|
+
const utils_1 = require("./utils");
|
|
11
10
|
exports.default = (cli) => {
|
|
12
11
|
cli.command('build', 'cli工具')
|
|
13
12
|
.option('--outDir [dir]', `[string] output directory (default: dist)`, {
|
|
@@ -20,31 +19,39 @@ exports.default = (cli) => {
|
|
|
20
19
|
const { outDir, clean } = options;
|
|
21
20
|
const root = (0, internal_1.getProjectRoot)();
|
|
22
21
|
if (clean && fs.existsSync(outDir)) {
|
|
23
|
-
|
|
22
|
+
console.info('正在清理之前的 build 产物...');
|
|
24
23
|
await fs.promises.rm(outDir, { recursive: true });
|
|
25
24
|
}
|
|
26
25
|
// 项目根目录写个空的 midway.config.js 之后会删除
|
|
27
|
-
const removeConfig =
|
|
26
|
+
// const removeConfig = writeConfig(root, {})
|
|
28
27
|
// 合并用户配置
|
|
29
|
-
const productionConfig = (0,
|
|
30
|
-
|
|
31
|
-
const feBuild = await
|
|
32
|
-
|
|
33
|
-
}).catch((e) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}))
|
|
37
|
-
|
|
28
|
+
const productionConfig = (0, utils_1.getProductionConfig)(root);
|
|
29
|
+
// console.info('正在打包前端代码...')
|
|
30
|
+
// const feBuild = await executePromise(run({
|
|
31
|
+
// presets: [require.resolve('../../plugins/preset')],
|
|
32
|
+
// }).catch((e: any) => {
|
|
33
|
+
// console.error(e)
|
|
34
|
+
// process.exit(1)
|
|
35
|
+
// }))
|
|
36
|
+
// console.info('打包前端代码成功~ 耗时:' + feBuild.time / 1000 + 's')
|
|
38
37
|
// 创建服务端渲染前端页面的 render 函数
|
|
39
|
-
(0,
|
|
38
|
+
(0, utils_1.createRender)((0, path_1.join)(root, outDir));
|
|
40
39
|
// 写 midway.config.js 到 dist 目录
|
|
41
|
-
(0,
|
|
40
|
+
(0, utils_1.writeConfig)(outDir, productionConfig);
|
|
42
41
|
// 写 package.json 到 dist 目录
|
|
43
42
|
// fs.cpSync(join(root, 'package.json'), join(outDir, 'package.json'))
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
console.info('正在打包后端代码...', root);
|
|
44
|
+
// let rdBuild
|
|
45
|
+
try {
|
|
46
|
+
console.log(666, root, outDir);
|
|
47
|
+
await (0, utils_1.buildServer)(root, outDir);
|
|
48
|
+
// 删除 midway.config.js
|
|
49
|
+
// removeConfig()
|
|
50
|
+
// console.info(`打包后端代码成功~ 耗时:` + rdBuild.time / 1000 + 's')
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
console.error('打包后端代码失败', err);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
49
56
|
});
|
|
50
57
|
};
|
|
@@ -2,5 +2,9 @@ export declare const createRender: (dist: string) => void;
|
|
|
2
2
|
export declare const buildServer: (cwd: string, outDir: string) => Promise<void>;
|
|
3
3
|
export declare const writeConfig: (outDir: string, productionConfig: any) => () => void;
|
|
4
4
|
export declare const getProductionConfig: (root: string) => {
|
|
5
|
-
routes:
|
|
5
|
+
routes: any;
|
|
6
6
|
};
|
|
7
|
+
export declare const executePromise: (promise: Promise<any>) => Promise<{
|
|
8
|
+
result: any;
|
|
9
|
+
time: number;
|
|
10
|
+
}>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProductionConfig = exports.writeConfig = exports.buildServer = exports.createRender = void 0;
|
|
3
|
+
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"));
|
|
7
7
|
const command_core_1 = require("@midwayjs/command-core");
|
|
8
8
|
const cli_plugin_build_1 = require("@midwayjs/cli-plugin-build");
|
|
9
|
+
// @ts-ignore
|
|
9
10
|
const internal_1 = require("@midwayjs/hooks/internal");
|
|
10
11
|
const createRender = (dist) => {
|
|
11
12
|
const code = `exports.default = require('@midwayjs/serve').Serve('/*', { dir: '_client', isKit: true });`;
|
|
@@ -27,8 +28,13 @@ const buildServer = async (cwd, outDir) => {
|
|
|
27
28
|
},
|
|
28
29
|
});
|
|
29
30
|
core.addPlugin(cli_plugin_build_1.BuildPlugin);
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
try {
|
|
32
|
+
await core.ready();
|
|
33
|
+
await core.invoke();
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
console.log(666, 'err', err);
|
|
37
|
+
}
|
|
32
38
|
};
|
|
33
39
|
exports.buildServer = buildServer;
|
|
34
40
|
const writeConfig = (outDir, productionConfig) => {
|
|
@@ -51,3 +57,13 @@ const getProductionConfig = (root) => {
|
|
|
51
57
|
};
|
|
52
58
|
};
|
|
53
59
|
exports.getProductionConfig = getProductionConfig;
|
|
60
|
+
const executePromise = async (promise) => {
|
|
61
|
+
const start = Date.now();
|
|
62
|
+
const result = await promise;
|
|
63
|
+
const time = Date.now() - start;
|
|
64
|
+
return {
|
|
65
|
+
result,
|
|
66
|
+
time,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
exports.executePromise = executePromise;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
5
|
+
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
|
+
};
|
|
23
|
+
exports.default = (cli) => {
|
|
24
|
+
cli.command('hack', 'cli工具')
|
|
25
|
+
.action(() => {
|
|
26
|
+
console.log(666, path.resolve(__dirname));
|
|
27
|
+
replaceContentInFile('/Users/wangzhenyu/Code/work/libs/cli/node_modules/@umijs/preset-umi/dist/libs/scan.js', 'exportsFields: []', `exportsFields: ['exports'],
|
|
28
|
+
conditionNames: ["import", "require"]`);
|
|
29
|
+
replaceContentInFile('/Users/wangzhenyu/Code/work/libs/cli/node_modules/enhanced-resolve/lib/ExportsFieldPlugin.js', 'paths = fieldProcessor(remainingRequest, this.conditionNames);', `paths = fieldProcessor(remainingRequest, this.conditionNames);
|
|
30
|
+
if (paths.length === 0 && remainingRequest === '.' && request.descriptionFileData.name === 'typeorm') {
|
|
31
|
+
paths = ['./index.mjs']
|
|
32
|
+
}
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -4,8 +4,8 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
6
6
|
const bootstrap_1 = require("@midwayjs/bootstrap");
|
|
7
|
+
// @ts-ignore
|
|
7
8
|
const internal_1 = require("@midwayjs/hooks/internal");
|
|
8
|
-
const { consola } = require('@wzyjs/utils');
|
|
9
9
|
exports.default = (cli) => {
|
|
10
10
|
cli.command('start', 'start')
|
|
11
11
|
.option('-p, --port <port>', '[number] specify port', { default: 3000 })
|
|
@@ -13,7 +13,7 @@ exports.default = (cli) => {
|
|
|
13
13
|
const root = (0, path_1.resolve)('dist');
|
|
14
14
|
// 判断目录是否存在
|
|
15
15
|
if (!fs.existsSync(root)) {
|
|
16
|
-
|
|
16
|
+
console.error('dist 目录不存在,请先执行 build 命令');
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
const config = {
|
|
@@ -30,6 +30,6 @@ exports.default = (cli) => {
|
|
|
30
30
|
ignore: ['**/_client/**'],
|
|
31
31
|
});
|
|
32
32
|
await server.run();
|
|
33
|
-
|
|
33
|
+
console.log(`Your application is running at http://localhost:${options.port}`);
|
|
34
34
|
});
|
|
35
35
|
};
|
package/dist/index.js
CHANGED
|
@@ -6,11 +6,13 @@ const dev_1 = tslib_1.__importDefault(require("./commands/dev"));
|
|
|
6
6
|
const build_1 = tslib_1.__importDefault(require("./commands/build"));
|
|
7
7
|
const start_1 = tslib_1.__importDefault(require("./commands/start"));
|
|
8
8
|
const merge_1 = tslib_1.__importDefault(require("./commands/merge"));
|
|
9
|
+
const hack_1 = tslib_1.__importDefault(require("./commands/hack"));
|
|
9
10
|
const cli = (0, cac_1.default)();
|
|
10
11
|
(0, dev_1.default)(cli);
|
|
11
12
|
(0, build_1.default)(cli);
|
|
12
13
|
(0, start_1.default)(cli);
|
|
13
14
|
(0, merge_1.default)(cli);
|
|
15
|
+
(0, hack_1.default)(cli);
|
|
14
16
|
cli.help();
|
|
15
|
-
cli.version('0.0.
|
|
17
|
+
cli.version('0.0.2');
|
|
16
18
|
cli.parse();
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wzyjs/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "description",
|
|
5
5
|
"author": "wzy",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "tsc -w",
|
|
9
|
-
"build": "tsc"
|
|
9
|
+
"build": "tsc --noEmitOnError false",
|
|
10
|
+
"build-link": "npm run build && npm link"
|
|
10
11
|
},
|
|
11
12
|
"files": [
|
|
12
13
|
"bin",
|
|
@@ -19,9 +20,7 @@
|
|
|
19
20
|
"@midwayjs/bootstrap": "^3.7.1",
|
|
20
21
|
"@midwayjs/cli-plugin-build": "^1.3.14",
|
|
21
22
|
"@midwayjs/command-core": "^1.3.14",
|
|
22
|
-
"@midwayjs/hooks": "^3.0.1",
|
|
23
23
|
"@umijs/plugins": "^4.0.28",
|
|
24
|
-
"@wzyjs/utils": "^0.0.31",
|
|
25
24
|
"cac": "^6.7.14",
|
|
26
25
|
"fs-extra": "^10.1.0",
|
|
27
26
|
"rc-field-form": "^1.32.2",
|
|
@@ -35,6 +34,9 @@
|
|
|
35
34
|
"@types/node": "^18.11.9",
|
|
36
35
|
"@types/react-router-dom": "^4.3.1"
|
|
37
36
|
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@midwayjs/hooks": "^3.1.6"
|
|
39
|
+
},
|
|
38
40
|
"publishConfig": {
|
|
39
41
|
"access": "public"
|
|
40
42
|
},
|
|
@@ -42,5 +44,5 @@
|
|
|
42
44
|
"type": "git",
|
|
43
45
|
"url": "https://gitee.com/wang-zhenyu/app.git"
|
|
44
46
|
},
|
|
45
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "1b21293a5dceaf179fb8c038beca93e048bdec8c"
|
|
46
48
|
}
|