@wzyjs/cli 0.0.3
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 +3 -0
- package/dist/commands/build/index.d.ts +3 -0
- package/dist/commands/build/index.js +55 -0
- package/dist/commands/build/utils.d.ts +6 -0
- package/dist/commands/build/utils.js +42 -0
- package/dist/commands/create/index.d.ts +3 -0
- package/dist/commands/create/index.js +13 -0
- package/dist/commands/dev/index.d.ts +3 -0
- package/dist/commands/dev/index.js +21 -0
- package/dist/commands/start/index.d.ts +3 -0
- package/dist/commands/start/index.js +35 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +16 -0
- package/dist/plugins/maxAlias.d.ts +3 -0
- package/dist/plugins/maxAlias.js +11 -0
- package/dist/plugins/maxAppData.d.ts +3 -0
- package/dist/plugins/maxAppData.js +10 -0
- package/dist/plugins/maxChecker.d.ts +3 -0
- package/dist/plugins/maxChecker.js +10 -0
- package/dist/plugins/preset.d.ts +4 -0
- package/dist/plugins/preset.js +24 -0
- package/package.json +42 -0
package/bin/mi.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
6
|
+
const umi_1 = require("umi");
|
|
7
|
+
const internal_1 = require("@midwayjs/hooks/internal");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const consola = require('consola');
|
|
10
|
+
exports.default = (cli) => {
|
|
11
|
+
cli.command('build', 'cli工具')
|
|
12
|
+
.option('--outDir [dir]', `[string] output directory (default: dist)`, {
|
|
13
|
+
default: 'dist',
|
|
14
|
+
})
|
|
15
|
+
.option('--clean', `[boolean] clean output directory before build (default: true)`, {
|
|
16
|
+
default: true,
|
|
17
|
+
})
|
|
18
|
+
.action(async (options) => {
|
|
19
|
+
const { outDir, clean } = options;
|
|
20
|
+
const root = (0, internal_1.getProjectRoot)();
|
|
21
|
+
if (clean && fs.existsSync(outDir)) {
|
|
22
|
+
consola.info('正在清理之前的 build 产物...');
|
|
23
|
+
await fs.promises.rm(outDir, { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
// 给 @midwayjs/hooks-bundler里的 vite() 插件,设置 midway.config.ts 的配置
|
|
26
|
+
// 加这一行,该插件就不会去使用根目录下的 midway.config.ts 文件了
|
|
27
|
+
// 就可把 midway.config.ts 文件删了,也没啥用
|
|
28
|
+
(0, internal_1.setConfig)({});
|
|
29
|
+
consola.info('正在打包前端代码...');
|
|
30
|
+
await (0, umi_1.run)({
|
|
31
|
+
presets: [require.resolve('../../plugins/preset')],
|
|
32
|
+
}).catch((e) => {
|
|
33
|
+
console.error(e);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
});
|
|
36
|
+
consola.success('打包前端代码成功');
|
|
37
|
+
(0, utils_1.createRender)((0, path_1.join)(root, outDir));
|
|
38
|
+
const userConfig = Object.assign({ static: true }, (0, internal_1.getConfig)(root));
|
|
39
|
+
if (Array.isArray(userConfig.routes)) {
|
|
40
|
+
userConfig.routes.push({
|
|
41
|
+
baseDir: '_serve',
|
|
42
|
+
basePath: '/',
|
|
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
|
+
consola.info('正在打包后端代码...', root);
|
|
50
|
+
fs.writeFileSync((0, path_1.join)(root, 'midway.config.js'), `module.exports = ${JSON.stringify(productionConfig, null, 2)}`, 'utf-8');
|
|
51
|
+
await (0, utils_1.executePromise)((0, utils_1.buildServer)(root, outDir));
|
|
52
|
+
fs.removeSync((0, path_1.join)(root, 'midway.config.js'));
|
|
53
|
+
consola.success(`打包后端代码成功.`);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildServer = exports.executePromise = exports.createRender = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
7
|
+
const command_core_1 = require("@midwayjs/command-core");
|
|
8
|
+
const cli_plugin_build_1 = require("@midwayjs/cli-plugin-build");
|
|
9
|
+
const createRender = (dist) => {
|
|
10
|
+
const code = `exports.default = require('@midwayjs/serve').Serve('/*', { dir: '_client', isKit: true });`;
|
|
11
|
+
const file = (0, path_1.join)(dist, '_serve/index.js');
|
|
12
|
+
fs.ensureFileSync(file);
|
|
13
|
+
fs.writeFileSync(file, code, 'utf-8');
|
|
14
|
+
};
|
|
15
|
+
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
|
+
const buildServer = async (cwd, outDir) => {
|
|
27
|
+
const core = new command_core_1.CommandCore({
|
|
28
|
+
commands: ['build'],
|
|
29
|
+
cwd,
|
|
30
|
+
log: {
|
|
31
|
+
log: () => {
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
options: {
|
|
35
|
+
outDir,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
core.addPlugin(cli_plugin_build_1.BuildPlugin);
|
|
39
|
+
await core.ready();
|
|
40
|
+
await core.invoke();
|
|
41
|
+
};
|
|
42
|
+
exports.buildServer = buildServer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
exports.default = (cli) => {
|
|
7
|
+
cli.command('create <name> [outDir]', 'cli工具')
|
|
8
|
+
.action((name, outDir) => {
|
|
9
|
+
const sourceDir = (0, path_1.resolve)('libs/cli/examples/empty');
|
|
10
|
+
const targetDir = (0, path_1.resolve)(outDir || '.', name);
|
|
11
|
+
fs.copySync(sourceDir, targetDir);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const umi_1 = require("umi");
|
|
4
|
+
const internal_1 = require("@midwayjs/hooks/internal");
|
|
5
|
+
exports.default = (cli) => {
|
|
6
|
+
cli.command('dev', 'cli工具')
|
|
7
|
+
.action(() => {
|
|
8
|
+
// 设置 midway 接口服务端口为 7001
|
|
9
|
+
process.env.MIDWAY_HTTP_PORT = '7001';
|
|
10
|
+
// 给 @midwayjs/hooks-bundler里的 vite() 插件,设置 midway.config.ts 的配置
|
|
11
|
+
// 加这一行,该插件就不会去使用根目录下的 midway.config.ts 文件了
|
|
12
|
+
// 就可把 midway.config.ts 文件删了,也没啥用
|
|
13
|
+
(0, internal_1.setConfig)({});
|
|
14
|
+
(0, umi_1.run)({
|
|
15
|
+
presets: [require.resolve('../../plugins/preset')],
|
|
16
|
+
}).catch((e) => {
|
|
17
|
+
console.error(e);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
6
|
+
const bootstrap_1 = require("@midwayjs/bootstrap");
|
|
7
|
+
const internal_1 = require("@midwayjs/hooks/internal");
|
|
8
|
+
const consola = require('consola');
|
|
9
|
+
exports.default = (cli) => {
|
|
10
|
+
cli.command('start', 'start')
|
|
11
|
+
.option('-p, --port <port>', '[number] specify port', { default: 3000 })
|
|
12
|
+
.action(async (options) => {
|
|
13
|
+
const root = (0, path_1.resolve)('dist');
|
|
14
|
+
// 判断目录是否存在
|
|
15
|
+
if (!fs.existsSync(root)) {
|
|
16
|
+
consola.error('dist 目录不存在,请先执行 build 命令');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const config = {
|
|
20
|
+
...Object.assign({ static: true }, (0, internal_1.getConfig)(root)),
|
|
21
|
+
build: {
|
|
22
|
+
outDir: './',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
(0, internal_1.setProjectRoot)(root);
|
|
26
|
+
(0, internal_1.setConfig)(config);
|
|
27
|
+
process.env.MIDWAY_HTTP_PORT = options.port.toString();
|
|
28
|
+
const server = bootstrap_1.Bootstrap.configure({
|
|
29
|
+
baseDir: root,
|
|
30
|
+
ignore: ['**/_client/**'],
|
|
31
|
+
});
|
|
32
|
+
await server.run();
|
|
33
|
+
consola.success(`Your application is running at http://localhost:${options.port}`);
|
|
34
|
+
});
|
|
35
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const cac_1 = tslib_1.__importDefault(require("cac"));
|
|
5
|
+
const dev_1 = tslib_1.__importDefault(require("./commands/dev"));
|
|
6
|
+
const build_1 = tslib_1.__importDefault(require("./commands/build"));
|
|
7
|
+
const start_1 = tslib_1.__importDefault(require("./commands/start"));
|
|
8
|
+
const create_1 = tslib_1.__importDefault(require("./commands/create"));
|
|
9
|
+
const cli = (0, cac_1.default)();
|
|
10
|
+
(0, dev_1.default)(cli);
|
|
11
|
+
(0, build_1.default)(cli);
|
|
12
|
+
(0, start_1.default)(cli);
|
|
13
|
+
(0, create_1.default)(cli);
|
|
14
|
+
cli.help();
|
|
15
|
+
cli.version('0.0.1');
|
|
16
|
+
cli.parse();
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wzyjs/cli",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "description",
|
|
5
|
+
"author": "wzy",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "tsc -w",
|
|
10
|
+
"build": "tsc"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"bin": {
|
|
16
|
+
"mi": "./bin/mi.js"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@midwayjs/bootstrap": "^3.7.1",
|
|
20
|
+
"@midwayjs/cli-plugin-build": "^1.3.14",
|
|
21
|
+
"@midwayjs/command-core": "^1.3.14",
|
|
22
|
+
"@midwayjs/hooks": "^3.0.1",
|
|
23
|
+
"@umijs/plugins": "^4.0.28",
|
|
24
|
+
"cac": "^6.7.14",
|
|
25
|
+
"consola": "^2.15.3",
|
|
26
|
+
"fs-extra": "^10.1.0",
|
|
27
|
+
"rc-field-form": "^1.27.3",
|
|
28
|
+
"umi": "^4.0.30",
|
|
29
|
+
"vite": "^2.7.9"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/detect-port": "^1.3.2",
|
|
33
|
+
"@types/fs-extra": "^9.0.13",
|
|
34
|
+
"@types/koa": "^2.13.4",
|
|
35
|
+
"@types/node": "^18.11.9",
|
|
36
|
+
"@types/react-router-dom": "^4.3.1"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "9561be09765107cdae54703e67fa53fd08a77329"
|
|
42
|
+
}
|