@wzyjs/cli 0.0.8 → 0.0.11
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 +19 -25
- package/dist/commands/build/utils.d.ts +4 -4
- package/dist/commands/build/utils.js +22 -11
- package/dist/examples/empty/src/index.d.ts +0 -0
- package/dist/examples/empty/src/index.js +1 -0
- package/dist/examples/fe/src/app.d.ts +9 -0
- package/dist/examples/fe/src/app.js +19 -0
- package/package.json +7 -3
|
@@ -5,7 +5,8 @@ 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 internal_1 = require("@midwayjs/hooks/internal");
|
|
8
|
-
const utils_1 = require("
|
|
8
|
+
const utils_1 = require("@wzyjs/utils");
|
|
9
|
+
const utils_2 = require("./utils");
|
|
9
10
|
const consola = require('consola');
|
|
10
11
|
exports.default = (cli) => {
|
|
11
12
|
cli.command('build', 'cli工具')
|
|
@@ -22,35 +23,28 @@ exports.default = (cli) => {
|
|
|
22
23
|
consola.info('正在清理之前的 build 产物...');
|
|
23
24
|
await fs.promises.rm(outDir, { recursive: true });
|
|
24
25
|
}
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
(0,
|
|
26
|
+
// 项目根目录写个空的 midway.config.js 之后会删除
|
|
27
|
+
const removeConfig = (0, utils_2.writeConfig)(root, {});
|
|
28
|
+
// 合并用户配置
|
|
29
|
+
const productionConfig = (0, utils_2.getProductionConfig)(root);
|
|
29
30
|
consola.info('正在打包前端代码...');
|
|
30
|
-
await (0, umi_1.run)({
|
|
31
|
+
const feBuild = await (0, utils_1.executePromise)((0, umi_1.run)({
|
|
31
32
|
presets: [require.resolve('../../plugins/preset')],
|
|
32
33
|
}).catch((e) => {
|
|
33
34
|
console.error(e);
|
|
34
35
|
process.exit(1);
|
|
35
|
-
});
|
|
36
|
-
consola.success('
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
const productionConfig = {
|
|
46
|
-
routes: userConfig.routes,
|
|
47
|
-
};
|
|
48
|
-
fs.writeFileSync((0, path_1.join)(outDir, 'midway.config.js'), `module.exports = ${JSON.stringify(productionConfig, null, 2)}`, 'utf-8');
|
|
49
|
-
fs.cpSync((0, path_1.join)(root, 'package.json'), (0, path_1.join)(outDir, 'package.json.bak'));
|
|
36
|
+
}));
|
|
37
|
+
consola.success('打包前端代码成功~ 耗时:' + feBuild.time / 1000 + 's');
|
|
38
|
+
// 创建服务端渲染前端页面的 render 函数
|
|
39
|
+
(0, utils_2.createRender)((0, path_1.join)(root, outDir));
|
|
40
|
+
// 写 midway.config.js 到 dist 目录
|
|
41
|
+
(0, utils_2.writeConfig)(outDir, productionConfig);
|
|
42
|
+
// 写 package.json 到 dist 目录
|
|
43
|
+
fs.cpSync((0, path_1.join)(root, 'package.json'), (0, path_1.join)(outDir, 'package.json'));
|
|
50
44
|
consola.info('正在打包后端代码...', root);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
consola.success(
|
|
45
|
+
const rdBuild = await (0, utils_1.executePromise)((0, utils_2.buildServer)(root, outDir));
|
|
46
|
+
// 删除 midway.config.js
|
|
47
|
+
removeConfig();
|
|
48
|
+
consola.success(`打包后端代码成功~ 耗时:` + rdBuild.time / 1000 + 's');
|
|
55
49
|
});
|
|
56
50
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const createRender: (dist: string) => void;
|
|
2
|
-
export declare const executePromise: (promise: Promise<any>) => Promise<{
|
|
3
|
-
result: any;
|
|
4
|
-
time: number;
|
|
5
|
-
}>;
|
|
6
2
|
export declare const buildServer: (cwd: string, outDir: string) => Promise<void>;
|
|
3
|
+
export declare const writeConfig: (outDir: string, productionConfig: any) => () => void;
|
|
4
|
+
export declare const getProductionConfig: (root: string) => {
|
|
5
|
+
routes: import("@midwayjs/hooks/internal").MidwayRoute[] | undefined;
|
|
6
|
+
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
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
|
+
const internal_1 = require("@midwayjs/hooks/internal");
|
|
9
10
|
const createRender = (dist) => {
|
|
10
11
|
const code = `exports.default = require('@midwayjs/serve').Serve('/*', { dir: '_client', isKit: true });`;
|
|
11
12
|
const file = (0, path_1.join)(dist, '_serve/index.js');
|
|
@@ -13,16 +14,6 @@ const createRender = (dist) => {
|
|
|
13
14
|
fs.writeFileSync(file, code, 'utf-8');
|
|
14
15
|
};
|
|
15
16
|
exports.createRender = createRender;
|
|
16
|
-
const executePromise = async (promise) => {
|
|
17
|
-
const start = Date.now();
|
|
18
|
-
const result = await promise;
|
|
19
|
-
const time = Date.now() - start;
|
|
20
|
-
return {
|
|
21
|
-
result,
|
|
22
|
-
time,
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
exports.executePromise = executePromise;
|
|
26
17
|
const buildServer = async (cwd, outDir) => {
|
|
27
18
|
const core = new command_core_1.CommandCore({
|
|
28
19
|
commands: ['build'],
|
|
@@ -40,3 +31,23 @@ const buildServer = async (cwd, outDir) => {
|
|
|
40
31
|
await core.invoke();
|
|
41
32
|
};
|
|
42
33
|
exports.buildServer = buildServer;
|
|
34
|
+
const writeConfig = (outDir, productionConfig) => {
|
|
35
|
+
fs.writeFileSync((0, path_1.join)(outDir, 'midway.config.js'), `module.exports = ${JSON.stringify(productionConfig, null, 2)}`, 'utf-8');
|
|
36
|
+
return () => {
|
|
37
|
+
fs.removeSync((0, path_1.join)(outDir, 'midway.config.js'));
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.writeConfig = writeConfig;
|
|
41
|
+
const getProductionConfig = (root) => {
|
|
42
|
+
const userConfig = Object.assign({ static: true }, (0, internal_1.getConfig)(root));
|
|
43
|
+
if (Array.isArray(userConfig.routes)) {
|
|
44
|
+
userConfig.routes.push({
|
|
45
|
+
baseDir: '_serve',
|
|
46
|
+
basePath: '/',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
routes: userConfig.routes,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
exports.getProductionConfig = getProductionConfig;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// 运行时配置
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.layout = exports.getInitialState = void 0;
|
|
5
|
+
// 全局初始化数据配置,用于 Layout 用户信息和权限初始化
|
|
6
|
+
// 更多信息见文档:https://next.umijs.org/docs/api/runtime-config#getinitialstate
|
|
7
|
+
async function getInitialState() {
|
|
8
|
+
return { name: '@umijs/max' };
|
|
9
|
+
}
|
|
10
|
+
exports.getInitialState = getInitialState;
|
|
11
|
+
const layout = () => {
|
|
12
|
+
return {
|
|
13
|
+
logo: 'https://img.alicdn.com/tfs/TB1YHEpwUT1gK0jSZFhXXaAtVXa-28-27.svg',
|
|
14
|
+
menu: {
|
|
15
|
+
locale: false,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
exports.layout = layout;
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wzyjs/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "description",
|
|
5
5
|
"author": "wzy",
|
|
6
6
|
"license": "ISC",
|
|
7
|
-
"type": "commonjs",
|
|
8
7
|
"scripts": {
|
|
9
8
|
"dev": "tsc -w",
|
|
10
9
|
"build": "tsc"
|
|
@@ -21,6 +20,7 @@
|
|
|
21
20
|
"@midwayjs/command-core": "^1.3.14",
|
|
22
21
|
"@midwayjs/hooks": "^3.0.1",
|
|
23
22
|
"@umijs/plugins": "^4.0.28",
|
|
23
|
+
"@wzyjs/utils": "^0.0.11",
|
|
24
24
|
"cac": "^6.7.14",
|
|
25
25
|
"consola": "^2.15.3",
|
|
26
26
|
"fs-extra": "^10.1.0",
|
|
@@ -38,5 +38,9 @@
|
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://gitee.com/wang-zhenyu/app.git"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "00865dfbf006e37041dc48b3f8d6e4191d3bf75f"
|
|
42
46
|
}
|