@gct-paas/cli 0.0.1-dev.2 → 0.0.1-dev.20
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/LICENSE +21 -0
- package/dist/actions/gen-api/api-manage.cjs +46 -0
- package/dist/actions/gen-api/api-manage.d.ts +36 -0
- package/dist/actions/gen-api/gen-api.cjs +157 -0
- package/dist/actions/gen-api/gen-api.d.ts +58 -0
- package/dist/actions/gen-api/model-manage.cjs +127 -0
- package/dist/actions/gen-api/model-manage.d.ts +124 -0
- package/dist/actions/index.cjs +12 -0
- package/dist/actions/index.d.ts +1 -0
- package/dist/bin.cjs +5 -0
- package/dist/commands/gen-api/gen-api.cjs +16 -0
- package/dist/commands/gen-api/gen-api.d.ts +44 -0
- package/dist/commands/index.cjs +23 -0
- package/dist/core/handlebars/constant/index.cjs +8 -0
- package/dist/core/handlebars/constant/index.d.ts +2 -0
- package/dist/core/handlebars/handlebars-engine.cjs +134 -0
- package/dist/core/handlebars/handlebars-engine.d.ts +74 -0
- package/dist/core/handlebars/helpers/and/and.cjs +21 -0
- package/dist/core/handlebars/helpers/and/and.d.ts +13 -0
- package/dist/core/handlebars/helpers/camel-case/camel-case.cjs +20 -0
- package/dist/core/handlebars/helpers/camel-case/camel-case.d.ts +13 -0
- package/dist/core/handlebars/helpers/concat/concat.cjs +17 -0
- package/dist/core/handlebars/helpers/concat/concat.d.ts +13 -0
- package/dist/core/handlebars/helpers/eq/eq.cjs +19 -0
- package/dist/core/handlebars/helpers/eq/eq.d.ts +14 -0
- package/dist/core/handlebars/helpers/format-import/format-import.cjs +41 -0
- package/dist/core/handlebars/helpers/format-import/format-import.d.ts +13 -0
- package/dist/core/handlebars/helpers/format-import-item/format-import-item.cjs +40 -0
- package/dist/core/handlebars/helpers/format-import-item/format-import-item.d.ts +13 -0
- package/dist/core/handlebars/helpers/format-js-type/format-js-type.cjs +41 -0
- package/dist/core/handlebars/helpers/format-js-type/format-js-type.d.ts +14 -0
- package/dist/core/handlebars/helpers/gt/gt.cjs +19 -0
- package/dist/core/handlebars/helpers/gt/gt.d.ts +14 -0
- package/dist/core/handlebars/helpers/gte/gte.cjs +19 -0
- package/dist/core/handlebars/helpers/gte/gte.d.ts +14 -0
- package/dist/core/handlebars/helpers/helper-base.cjs +19 -0
- package/dist/core/handlebars/helpers/helper-base.d.ts +22 -0
- package/dist/core/handlebars/helpers/includes/includes.cjs +18 -0
- package/dist/core/handlebars/helpers/includes/includes.d.ts +13 -0
- package/dist/core/handlebars/helpers/index.cjs +52 -0
- package/dist/core/handlebars/helpers/index.d.ts +6 -0
- package/dist/core/handlebars/helpers/json/json.cjs +16 -0
- package/dist/core/handlebars/helpers/json/json.d.ts +13 -0
- package/dist/core/handlebars/helpers/lower-case/lower-case.cjs +19 -0
- package/dist/core/handlebars/helpers/lower-case/lower-case.d.ts +13 -0
- package/dist/core/handlebars/helpers/lt/lt.cjs +19 -0
- package/dist/core/handlebars/helpers/lt/lt.d.ts +14 -0
- package/dist/core/handlebars/helpers/lte/lte.cjs +19 -0
- package/dist/core/handlebars/helpers/lte/lte.d.ts +14 -0
- package/dist/core/handlebars/helpers/neq/neq.cjs +19 -0
- package/dist/core/handlebars/helpers/neq/neq.d.ts +14 -0
- package/dist/core/handlebars/helpers/not/not.cjs +21 -0
- package/dist/core/handlebars/helpers/not/not.d.ts +14 -0
- package/dist/core/handlebars/helpers/not-includes/not-includes.cjs +18 -0
- package/dist/core/handlebars/helpers/not-includes/not-includes.d.ts +13 -0
- package/dist/core/handlebars/helpers/or/or.cjs +23 -0
- package/dist/core/handlebars/helpers/or/or.d.ts +13 -0
- package/dist/core/handlebars/helpers/pascal-case/pascal-case.cjs +20 -0
- package/dist/core/handlebars/helpers/pascal-case/pascal-case.d.ts +13 -0
- package/dist/core/handlebars/helpers/snake-case/snake-case.cjs +20 -0
- package/dist/core/handlebars/helpers/snake-case/snake-case.d.ts +13 -0
- package/dist/core/handlebars/helpers/spinal-case/spinal-case.cjs +20 -0
- package/dist/core/handlebars/helpers/spinal-case/spinal-case.d.ts +13 -0
- package/dist/core/handlebars/helpers/upper-case/upper-case.cjs +19 -0
- package/dist/core/handlebars/helpers/upper-case/upper-case.d.ts +13 -0
- package/dist/core/handlebars/index.cjs +27 -0
- package/dist/core/handlebars/index.d.ts +2 -0
- package/dist/core/handlebars/utils/helper/helper.cjs +41 -0
- package/dist/core/handlebars/utils/helper/helper.d.ts +33 -0
- package/dist/core/handlebars/utils/index.cjs +20 -0
- package/dist/core/handlebars/utils/index.d.ts +17 -0
- package/dist/core/index.cjs +27 -0
- package/dist/core/index.d.ts +2 -7
- package/dist/core/interface/index.cjs +1 -0
- package/dist/core/interface/index.d.ts +1 -0
- package/dist/index.cjs +47 -0
- package/dist/interface/i-command/i-command.cjs +1 -0
- package/dist/interface/i-command/i-command.d.ts +0 -6
- package/dist/interface/index.cjs +16 -0
- package/dist/utils/index.cjs +18 -0
- package/dist/utils/local-binaries/local-binaries.cjs +19 -0
- package/es/actions/gen-api/api-manage.d.ts +36 -0
- package/es/actions/gen-api/api-manage.mjs +38 -0
- package/es/actions/gen-api/gen-api.d.ts +58 -0
- package/es/actions/gen-api/gen-api.mjs +164 -0
- package/es/actions/gen-api/model-manage.d.ts +124 -0
- package/es/actions/gen-api/model-manage.mjs +126 -0
- package/es/actions/index.d.ts +1 -0
- package/es/actions/index.mjs +1 -0
- package/es/bin.d.ts +2 -0
- package/es/commands/gen-api/gen-api.d.ts +44 -0
- package/es/commands/gen-api/gen-api.mjs +15 -0
- package/es/commands/index.d.ts +5 -0
- package/{dist → es}/commands/index.mjs +2 -0
- package/es/core/handlebars/constant/index.d.ts +2 -0
- package/es/core/handlebars/constant/index.mjs +2 -0
- package/es/core/handlebars/handlebars-engine.d.ts +74 -0
- package/es/core/handlebars/handlebars-engine.mjs +122 -0
- package/es/core/handlebars/helpers/and/and.d.ts +13 -0
- package/es/core/handlebars/helpers/and/and.mjs +14 -0
- package/es/core/handlebars/helpers/camel-case/camel-case.d.ts +13 -0
- package/es/core/handlebars/helpers/camel-case/camel-case.mjs +13 -0
- package/es/core/handlebars/helpers/concat/concat.d.ts +13 -0
- package/es/core/handlebars/helpers/concat/concat.mjs +10 -0
- package/es/core/handlebars/helpers/eq/eq.d.ts +14 -0
- package/es/core/handlebars/helpers/eq/eq.mjs +12 -0
- package/es/core/handlebars/helpers/format-import/format-import.d.ts +13 -0
- package/es/core/handlebars/helpers/format-import/format-import.mjs +34 -0
- package/es/core/handlebars/helpers/format-import-item/format-import-item.d.ts +13 -0
- package/es/core/handlebars/helpers/format-import-item/format-import-item.mjs +33 -0
- package/es/core/handlebars/helpers/format-js-type/format-js-type.d.ts +14 -0
- package/es/core/handlebars/helpers/format-js-type/format-js-type.mjs +34 -0
- package/es/core/handlebars/helpers/gt/gt.d.ts +14 -0
- package/es/core/handlebars/helpers/gt/gt.mjs +12 -0
- package/es/core/handlebars/helpers/gte/gte.d.ts +14 -0
- package/es/core/handlebars/helpers/gte/gte.mjs +12 -0
- package/es/core/handlebars/helpers/helper-base.d.ts +22 -0
- package/es/core/handlebars/helpers/helper-base.mjs +11 -0
- package/es/core/handlebars/helpers/includes/includes.d.ts +13 -0
- package/es/core/handlebars/helpers/includes/includes.mjs +11 -0
- package/es/core/handlebars/helpers/index.d.ts +6 -0
- package/es/core/handlebars/helpers/index.mjs +46 -0
- package/es/core/handlebars/helpers/json/json.d.ts +13 -0
- package/es/core/handlebars/helpers/json/json.mjs +13 -0
- package/es/core/handlebars/helpers/lower-case/lower-case.d.ts +13 -0
- package/es/core/handlebars/helpers/lower-case/lower-case.mjs +12 -0
- package/es/core/handlebars/helpers/lt/lt.d.ts +14 -0
- package/es/core/handlebars/helpers/lt/lt.mjs +12 -0
- package/es/core/handlebars/helpers/lte/lte.d.ts +14 -0
- package/es/core/handlebars/helpers/lte/lte.mjs +12 -0
- package/es/core/handlebars/helpers/neq/neq.d.ts +14 -0
- package/es/core/handlebars/helpers/neq/neq.mjs +12 -0
- package/es/core/handlebars/helpers/not/not.d.ts +14 -0
- package/es/core/handlebars/helpers/not/not.mjs +12 -0
- package/es/core/handlebars/helpers/not-includes/not-includes.d.ts +13 -0
- package/es/core/handlebars/helpers/not-includes/not-includes.mjs +11 -0
- package/es/core/handlebars/helpers/or/or.d.ts +13 -0
- package/es/core/handlebars/helpers/or/or.mjs +16 -0
- package/es/core/handlebars/helpers/pascal-case/pascal-case.d.ts +13 -0
- package/es/core/handlebars/helpers/pascal-case/pascal-case.mjs +13 -0
- package/es/core/handlebars/helpers/snake-case/snake-case.d.ts +13 -0
- package/es/core/handlebars/helpers/snake-case/snake-case.mjs +13 -0
- package/es/core/handlebars/helpers/spinal-case/spinal-case.d.ts +13 -0
- package/es/core/handlebars/helpers/spinal-case/spinal-case.mjs +13 -0
- package/es/core/handlebars/helpers/upper-case/upper-case.d.ts +13 -0
- package/es/core/handlebars/helpers/upper-case/upper-case.mjs +12 -0
- package/es/core/handlebars/index.d.ts +2 -0
- package/es/core/handlebars/index.mjs +2 -0
- package/es/core/handlebars/utils/helper/helper.d.ts +33 -0
- package/es/core/handlebars/utils/helper/helper.mjs +54 -0
- package/es/core/handlebars/utils/index.d.ts +17 -0
- package/es/core/handlebars/utils/index.mjs +7 -0
- package/es/core/index.d.ts +2 -0
- package/es/core/index.mjs +2 -0
- package/es/core/interface/index.d.ts +1 -0
- package/es/index.d.ts +2 -0
- package/es/interface/i-command/i-command.d.ts +22 -0
- package/es/interface/i-command/i-command.mjs +0 -0
- package/es/interface/index.d.ts +1 -0
- package/es/types/index.d.ts +1 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/local-binaries/local-binaries.d.ts +3 -0
- package/package.json +28 -46
- package/dist/core/commitlint/commitlint-config/commitlint-config.d.ts +0 -9
- package/dist/core/commitlint/commitlint-config/commitlint-config.mjs +0 -28
- package/dist/core/commitlint/index.d.ts +0 -1
- package/dist/core/commitlint/index.mjs +0 -1
- package/dist/core/constants/index.d.ts +0 -8
- package/dist/core/constants/index.mjs +0 -2
- package/dist/core/eslint/eslint-config/eslint-config.d.ts +0 -9
- package/dist/core/eslint/eslint-config/eslint-config.mjs +0 -109
- package/dist/core/eslint/index.d.ts +0 -1
- package/dist/core/eslint/index.mjs +0 -1
- package/dist/core/index.mjs +0 -7
- package/dist/core/prettier/index.d.ts +0 -1
- package/dist/core/prettier/index.mjs +0 -1
- package/dist/core/prettier/prettier-config/prettier-config.d.ts +0 -22
- package/dist/core/prettier/prettier-config/prettier-config.mjs +0 -26
- package/dist/core/rollup/index.d.ts +0 -2
- package/dist/core/rollup/index.mjs +0 -2
- package/dist/core/rollup/rollup-config/dev-config.d.ts +0 -9
- package/dist/core/rollup/rollup-config/dev-config.mjs +0 -98
- package/dist/core/rollup/rollup-plugins/copy-file.d.ts +0 -37
- package/dist/core/rollup/rollup-plugins/copy-file.mjs +0 -18
- package/dist/core/rollup/rollup-plugins/ignore-compiler-file.d.ts +0 -8
- package/dist/core/rollup/rollup-plugins/ignore-compiler-file.mjs +0 -17
- package/dist/core/rollup/rollup-plugins/index.d.ts +0 -2
- package/dist/core/rollup/rollup-plugins/index.mjs +0 -2
- package/dist/core/stylelint/index.d.ts +0 -1
- package/dist/core/stylelint/index.mjs +0 -1
- package/dist/core/stylelint/stylelint-config/stylelint-config.d.ts +0 -9
- package/dist/core/stylelint/stylelint-config/stylelint-config.mjs +0 -21
- package/dist/core/util/index.d.ts +0 -21
- package/dist/core/util/index.mjs +0 -7
- package/dist/core/util/watcher/watcher.d.ts +0 -61
- package/dist/core/util/watcher/watcher.mjs +0 -108
- package/dist/core/vite/index.d.ts +0 -1
- package/dist/core/vite/index.mjs +0 -1
- package/dist/core/vite/vite-config/vite-config.d.ts +0 -9
- package/dist/core/vite/vite-config/vite-config.mjs +0 -47
- /package/{dist → es}/bin.mjs +0 -0
- /package/{dist/interface/i-command/i-command.mjs → es/core/interface/index.mjs} +0 -0
- /package/{dist → es}/index.mjs +0 -0
- /package/{dist → es}/interface/index.mjs +0 -0
- /package/{dist → es}/utils/index.mjs +0 -0
- /package/{dist → es}/utils/local-binaries/local-binaries.mjs +0 -0
package/dist/core/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type IObject = Record<string | symbol, any>;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
bootstrap: true
|
|
8
|
+
};
|
|
9
|
+
exports.bootstrap = bootstrap;
|
|
10
|
+
var _commander = require("commander");
|
|
11
|
+
var _commands = require("./commands/index.cjs");
|
|
12
|
+
var _utils = require("./utils/index.cjs");
|
|
13
|
+
var _package = _interopRequireDefault(require("../package.json"));
|
|
14
|
+
var _core = require("./core/index.cjs");
|
|
15
|
+
Object.keys(_core).forEach(function (key) {
|
|
16
|
+
if (key === "default" || key === "__esModule") return;
|
|
17
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
18
|
+
if (key in exports && exports[key] === _core[key]) return;
|
|
19
|
+
Object.defineProperty(exports, key, {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _core[key];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
27
|
+
async function bootstrap() {
|
|
28
|
+
process.on("SIGINT", () => {
|
|
29
|
+
process.exit();
|
|
30
|
+
});
|
|
31
|
+
_commander.program.version(_package.default.version, "-v, --version", "\u67E5\u770B\u5F53\u524D\u7248\u672C").usage("<command> [options]").helpOption("-h, --help", "\u83B7\u53D6\u5E2E\u52A9\u4FE1\u606F").configureOutput({
|
|
32
|
+
// Visibly override write routines as example!
|
|
33
|
+
writeErr: str => process.stdout.write(`[ERR] ${str}`),
|
|
34
|
+
// Highlight errors in color.
|
|
35
|
+
outputError: (str, write) => write(`\x1B[31m${str}\x1B[0m`)
|
|
36
|
+
});
|
|
37
|
+
if ((0, _utils.localBinExists)()) {
|
|
38
|
+
const localCommandLoader = (0, _utils.loadLocalBinCommandLoader)();
|
|
39
|
+
localCommandLoader.load(_commander.program);
|
|
40
|
+
} else {
|
|
41
|
+
_commands.CommandLoader.load(_commander.program);
|
|
42
|
+
}
|
|
43
|
+
_commander.program.parse(process.argv);
|
|
44
|
+
if (!process.argv.slice(2).length) {
|
|
45
|
+
_commander.program.outputHelp();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -2,8 +2,6 @@ import { Command } from 'commander';
|
|
|
2
2
|
/**
|
|
3
3
|
* 命令项
|
|
4
4
|
*
|
|
5
|
-
* @author chitanda
|
|
6
|
-
* @date 2021-12-18 15:12:13
|
|
7
5
|
* @export
|
|
8
6
|
* @interface ICommand
|
|
9
7
|
*/
|
|
@@ -11,16 +9,12 @@ export interface ICommand {
|
|
|
11
9
|
/**
|
|
12
10
|
* 加载命令
|
|
13
11
|
*
|
|
14
|
-
* @author chitanda
|
|
15
|
-
* @date 2021-12-18 15:12:22
|
|
16
12
|
* @param {Command} program
|
|
17
13
|
*/
|
|
18
14
|
load(program: Command): void;
|
|
19
15
|
/**
|
|
20
16
|
* 执行行为
|
|
21
17
|
*
|
|
22
|
-
* @author chitanda
|
|
23
|
-
* @date 2021-12-21 16:12:22
|
|
24
18
|
* @param {...unknown[]} args
|
|
25
19
|
* @return {*} {(void | Promise<void>)}
|
|
26
20
|
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _iCommand = require("./i-command/i-command.cjs");
|
|
7
|
+
Object.keys(_iCommand).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _iCommand[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _iCommand[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "loadLocalBinCommandLoader", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _localBinaries.loadLocalBinCommandLoader;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "localBinExists", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _localBinaries.localBinExists;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _localBinaries = require("./local-binaries/local-binaries.cjs");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.loadLocalBinCommandLoader = loadLocalBinCommandLoader;
|
|
7
|
+
exports.localBinExists = localBinExists;
|
|
8
|
+
var _path = require("path");
|
|
9
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const localBinPathSegments = [process.cwd(), "node_modules", "@nestjs", "cli"];
|
|
12
|
+
function localBinExists() {
|
|
13
|
+
return _fsExtra.default.existsSync((0, _path.join)(...localBinPathSegments));
|
|
14
|
+
}
|
|
15
|
+
function loadLocalBinCommandLoader() {
|
|
16
|
+
const path = _path.posix.join(...localBinPathSegments, "commands");
|
|
17
|
+
const commandsFile = require(path);
|
|
18
|
+
return commandsFile.CommandLoader;
|
|
19
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IObject } from '../../core';
|
|
2
|
+
/**
|
|
3
|
+
* api 管理
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class EntityApiManage
|
|
7
|
+
*/
|
|
8
|
+
export declare class EntityApiManage {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly cache: Map<string, IObject>;
|
|
11
|
+
constructor(name: string);
|
|
12
|
+
/**
|
|
13
|
+
* 新增方法
|
|
14
|
+
*
|
|
15
|
+
* @param {string} method 方法名称
|
|
16
|
+
* @param {string} mode 请求方式
|
|
17
|
+
* @param {IObject} cfg 从 swagger 获取的配置
|
|
18
|
+
*/
|
|
19
|
+
add(method: string, mode: string, cfg: IObject): void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* api 清单管理
|
|
23
|
+
*
|
|
24
|
+
* @export
|
|
25
|
+
* @class ApiManage
|
|
26
|
+
*/
|
|
27
|
+
export declare class ApiManage {
|
|
28
|
+
readonly cache: Map<string, EntityApiManage>;
|
|
29
|
+
/**
|
|
30
|
+
* 新增 api
|
|
31
|
+
*
|
|
32
|
+
* @param {string} pathStr 请求路径
|
|
33
|
+
* @param {IObject} cfg swagger 配置
|
|
34
|
+
*/
|
|
35
|
+
add(pathStr: string, cfg: IObject): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class EntityApiManage {
|
|
2
|
+
constructor(name) {
|
|
3
|
+
this.name = name;
|
|
4
|
+
}
|
|
5
|
+
cache = /* @__PURE__ */ new Map();
|
|
6
|
+
/**
|
|
7
|
+
* 新增方法
|
|
8
|
+
*
|
|
9
|
+
* @param {string} method 方法名称
|
|
10
|
+
* @param {string} mode 请求方式
|
|
11
|
+
* @param {IObject} cfg 从 swagger 获取的配置
|
|
12
|
+
*/
|
|
13
|
+
add(method, mode, cfg) {
|
|
14
|
+
const tag = `${method}:${mode}`;
|
|
15
|
+
this.cache.set(tag, cfg);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class ApiManage {
|
|
19
|
+
cache = /* @__PURE__ */ new Map();
|
|
20
|
+
/**
|
|
21
|
+
* 新增 api
|
|
22
|
+
*
|
|
23
|
+
* @param {string} pathStr 请求路径
|
|
24
|
+
* @param {IObject} cfg swagger 配置
|
|
25
|
+
*/
|
|
26
|
+
add(pathStr, cfg) {
|
|
27
|
+
const entityName = pathStr.split("/")[3];
|
|
28
|
+
const method = pathStr.split("/")[4];
|
|
29
|
+
if (!this.cache.has(entityName)) {
|
|
30
|
+
this.cache.set(entityName, new EntityApiManage(entityName));
|
|
31
|
+
}
|
|
32
|
+
const entity = this.cache.get(entityName);
|
|
33
|
+
const modes = Object.keys(cfg);
|
|
34
|
+
modes.forEach((mode) => {
|
|
35
|
+
entity.add(method, mode, cfg[mode]);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { HandlebarsEngine, IObject } from '../../core';
|
|
2
|
+
/**
|
|
3
|
+
* 基于 handlebars 模板编写生成 api
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class GenApiAction
|
|
7
|
+
*/
|
|
8
|
+
export declare class GenApiAction {
|
|
9
|
+
private engine;
|
|
10
|
+
private modelManage;
|
|
11
|
+
private configs;
|
|
12
|
+
/**
|
|
13
|
+
* 生成 api
|
|
14
|
+
*
|
|
15
|
+
* @param {string} baseUrl swagger 服务地址
|
|
16
|
+
* @param {string} tag 要发布的 api 标识
|
|
17
|
+
* @param {string} template 模板目录
|
|
18
|
+
* @param {string} output 输出目录
|
|
19
|
+
* @param {boolean} clean 是否清理输出目录后再生成
|
|
20
|
+
*/
|
|
21
|
+
run(baseUrl: string, tag: string, template: string, output: string, clean: boolean): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* 基于模型编译输出文件
|
|
24
|
+
*
|
|
25
|
+
* @protected
|
|
26
|
+
* @param {string} url
|
|
27
|
+
* @param {string} outPath
|
|
28
|
+
* @param {HandlebarsEngine} engine
|
|
29
|
+
* @returns {*} {Promise<void>}
|
|
30
|
+
*/
|
|
31
|
+
protected write(tag: string, url: string, outPath: string, engine: HandlebarsEngine): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* 注册所有的宏
|
|
34
|
+
*
|
|
35
|
+
* @protected
|
|
36
|
+
* @param {string} tempPath
|
|
37
|
+
* @param {HandlebarsEngine} engine
|
|
38
|
+
* @returns {*} {Promise<void>}
|
|
39
|
+
*/
|
|
40
|
+
protected registerMacros(tempPath: string, engine: HandlebarsEngine): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* 注册所有模板文件
|
|
43
|
+
*
|
|
44
|
+
* @protected
|
|
45
|
+
* @param {string} tempPath
|
|
46
|
+
* @param {HandlebarsEngine} engine
|
|
47
|
+
* @returns {*} {Promise<void>}
|
|
48
|
+
*/
|
|
49
|
+
protected registerTempFiles(tempPath: string, engine: HandlebarsEngine): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* 针对加载的配置进行处理
|
|
52
|
+
*
|
|
53
|
+
* @protected
|
|
54
|
+
* @param {IObject} model
|
|
55
|
+
* @returns {*} {IObject}
|
|
56
|
+
*/
|
|
57
|
+
protected transformModel(model: IObject): IObject;
|
|
58
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fse from "fs-extra";
|
|
3
|
+
import * as rm from "rimraf";
|
|
4
|
+
import glob from "fast-glob";
|
|
5
|
+
import log from "consola";
|
|
6
|
+
import got from "got";
|
|
7
|
+
import { HandlebarsEngine, MACRO_FOLDER } from "../../core/index.mjs";
|
|
8
|
+
import { ModelManage } from "./model-manage.mjs";
|
|
9
|
+
export class GenApiAction {
|
|
10
|
+
// private baseUrl = 'http://paas.paasdev.gct-paas.com';
|
|
11
|
+
engine = new HandlebarsEngine();
|
|
12
|
+
modelManage = new ModelManage();
|
|
13
|
+
configs = {
|
|
14
|
+
platform: "/gct-platform/v2/api-docs?group=%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0API",
|
|
15
|
+
apaas: "/gct-apaas/v2/api-docs?group=apaas%E5%B9%B3%E5%8F%B0API"
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 生成 api
|
|
19
|
+
*
|
|
20
|
+
* @param {string} baseUrl swagger 服务地址
|
|
21
|
+
* @param {string} tag 要发布的 api 标识
|
|
22
|
+
* @param {string} template 模板目录
|
|
23
|
+
* @param {string} output 输出目录
|
|
24
|
+
* @param {boolean} clean 是否清理输出目录后再生成
|
|
25
|
+
*/
|
|
26
|
+
async run(baseUrl, tag, template, output, clean) {
|
|
27
|
+
const cwd = process.cwd();
|
|
28
|
+
const tempPath = path.resolve(cwd, template);
|
|
29
|
+
const outPath = path.resolve(cwd, output);
|
|
30
|
+
if (clean === true && fse.existsSync(outPath)) {
|
|
31
|
+
rm.sync(outPath);
|
|
32
|
+
}
|
|
33
|
+
await this.registerMacros(tempPath, this.engine);
|
|
34
|
+
await this.registerTempFiles(tempPath, this.engine);
|
|
35
|
+
await this.write(
|
|
36
|
+
tag,
|
|
37
|
+
path.join(baseUrl, this.configs[tag]),
|
|
38
|
+
outPath,
|
|
39
|
+
this.engine
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 基于模型编译输出文件
|
|
44
|
+
*
|
|
45
|
+
* @protected
|
|
46
|
+
* @param {string} url
|
|
47
|
+
* @param {string} outPath
|
|
48
|
+
* @param {HandlebarsEngine} engine
|
|
49
|
+
* @returns {*} {Promise<void>}
|
|
50
|
+
*/
|
|
51
|
+
async write(tag, url, outPath, engine) {
|
|
52
|
+
const cfg = await got(url).json();
|
|
53
|
+
const model = this.transformModel(cfg);
|
|
54
|
+
this.modelManage.init(tag, model);
|
|
55
|
+
const all = [];
|
|
56
|
+
engine.temps.forEach((template, key) => {
|
|
57
|
+
if (key === "") {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const outFilePath = path.join(outPath, key);
|
|
61
|
+
const tags = engine.parseContextTags(key);
|
|
62
|
+
if (tags.length === 0) {
|
|
63
|
+
log.info(`\u751F\u6210\u6587\u4EF6\uFF1A${outFilePath}`);
|
|
64
|
+
all.push(
|
|
65
|
+
fse.outputFile(
|
|
66
|
+
outFilePath,
|
|
67
|
+
engine.render(template, {
|
|
68
|
+
entities: Array.from(this.modelManage.entities.values()),
|
|
69
|
+
definitions: model.definitions
|
|
70
|
+
}),
|
|
71
|
+
"utf-8"
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
} else {
|
|
75
|
+
if (tags.includes("api")) {
|
|
76
|
+
this.modelManage.entities.forEach((model2) => {
|
|
77
|
+
const filePath = engine.render(outFilePath, model2);
|
|
78
|
+
log.info(`\u751F\u6210\u6587\u4EF6\uFF1A${filePath}`);
|
|
79
|
+
all.push(
|
|
80
|
+
fse.outputFile(filePath, engine.render(template, model2), "utf-8")
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
await Promise.all(all);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 注册所有的宏
|
|
90
|
+
*
|
|
91
|
+
* @protected
|
|
92
|
+
* @param {string} tempPath
|
|
93
|
+
* @param {HandlebarsEngine} engine
|
|
94
|
+
* @returns {*} {Promise<void>}
|
|
95
|
+
*/
|
|
96
|
+
async registerMacros(tempPath, engine) {
|
|
97
|
+
const macroFiles = glob.sync(path.join(MACRO_FOLDER, "**/*.hbs"), {
|
|
98
|
+
cwd: tempPath,
|
|
99
|
+
dot: true,
|
|
100
|
+
absolute: true
|
|
101
|
+
});
|
|
102
|
+
if (macroFiles.length > 0) {
|
|
103
|
+
await Promise.all(
|
|
104
|
+
macroFiles.map((macroFilePath) => {
|
|
105
|
+
return new Promise((resolve) => {
|
|
106
|
+
fse.readFile(macroFilePath, "utf-8").then((file) => {
|
|
107
|
+
const key = path.relative(tempPath, macroFilePath);
|
|
108
|
+
log.info(`\u6CE8\u518C\u5B8F\uFF1A${key}`);
|
|
109
|
+
engine.registerMacro(key, file);
|
|
110
|
+
resolve();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 注册所有模板文件
|
|
119
|
+
*
|
|
120
|
+
* @protected
|
|
121
|
+
* @param {string} tempPath
|
|
122
|
+
* @param {HandlebarsEngine} engine
|
|
123
|
+
* @returns {*} {Promise<void>}
|
|
124
|
+
*/
|
|
125
|
+
async registerTempFiles(tempPath, engine) {
|
|
126
|
+
const tempFiles = glob.sync("**/*.hbs", {
|
|
127
|
+
cwd: tempPath,
|
|
128
|
+
dot: true,
|
|
129
|
+
absolute: true,
|
|
130
|
+
ignore: [path.join(MACRO_FOLDER, "**/*.hbs")]
|
|
131
|
+
});
|
|
132
|
+
if (tempFiles.length > 0) {
|
|
133
|
+
await Promise.all(
|
|
134
|
+
tempFiles.map((tempFilePath) => {
|
|
135
|
+
return new Promise((resolve) => {
|
|
136
|
+
fse.readFile(tempFilePath, "utf-8").then((file) => {
|
|
137
|
+
const key = path.relative(tempPath, tempFilePath);
|
|
138
|
+
log.info(`\u6CE8\u518C\u6A21\u677F\uFF1A${key}`);
|
|
139
|
+
engine.registerTemp(key, file);
|
|
140
|
+
resolve();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* 针对加载的配置进行处理
|
|
149
|
+
*
|
|
150
|
+
* @protected
|
|
151
|
+
* @param {IObject} model
|
|
152
|
+
* @returns {*} {IObject}
|
|
153
|
+
*/
|
|
154
|
+
transformModel(model) {
|
|
155
|
+
const keys = Object.keys(model.definitions);
|
|
156
|
+
keys.forEach((key) => {
|
|
157
|
+
const item = model.definitions[key];
|
|
158
|
+
if (item.properties) {
|
|
159
|
+
item.propertySize = Object.keys(item.properties).length;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return model;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { IObject } from '../../core';
|
|
2
|
+
/**
|
|
3
|
+
* 实体方法模型
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @interface IMethodModel
|
|
7
|
+
*/
|
|
8
|
+
export interface IMethodModel {
|
|
9
|
+
/**
|
|
10
|
+
* 方法名称
|
|
11
|
+
*
|
|
12
|
+
* @type {string}
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* 请求方式
|
|
17
|
+
*
|
|
18
|
+
* @type {string}
|
|
19
|
+
*/
|
|
20
|
+
mode: string;
|
|
21
|
+
/**
|
|
22
|
+
* 方法模型
|
|
23
|
+
*
|
|
24
|
+
* @type {IObject}
|
|
25
|
+
*/
|
|
26
|
+
model: IObject;
|
|
27
|
+
/**
|
|
28
|
+
* 请求实体
|
|
29
|
+
*
|
|
30
|
+
* @type {IObject}
|
|
31
|
+
*/
|
|
32
|
+
requestEntity?: IObject;
|
|
33
|
+
/**
|
|
34
|
+
* 响应实体
|
|
35
|
+
*
|
|
36
|
+
* @type {IObject}
|
|
37
|
+
*/
|
|
38
|
+
responseEntity?: IObject;
|
|
39
|
+
/**
|
|
40
|
+
* 查询参数
|
|
41
|
+
*
|
|
42
|
+
* @type {IObject[]}
|
|
43
|
+
*/
|
|
44
|
+
queries: IObject[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 实体模型
|
|
48
|
+
*
|
|
49
|
+
* @export
|
|
50
|
+
* @interface IEntityModel
|
|
51
|
+
*/
|
|
52
|
+
export interface IEntityModel {
|
|
53
|
+
/**
|
|
54
|
+
* 实体名称
|
|
55
|
+
*
|
|
56
|
+
* @type {string}
|
|
57
|
+
*/
|
|
58
|
+
entityName: string;
|
|
59
|
+
/**
|
|
60
|
+
* 平台标识 apaas, platform
|
|
61
|
+
*
|
|
62
|
+
* @type {string}
|
|
63
|
+
*/
|
|
64
|
+
tag: string;
|
|
65
|
+
/**
|
|
66
|
+
* 实体名称(同name)
|
|
67
|
+
*
|
|
68
|
+
* @type {string}
|
|
69
|
+
*/
|
|
70
|
+
api: string;
|
|
71
|
+
/**
|
|
72
|
+
* 实体模型
|
|
73
|
+
*
|
|
74
|
+
* @type {IObject}
|
|
75
|
+
*/
|
|
76
|
+
model: IObject;
|
|
77
|
+
/**
|
|
78
|
+
* 实体方法模型
|
|
79
|
+
*
|
|
80
|
+
* @type {IMethodModel[]}
|
|
81
|
+
*/
|
|
82
|
+
methods: IMethodModel[];
|
|
83
|
+
/**
|
|
84
|
+
* 实体引用实体名称集合
|
|
85
|
+
*
|
|
86
|
+
* @type {string[]}
|
|
87
|
+
*/
|
|
88
|
+
entityRefs: string[];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 模型管理
|
|
92
|
+
*
|
|
93
|
+
* @export
|
|
94
|
+
* @class ModelManage
|
|
95
|
+
*/
|
|
96
|
+
export declare class ModelManage {
|
|
97
|
+
/**
|
|
98
|
+
* 所有实体模型
|
|
99
|
+
*
|
|
100
|
+
* @type {Map<string, IEntityModel>}
|
|
101
|
+
*/
|
|
102
|
+
readonly entities: Map<string, IEntityModel>;
|
|
103
|
+
/**
|
|
104
|
+
* 所有用到的实体定义
|
|
105
|
+
*
|
|
106
|
+
* @type {Map<string, IObject>}
|
|
107
|
+
*/
|
|
108
|
+
readonly definitions: Map<string, IObject>;
|
|
109
|
+
/**
|
|
110
|
+
* 目前接口中的基础数据类型
|
|
111
|
+
*
|
|
112
|
+
* @protected
|
|
113
|
+
*/
|
|
114
|
+
protected basicDataType: string[];
|
|
115
|
+
init(tag: string, cfg: IObject): void;
|
|
116
|
+
/**
|
|
117
|
+
* 获取接口的引用对象
|
|
118
|
+
*
|
|
119
|
+
* @protected
|
|
120
|
+
* @param {IObject} data
|
|
121
|
+
* @returns {*} {string}
|
|
122
|
+
*/
|
|
123
|
+
protected getOriginRef(data: IObject): string;
|
|
124
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ApiManage } from "./api-manage.mjs";
|
|
2
|
+
export class ModelManage {
|
|
3
|
+
/**
|
|
4
|
+
* 所有实体模型
|
|
5
|
+
*
|
|
6
|
+
* @type {Map<string, IEntityModel>}
|
|
7
|
+
*/
|
|
8
|
+
entities = /* @__PURE__ */ new Map();
|
|
9
|
+
/**
|
|
10
|
+
* 所有用到的实体定义
|
|
11
|
+
*
|
|
12
|
+
* @type {Map<string, IObject>}
|
|
13
|
+
*/
|
|
14
|
+
definitions = /* @__PURE__ */ new Map();
|
|
15
|
+
/**
|
|
16
|
+
* 目前接口中的基础数据类型
|
|
17
|
+
*
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
20
|
+
basicDataType = [
|
|
21
|
+
"any",
|
|
22
|
+
"number",
|
|
23
|
+
"string",
|
|
24
|
+
"null",
|
|
25
|
+
"boolean",
|
|
26
|
+
"Void",
|
|
27
|
+
"object"
|
|
28
|
+
];
|
|
29
|
+
init(tag, cfg) {
|
|
30
|
+
const apiManage = new ApiManage();
|
|
31
|
+
const paths = Object.keys(cfg.paths).filter((pathStr) => {
|
|
32
|
+
return !pathStr.startsWith("/external") || pathStr === "/external/api/tenant/info/byPortOrDomain";
|
|
33
|
+
});
|
|
34
|
+
paths.forEach((pathStr) => {
|
|
35
|
+
const pathCfg = cfg.paths[pathStr];
|
|
36
|
+
apiManage.add(pathStr, pathCfg);
|
|
37
|
+
});
|
|
38
|
+
const entityNames = apiManage.cache.keys();
|
|
39
|
+
for (const entityName of entityNames) {
|
|
40
|
+
const entitySet = /* @__PURE__ */ new Set();
|
|
41
|
+
const entityManage = apiManage.cache.get(entityName);
|
|
42
|
+
const methods = [];
|
|
43
|
+
const tags = entityManage.cache.keys();
|
|
44
|
+
for (const tag2 of tags) {
|
|
45
|
+
const [methodName, mode] = tag2.split(":");
|
|
46
|
+
const config = entityManage.cache.get(tag2);
|
|
47
|
+
let requestEntity = void 0;
|
|
48
|
+
const param = config.parameters.find((param2) => {
|
|
49
|
+
if (param2.in === "body") {
|
|
50
|
+
return param2;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
if (param && param.schema) {
|
|
54
|
+
const refKey = this.getOriginRef(param.schema);
|
|
55
|
+
requestEntity = cfg.definitions[refKey];
|
|
56
|
+
if (requestEntity && Object.keys(requestEntity).length > 0) {
|
|
57
|
+
this.definitions.set(refKey, requestEntity);
|
|
58
|
+
entitySet.add(refKey);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
let responseEntity = void 0;
|
|
62
|
+
if (config.responses["200"].schema) {
|
|
63
|
+
const refKey = this.getOriginRef(config.responses["200"].schema);
|
|
64
|
+
responseEntity = cfg.definitions[refKey];
|
|
65
|
+
if (responseEntity && Object.keys(responseEntity).length > 0) {
|
|
66
|
+
this.definitions.set(refKey, responseEntity);
|
|
67
|
+
entitySet.add(refKey);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const queries = config.parameters.filter(
|
|
71
|
+
(param2) => {
|
|
72
|
+
if (param2.in === "query") {
|
|
73
|
+
return param2;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
if (methodName === "{id}") {
|
|
78
|
+
queries.push({
|
|
79
|
+
name: "id",
|
|
80
|
+
in: "query",
|
|
81
|
+
description: "\u6570\u636E\u4E3B\u952E",
|
|
82
|
+
required: true,
|
|
83
|
+
type: "string"
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
methods.push({
|
|
87
|
+
name: methodName !== "undefined" ? methodName : "",
|
|
88
|
+
mode,
|
|
89
|
+
model: config,
|
|
90
|
+
requestEntity,
|
|
91
|
+
responseEntity,
|
|
92
|
+
queries
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
this.entities.set(entityName, {
|
|
96
|
+
tag,
|
|
97
|
+
entityName,
|
|
98
|
+
api: entityName,
|
|
99
|
+
model: cfg.definitions[entityName],
|
|
100
|
+
methods,
|
|
101
|
+
entityRefs: Array.from(entitySet.values()).filter((item) => {
|
|
102
|
+
return this.basicDataType.findIndex((type) => {
|
|
103
|
+
return item.indexOf(`\xAB${type}\xBB`) !== -1;
|
|
104
|
+
}) === -1 && !this.basicDataType.includes(item);
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 获取接口的引用对象
|
|
111
|
+
*
|
|
112
|
+
* @protected
|
|
113
|
+
* @param {IObject} data
|
|
114
|
+
* @returns {*} {string}
|
|
115
|
+
*/
|
|
116
|
+
getOriginRef(data) {
|
|
117
|
+
const { $ref, originalRef, type } = data;
|
|
118
|
+
if (type) return type;
|
|
119
|
+
if (originalRef) return originalRef;
|
|
120
|
+
if ($ref) {
|
|
121
|
+
const _refs_ = $ref.split("/");
|
|
122
|
+
return _refs_[_refs_.length - 1];
|
|
123
|
+
}
|
|
124
|
+
return "any";
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GenApiAction } from './gen-api/gen-api';
|