@wzyjs/cli 0.2.12 → 0.2.37
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/bin/mi.js +2 -2
- package/dist/index.js +3392 -16
- package/package.json +9 -32
- package/dist/commands/build/index.d.ts +0 -3
- package/dist/commands/build/index.js +0 -71
- package/dist/commands/dev/index.d.ts +0 -3
- package/dist/commands/dev/index.js +0 -24
- package/dist/commands/merge/index.d.ts +0 -3
- package/dist/commands/merge/index.js +0 -13
- package/dist/commands/merge/script.d.ts +0 -6
- package/dist/commands/merge/script.js +0 -58
- package/dist/commands/start/index.d.ts +0 -3
- package/dist/commands/start/index.js +0 -56
- package/dist/index.d.ts +0 -1
- package/dist/plugins/maxAlias.d.ts +0 -3
- package/dist/plugins/maxAlias.js +0 -11
- package/dist/plugins/maxAppData.d.ts +0 -3
- package/dist/plugins/maxAppData.js +0 -10
- package/dist/plugins/maxChecker.d.ts +0 -3
- package/dist/plugins/maxChecker.js +0 -10
- package/dist/plugins/preset.d.ts +0 -4
- package/dist/plugins/preset.js +0 -24
- package/dist/utils/index.d.ts +0 -11
- package/dist/utils/index.js +0 -131
package/package.json
CHANGED
|
@@ -1,48 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wzyjs/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.37",
|
|
4
4
|
"description": "description",
|
|
5
5
|
"author": "wzy",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"build": "
|
|
9
|
-
|
|
7
|
+
"build": "bun build ./src/index.ts --outdir dist --target bun",
|
|
8
|
+
"build-link": "npm run build && bun link"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"mi": "./bin/mi.js"
|
|
10
12
|
},
|
|
11
13
|
"files": [
|
|
12
14
|
"bin",
|
|
13
15
|
"dist"
|
|
14
16
|
],
|
|
15
|
-
"bin": {
|
|
16
|
-
"mi": "./bin/mi.js"
|
|
17
|
-
},
|
|
18
17
|
"dependencies": {
|
|
19
|
-
"@midwayjs/bootstrap": "^3.7.1",
|
|
20
|
-
"@midwayjs/cli-plugin-build": "^1.3.14",
|
|
21
|
-
"@midwayjs/command-core": "^1.3.14",
|
|
22
|
-
"@midwayjs/core": "^3.12.3",
|
|
23
|
-
"@midwayjs/hooks-internal": "^3.1.6",
|
|
24
|
-
"@midwayjs/logger": "^3.4.2",
|
|
25
|
-
"@midwayjs/rpc": "^3.1.6",
|
|
26
|
-
"@umijs/plugins": "^4.0.28",
|
|
27
18
|
"cac": "^6.7.14",
|
|
28
|
-
"fs-extra": "^10.1.0"
|
|
29
|
-
"rc-field-form": "^1.32.2",
|
|
30
|
-
"umi": "^4.0.30",
|
|
31
|
-
"vite": "^2.7.9"
|
|
19
|
+
"fs-extra": "^10.1.0"
|
|
32
20
|
},
|
|
33
21
|
"devDependencies": {
|
|
34
|
-
"@types/
|
|
35
|
-
"@types/fs-extra": "^9.0.13",
|
|
36
|
-
"@types/koa": "^2.13.4",
|
|
37
|
-
"@types/node": "^18.11.9",
|
|
38
|
-
"@types/react-router-dom": "^4.3.1"
|
|
39
|
-
},
|
|
40
|
-
"publishConfig": {
|
|
41
|
-
"access": "public"
|
|
42
|
-
},
|
|
43
|
-
"repository": {
|
|
44
|
-
"type": "git",
|
|
45
|
-
"url": "https://gitee.com/wang-zhenyu/app.git"
|
|
22
|
+
"@types/fs-extra": "^9.0.13"
|
|
46
23
|
},
|
|
47
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "2a0b2c984726753e8f4f3c17c63316b04051a942"
|
|
48
25
|
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const path_1 = require("path");
|
|
27
|
-
const fs = __importStar(require("fs-extra"));
|
|
28
|
-
const umi_1 = require("umi");
|
|
29
|
-
const hooks_internal_1 = require("@midwayjs/hooks-internal");
|
|
30
|
-
const utils_1 = require("../../utils");
|
|
31
|
-
exports.default = (cli) => {
|
|
32
|
-
cli.command('build', 'cli工具')
|
|
33
|
-
.option('--outDir [dir]', `[string] output directory (default: dist)`, {
|
|
34
|
-
default: 'dist',
|
|
35
|
-
})
|
|
36
|
-
.option('--clean', `[boolean] clean output directory before build (default: true)`, {
|
|
37
|
-
default: true,
|
|
38
|
-
})
|
|
39
|
-
.action(async (options) => {
|
|
40
|
-
const { outDir, clean } = options;
|
|
41
|
-
const root = (0, hooks_internal_1.getProjectRoot)();
|
|
42
|
-
if (clean && fs.existsSync(outDir)) {
|
|
43
|
-
console.info('正在清理之前的 build 产物...');
|
|
44
|
-
await fs.promises.rm(outDir, { recursive: true });
|
|
45
|
-
}
|
|
46
|
-
await (0, utils_1.hack)();
|
|
47
|
-
// 合并用户配置
|
|
48
|
-
const productionConfig = (0, utils_1.getProductionConfig)(root);
|
|
49
|
-
console.info('正在打包前端代码...');
|
|
50
|
-
const feBuild = await (0, utils_1.executePromise)((0, umi_1.run)({
|
|
51
|
-
presets: [require.resolve('../../plugins/preset')],
|
|
52
|
-
}).catch((e) => {
|
|
53
|
-
console.error(e);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}));
|
|
56
|
-
console.info('打包前端代码成功~ 耗时:' + feBuild.time / 1000 + 's');
|
|
57
|
-
// 创建服务端渲染前端页面的 render 函数
|
|
58
|
-
(0, utils_1.createRender)((0, path_1.join)(root, outDir));
|
|
59
|
-
// 写 midway.config.js 到 dist 目录
|
|
60
|
-
(0, utils_1.writeConfig)(outDir, productionConfig);
|
|
61
|
-
console.info('正在打包后端代码...', root, outDir);
|
|
62
|
-
try {
|
|
63
|
-
const rdBuild = await (0, utils_1.executePromise)((0, utils_1.buildServer)(root, outDir));
|
|
64
|
-
console.info(`打包后端代码成功~ 耗时:` + rdBuild.time / 1000 + 's');
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
console.error('打包后端代码失败', err);
|
|
68
|
-
process.exit(1);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const umi_1 = require("umi");
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
exports.default = (cli) => {
|
|
6
|
-
cli.command('dev', 'cli工具')
|
|
7
|
-
.option('--port [port]', `port (default: 7001)`, {
|
|
8
|
-
default: '7001',
|
|
9
|
-
})
|
|
10
|
-
.action(async (options) => {
|
|
11
|
-
const { port } = options;
|
|
12
|
-
// 设置 midway 接口服务端口为指定端口
|
|
13
|
-
process.env.MIDWAY_HTTP_PORT = port;
|
|
14
|
-
// 增加 nodeJs 运行时内存的大小
|
|
15
|
-
process.env.NODE_OPTIONS = '--max-old-space-size=10240';
|
|
16
|
-
await (0, utils_1.hack)();
|
|
17
|
-
(0, umi_1.run)({
|
|
18
|
-
presets: [require.resolve('../../plugins/preset')],
|
|
19
|
-
}).catch((e) => {
|
|
20
|
-
console.error(e);
|
|
21
|
-
process.exit(1);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const script_1 = __importDefault(require("./script"));
|
|
7
|
-
exports.default = (cli) => {
|
|
8
|
-
cli.command('m', 'cli工具')
|
|
9
|
-
.option('--count', '[number] 合并几个commit,不填会自动计算与最新commit相同名称的数量')
|
|
10
|
-
.option('--commit', '[boolean] 是否在合并前提交代码')
|
|
11
|
-
.option('--push', '[boolean] 是否在合并后推送代码')
|
|
12
|
-
.action(script_1.default);
|
|
13
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const { exec } = require('child_process');
|
|
4
|
-
// 获取最新的msg
|
|
5
|
-
async function getLatestCommitMsg() {
|
|
6
|
-
return execGitCommand(`git log -1 --pretty=%B`);
|
|
7
|
-
}
|
|
8
|
-
function getContinuousCommitCount() {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
exec(`git log --oneline --format=%s`, (err, stdout) => {
|
|
11
|
-
if (err) {
|
|
12
|
-
reject(err);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const messages = stdout.split('\n');
|
|
16
|
-
const msg = messages[0];
|
|
17
|
-
let count = 0;
|
|
18
|
-
for (const item of messages) {
|
|
19
|
-
if (item !== msg) {
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
count++;
|
|
23
|
-
}
|
|
24
|
-
resolve(count);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function execGitCommand(command) {
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
exec(command, (err, stdout) => {
|
|
31
|
-
if (err) {
|
|
32
|
-
reject(err);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
resolve(stdout);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
exports.default = async (options) => {
|
|
40
|
-
const hasChange = await execGitCommand('git status -s');
|
|
41
|
-
if (hasChange) {
|
|
42
|
-
if (options?.commit) {
|
|
43
|
-
console.log('commit success', await execGitCommand(`git commit -a -m "${(await getLatestCommitMsg()).trim()}"`));
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
console.log('stash success', await execGitCommand('git stash'));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const count = options?.count || await getContinuousCommitCount();
|
|
50
|
-
const command = `GIT_EDITOR=true GIT_SEQUENCE_EDITOR="sed -i -e '2,\\$s/^pick/squash/'" git rebase -i HEAD~${count}`;
|
|
51
|
-
console.log('rebase success', await execGitCommand(command));
|
|
52
|
-
if (options?.push) {
|
|
53
|
-
console.log('push success', await execGitCommand('git push origin HEAD --force'));
|
|
54
|
-
}
|
|
55
|
-
if (hasChange && !options?.commit) {
|
|
56
|
-
await execGitCommand('git stash pop');
|
|
57
|
-
}
|
|
58
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const path_1 = require("path");
|
|
27
|
-
const fs = __importStar(require("fs-extra"));
|
|
28
|
-
const bootstrap_1 = require("@midwayjs/bootstrap");
|
|
29
|
-
const hooks_internal_1 = require("@midwayjs/hooks-internal");
|
|
30
|
-
exports.default = (cli) => {
|
|
31
|
-
cli.command('start', 'start')
|
|
32
|
-
.option('-p, --port <port>', '[number] specify port', { default: 3000 })
|
|
33
|
-
.action(async (options) => {
|
|
34
|
-
const root = (0, path_1.resolve)('dist');
|
|
35
|
-
// 判断目录是否存在
|
|
36
|
-
if (!fs.existsSync(root)) {
|
|
37
|
-
console.error('dist 目录不存在,请先执行 build 命令');
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const config = {
|
|
41
|
-
...Object.assign({ static: true }, (0, hooks_internal_1.getConfig)(root)),
|
|
42
|
-
build: {
|
|
43
|
-
outDir: './',
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
(0, hooks_internal_1.setProjectRoot)(root);
|
|
47
|
-
(0, hooks_internal_1.setConfig)(config);
|
|
48
|
-
process.env.MIDWAY_HTTP_PORT = options.port.toString();
|
|
49
|
-
const server = bootstrap_1.Bootstrap.configure({
|
|
50
|
-
baseDir: root,
|
|
51
|
-
ignore: ['**/_client/**'],
|
|
52
|
-
});
|
|
53
|
-
await server.run();
|
|
54
|
-
console.log(`Your application is running at http://localhost:${options.port}`);
|
|
55
|
-
});
|
|
56
|
-
};
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/plugins/maxAlias.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = (api) => {
|
|
4
|
-
api.modifyAppData((memo) => {
|
|
5
|
-
memo.umi.name = 'Umi Max';
|
|
6
|
-
memo.umi.importSource = '@umijs/max';
|
|
7
|
-
memo.umi.cliName = 'max';
|
|
8
|
-
return memo;
|
|
9
|
-
});
|
|
10
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = (api) => {
|
|
4
|
-
api.onCheckPkgJSON(({ current }) => {
|
|
5
|
-
const hasUmi = current.dependencies?.['umi'] || current.devDependencies?.['umi'];
|
|
6
|
-
if (hasUmi) {
|
|
7
|
-
throw new Error(`You are using ${api.appData.umi.importSource}, please remove umi from your dependencies in package.json.`);
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
};
|
package/dist/plugins/preset.d.ts
DELETED
package/dist/plugins/preset.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = () => {
|
|
4
|
-
return {
|
|
5
|
-
plugins: [
|
|
6
|
-
require.resolve('@umijs/plugins/dist/access'),
|
|
7
|
-
require.resolve('@umijs/plugins/dist/analytics'),
|
|
8
|
-
require.resolve('@umijs/plugins/dist/antd'),
|
|
9
|
-
require.resolve('@umijs/plugins/dist/dva'),
|
|
10
|
-
require.resolve('@umijs/plugins/dist/initial-state'),
|
|
11
|
-
require.resolve('@umijs/plugins/dist/layout'),
|
|
12
|
-
require.resolve('@umijs/plugins/dist/locale'),
|
|
13
|
-
require.resolve('@umijs/plugins/dist/mf'),
|
|
14
|
-
require.resolve('@umijs/plugins/dist/model'),
|
|
15
|
-
require.resolve('@umijs/plugins/dist/moment2dayjs'),
|
|
16
|
-
require.resolve('@umijs/plugins/dist/qiankun'),
|
|
17
|
-
require.resolve('@umijs/plugins/dist/tailwindcss'),
|
|
18
|
-
require.resolve('@umijs/plugins/dist/valtio'),
|
|
19
|
-
require.resolve('./maxAlias'),
|
|
20
|
-
require.resolve('./maxAppData'),
|
|
21
|
-
require.resolve('./maxChecker'),
|
|
22
|
-
],
|
|
23
|
-
};
|
|
24
|
-
};
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const createRender: (dist: string) => void;
|
|
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
|
-
};
|
|
7
|
-
export declare const executePromise: (promise: Promise<any>) => Promise<{
|
|
8
|
-
result: any;
|
|
9
|
-
time: number;
|
|
10
|
-
}>;
|
|
11
|
-
export declare const hack: () => Promise<void>;
|
package/dist/utils/index.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.hack = exports.executePromise = exports.getProductionConfig = exports.writeConfig = exports.buildServer = exports.createRender = void 0;
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
|
-
const fs = __importStar(require("fs-extra"));
|
|
32
|
-
const command_core_1 = require("@midwayjs/command-core");
|
|
33
|
-
const cli_plugin_build_1 = require("@midwayjs/cli-plugin-build");
|
|
34
|
-
const hooks_internal_1 = require("@midwayjs/hooks-internal");
|
|
35
|
-
const createRender = (dist) => {
|
|
36
|
-
const code = `exports.default = require('@midwayjs/serve').Serve('/*', { dir: '_client', isKit: true });`;
|
|
37
|
-
const file = path_1.default.join(dist, '_serve/index.js');
|
|
38
|
-
fs.ensureFileSync(file);
|
|
39
|
-
fs.writeFileSync(file, code, 'utf-8');
|
|
40
|
-
};
|
|
41
|
-
exports.createRender = createRender;
|
|
42
|
-
const buildServer = async (cwd, outDir) => {
|
|
43
|
-
const core = new command_core_1.CommandCore({
|
|
44
|
-
commands: ['build'],
|
|
45
|
-
cwd,
|
|
46
|
-
log: {
|
|
47
|
-
log: () => {
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
options: {
|
|
51
|
-
outDir,
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
core.addPlugin(cli_plugin_build_1.BuildPlugin);
|
|
55
|
-
await core.ready();
|
|
56
|
-
await core.invoke();
|
|
57
|
-
};
|
|
58
|
-
exports.buildServer = buildServer;
|
|
59
|
-
const writeConfig = (outDir, productionConfig) => {
|
|
60
|
-
fs.writeFileSync(path_1.default.join(outDir, 'midway.config.js'), `module.exports = ${JSON.stringify(productionConfig, null, 2)}`, 'utf-8');
|
|
61
|
-
return () => {
|
|
62
|
-
fs.removeSync(path_1.default.join(outDir, 'midway.config.js'));
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
exports.writeConfig = writeConfig;
|
|
66
|
-
const getProductionConfig = (root) => {
|
|
67
|
-
const userConfig = Object.assign({ static: true }, (0, hooks_internal_1.getConfig)(root));
|
|
68
|
-
if (Array.isArray(userConfig.routes)) {
|
|
69
|
-
userConfig.routes.push({
|
|
70
|
-
baseDir: '_serve',
|
|
71
|
-
basePath: '/',
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
routes: userConfig.routes,
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
exports.getProductionConfig = getProductionConfig;
|
|
79
|
-
const executePromise = async (promise) => {
|
|
80
|
-
const start = Date.now();
|
|
81
|
-
const result = await promise;
|
|
82
|
-
const time = Date.now() - start;
|
|
83
|
-
return {
|
|
84
|
-
result,
|
|
85
|
-
time,
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
exports.executePromise = executePromise;
|
|
89
|
-
const replaceContentInFile = (filePath, targetContent, replacement) => {
|
|
90
|
-
return new Promise((resolve, reject) => {
|
|
91
|
-
fs.readFile(filePath, 'utf8', (err, data) => {
|
|
92
|
-
if (err) {
|
|
93
|
-
console.error(`读取文件时发生错误:${err}`);
|
|
94
|
-
reject(err);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (replacement && data.includes(replacement)) {
|
|
98
|
-
console.error(`已替换过:${filePath}`);
|
|
99
|
-
resolve();
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (!data.includes(targetContent)) {
|
|
103
|
-
console.error(`不包含目标内容:${targetContent}`);
|
|
104
|
-
reject(`不包含目标内容:${targetContent}`);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const updatedData = data.replaceAll(targetContent, replacement);
|
|
108
|
-
fs.writeFile(filePath, updatedData, 'utf8', (err) => {
|
|
109
|
-
if (err) {
|
|
110
|
-
console.error(`写入文件时发生错误:${err}`);
|
|
111
|
-
reject(err);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
console.log(`成功替换文件中的内容!`);
|
|
115
|
-
resolve();
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
|
-
const hack = async () => {
|
|
122
|
-
const pwd = path_1.default.resolve(__dirname, '../../');
|
|
123
|
-
await replaceContentInFile(`${pwd}/node_modules/@umijs/preset-umi/dist/libs/scan.js`, 'exportsFields: []', `exportsFields: ['exports'],
|
|
124
|
-
conditionNames: ["import", "require"]`);
|
|
125
|
-
await replaceContentInFile(`${pwd}/node_modules/enhanced-resolve/lib/ExportsFieldPlugin.js`, 'paths = fieldProcessor(remainingRequest, this.conditionNames);', `paths = fieldProcessor(remainingRequest, this.conditionNames)
|
|
126
|
-
if (paths.length === 0 && remainingRequest === '.' && request.descriptionFileData.name === 'typeorm') {
|
|
127
|
-
paths = ['./index.mjs']
|
|
128
|
-
}
|
|
129
|
-
`);
|
|
130
|
-
};
|
|
131
|
-
exports.hack = hack;
|