@gct-paas/cli 0.0.1-dev.1 → 0.0.1-dev.10

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.
Files changed (201) hide show
  1. package/LICENSE +21 -0
  2. package/dist/actions/gen-api/api-manage.cjs +46 -0
  3. package/dist/actions/gen-api/api-manage.d.ts +36 -0
  4. package/dist/actions/gen-api/gen-api.cjs +157 -0
  5. package/dist/actions/gen-api/gen-api.d.ts +58 -0
  6. package/dist/actions/gen-api/model-manage.cjs +127 -0
  7. package/dist/actions/gen-api/model-manage.d.ts +124 -0
  8. package/dist/actions/index.cjs +12 -0
  9. package/dist/actions/index.d.ts +1 -0
  10. package/dist/bin.cjs +5 -0
  11. package/dist/bin.d.ts +2 -0
  12. package/dist/commands/gen-api/gen-api.cjs +16 -0
  13. package/dist/commands/gen-api/gen-api.d.ts +44 -0
  14. package/dist/commands/index.cjs +23 -0
  15. package/dist/commands/index.d.ts +5 -0
  16. package/dist/core/handlebars/constant/index.cjs +8 -0
  17. package/dist/core/handlebars/constant/index.d.ts +2 -0
  18. package/dist/core/handlebars/handlebars-engine.cjs +134 -0
  19. package/dist/core/handlebars/handlebars-engine.d.ts +74 -0
  20. package/dist/core/handlebars/helpers/and/and.cjs +21 -0
  21. package/dist/core/handlebars/helpers/and/and.d.ts +13 -0
  22. package/dist/core/handlebars/helpers/camel-case/camel-case.cjs +20 -0
  23. package/dist/core/handlebars/helpers/camel-case/camel-case.d.ts +13 -0
  24. package/dist/core/handlebars/helpers/concat/concat.cjs +17 -0
  25. package/dist/core/handlebars/helpers/concat/concat.d.ts +13 -0
  26. package/dist/core/handlebars/helpers/eq/eq.cjs +19 -0
  27. package/dist/core/handlebars/helpers/eq/eq.d.ts +14 -0
  28. package/dist/core/handlebars/helpers/format-import/format-import.cjs +41 -0
  29. package/dist/core/handlebars/helpers/format-import/format-import.d.ts +13 -0
  30. package/dist/core/handlebars/helpers/format-import-item/format-import-item.cjs +37 -0
  31. package/dist/core/handlebars/helpers/format-import-item/format-import-item.d.ts +13 -0
  32. package/dist/core/handlebars/helpers/format-js-type/format-js-type.cjs +41 -0
  33. package/dist/core/handlebars/helpers/format-js-type/format-js-type.d.ts +14 -0
  34. package/dist/core/handlebars/helpers/gt/gt.cjs +19 -0
  35. package/dist/core/handlebars/helpers/gt/gt.d.ts +14 -0
  36. package/dist/core/handlebars/helpers/gte/gte.cjs +19 -0
  37. package/dist/core/handlebars/helpers/gte/gte.d.ts +14 -0
  38. package/dist/core/handlebars/helpers/helper-base.cjs +19 -0
  39. package/dist/core/handlebars/helpers/helper-base.d.ts +22 -0
  40. package/dist/core/handlebars/helpers/includes/includes.cjs +18 -0
  41. package/dist/core/handlebars/helpers/includes/includes.d.ts +13 -0
  42. package/dist/core/handlebars/helpers/index.cjs +52 -0
  43. package/dist/core/handlebars/helpers/index.d.ts +6 -0
  44. package/dist/core/handlebars/helpers/json/json.cjs +16 -0
  45. package/dist/core/handlebars/helpers/json/json.d.ts +13 -0
  46. package/dist/core/handlebars/helpers/lower-case/lower-case.cjs +19 -0
  47. package/dist/core/handlebars/helpers/lower-case/lower-case.d.ts +13 -0
  48. package/dist/core/handlebars/helpers/lt/lt.cjs +19 -0
  49. package/dist/core/handlebars/helpers/lt/lt.d.ts +14 -0
  50. package/dist/core/handlebars/helpers/lte/lte.cjs +19 -0
  51. package/dist/core/handlebars/helpers/lte/lte.d.ts +14 -0
  52. package/dist/core/handlebars/helpers/neq/neq.cjs +19 -0
  53. package/dist/core/handlebars/helpers/neq/neq.d.ts +14 -0
  54. package/dist/core/handlebars/helpers/not/not.cjs +21 -0
  55. package/dist/core/handlebars/helpers/not/not.d.ts +14 -0
  56. package/dist/core/handlebars/helpers/not-includes/not-includes.cjs +18 -0
  57. package/dist/core/handlebars/helpers/not-includes/not-includes.d.ts +13 -0
  58. package/dist/core/handlebars/helpers/or/or.cjs +23 -0
  59. package/dist/core/handlebars/helpers/or/or.d.ts +13 -0
  60. package/dist/core/handlebars/helpers/pascal-case/pascal-case.cjs +20 -0
  61. package/dist/core/handlebars/helpers/pascal-case/pascal-case.d.ts +13 -0
  62. package/dist/core/handlebars/helpers/snake-case/snake-case.cjs +20 -0
  63. package/dist/core/handlebars/helpers/snake-case/snake-case.d.ts +13 -0
  64. package/dist/core/handlebars/helpers/spinal-case/spinal-case.cjs +20 -0
  65. package/dist/core/handlebars/helpers/spinal-case/spinal-case.d.ts +13 -0
  66. package/dist/core/handlebars/helpers/upper-case/upper-case.cjs +19 -0
  67. package/dist/core/handlebars/helpers/upper-case/upper-case.d.ts +13 -0
  68. package/dist/core/handlebars/index.cjs +27 -0
  69. package/dist/core/handlebars/index.d.ts +2 -0
  70. package/dist/core/handlebars/utils/helper/helper.cjs +41 -0
  71. package/dist/core/handlebars/utils/helper/helper.d.ts +33 -0
  72. package/dist/core/handlebars/utils/index.cjs +20 -0
  73. package/dist/core/handlebars/utils/index.d.ts +17 -0
  74. package/dist/core/index.cjs +27 -0
  75. package/dist/core/index.d.ts +2 -0
  76. package/dist/core/interface/index.cjs +1 -0
  77. package/dist/core/interface/index.d.ts +1 -0
  78. package/dist/index.cjs +47 -0
  79. package/dist/index.d.ts +2 -0
  80. package/dist/interface/i-command/i-command.cjs +1 -0
  81. package/dist/interface/i-command/i-command.d.ts +22 -0
  82. package/dist/interface/index.cjs +16 -0
  83. package/dist/utils/index.cjs +18 -0
  84. package/dist/utils/index.d.ts +1 -0
  85. package/dist/utils/local-binaries/local-binaries.cjs +19 -0
  86. package/dist/utils/local-binaries/local-binaries.d.ts +3 -0
  87. package/es/actions/gen-api/api-manage.d.ts +36 -0
  88. package/es/actions/gen-api/api-manage.mjs +38 -0
  89. package/es/actions/gen-api/gen-api.d.ts +58 -0
  90. package/es/actions/gen-api/gen-api.mjs +164 -0
  91. package/es/actions/gen-api/model-manage.d.ts +124 -0
  92. package/es/actions/gen-api/model-manage.mjs +126 -0
  93. package/es/actions/index.d.ts +1 -0
  94. package/es/actions/index.mjs +1 -0
  95. package/es/bin.d.ts +2 -0
  96. package/es/commands/gen-api/gen-api.d.ts +44 -0
  97. package/es/commands/gen-api/gen-api.mjs +15 -0
  98. package/es/commands/index.d.ts +5 -0
  99. package/es/commands/index.mjs +16 -0
  100. package/es/core/handlebars/constant/index.d.ts +2 -0
  101. package/es/core/handlebars/constant/index.mjs +2 -0
  102. package/es/core/handlebars/handlebars-engine.d.ts +74 -0
  103. package/es/core/handlebars/handlebars-engine.mjs +122 -0
  104. package/es/core/handlebars/helpers/and/and.d.ts +13 -0
  105. package/es/core/handlebars/helpers/and/and.mjs +14 -0
  106. package/es/core/handlebars/helpers/camel-case/camel-case.d.ts +13 -0
  107. package/es/core/handlebars/helpers/camel-case/camel-case.mjs +13 -0
  108. package/es/core/handlebars/helpers/concat/concat.d.ts +13 -0
  109. package/es/core/handlebars/helpers/concat/concat.mjs +10 -0
  110. package/es/core/handlebars/helpers/eq/eq.d.ts +14 -0
  111. package/es/core/handlebars/helpers/eq/eq.mjs +12 -0
  112. package/es/core/handlebars/helpers/format-import/format-import.d.ts +13 -0
  113. package/es/core/handlebars/helpers/format-import/format-import.mjs +34 -0
  114. package/es/core/handlebars/helpers/format-import-item/format-import-item.d.ts +13 -0
  115. package/es/core/handlebars/helpers/format-import-item/format-import-item.mjs +30 -0
  116. package/es/core/handlebars/helpers/format-js-type/format-js-type.d.ts +14 -0
  117. package/es/core/handlebars/helpers/format-js-type/format-js-type.mjs +34 -0
  118. package/es/core/handlebars/helpers/gt/gt.d.ts +14 -0
  119. package/es/core/handlebars/helpers/gt/gt.mjs +12 -0
  120. package/es/core/handlebars/helpers/gte/gte.d.ts +14 -0
  121. package/es/core/handlebars/helpers/gte/gte.mjs +12 -0
  122. package/es/core/handlebars/helpers/helper-base.d.ts +22 -0
  123. package/es/core/handlebars/helpers/helper-base.mjs +11 -0
  124. package/es/core/handlebars/helpers/includes/includes.d.ts +13 -0
  125. package/es/core/handlebars/helpers/includes/includes.mjs +11 -0
  126. package/es/core/handlebars/helpers/index.d.ts +6 -0
  127. package/es/core/handlebars/helpers/index.mjs +46 -0
  128. package/es/core/handlebars/helpers/json/json.d.ts +13 -0
  129. package/es/core/handlebars/helpers/json/json.mjs +13 -0
  130. package/es/core/handlebars/helpers/lower-case/lower-case.d.ts +13 -0
  131. package/es/core/handlebars/helpers/lower-case/lower-case.mjs +12 -0
  132. package/es/core/handlebars/helpers/lt/lt.d.ts +14 -0
  133. package/es/core/handlebars/helpers/lt/lt.mjs +12 -0
  134. package/es/core/handlebars/helpers/lte/lte.d.ts +14 -0
  135. package/es/core/handlebars/helpers/lte/lte.mjs +12 -0
  136. package/es/core/handlebars/helpers/neq/neq.d.ts +14 -0
  137. package/es/core/handlebars/helpers/neq/neq.mjs +12 -0
  138. package/es/core/handlebars/helpers/not/not.d.ts +14 -0
  139. package/es/core/handlebars/helpers/not/not.mjs +12 -0
  140. package/es/core/handlebars/helpers/not-includes/not-includes.d.ts +13 -0
  141. package/es/core/handlebars/helpers/not-includes/not-includes.mjs +11 -0
  142. package/es/core/handlebars/helpers/or/or.d.ts +13 -0
  143. package/es/core/handlebars/helpers/or/or.mjs +16 -0
  144. package/es/core/handlebars/helpers/pascal-case/pascal-case.d.ts +13 -0
  145. package/es/core/handlebars/helpers/pascal-case/pascal-case.mjs +13 -0
  146. package/es/core/handlebars/helpers/snake-case/snake-case.d.ts +13 -0
  147. package/es/core/handlebars/helpers/snake-case/snake-case.mjs +13 -0
  148. package/es/core/handlebars/helpers/spinal-case/spinal-case.d.ts +13 -0
  149. package/es/core/handlebars/helpers/spinal-case/spinal-case.mjs +13 -0
  150. package/es/core/handlebars/helpers/upper-case/upper-case.d.ts +13 -0
  151. package/es/core/handlebars/helpers/upper-case/upper-case.mjs +12 -0
  152. package/es/core/handlebars/index.d.ts +2 -0
  153. package/es/core/handlebars/index.mjs +2 -0
  154. package/es/core/handlebars/utils/helper/helper.d.ts +33 -0
  155. package/es/core/handlebars/utils/helper/helper.mjs +54 -0
  156. package/es/core/handlebars/utils/index.d.ts +17 -0
  157. package/es/core/handlebars/utils/index.mjs +7 -0
  158. package/es/core/index.d.ts +2 -0
  159. package/es/core/index.mjs +2 -0
  160. package/es/core/interface/index.d.ts +1 -0
  161. package/es/core/interface/index.mjs +0 -0
  162. package/es/index.d.ts +2 -0
  163. package/es/interface/i-command/i-command.d.ts +22 -0
  164. package/es/interface/i-command/i-command.mjs +0 -0
  165. package/es/interface/index.d.ts +1 -0
  166. package/es/interface/index.mjs +1 -0
  167. package/es/types/index.d.ts +1 -0
  168. package/es/utils/index.d.ts +1 -0
  169. package/es/utils/index.mjs +4 -0
  170. package/es/utils/local-binaries/local-binaries.d.ts +3 -0
  171. package/es/utils/local-binaries/local-binaries.mjs +11 -0
  172. package/package.json +29 -47
  173. package/src/bin.ts +0 -5
  174. package/src/commands/index.ts +0 -16
  175. package/src/core/commitlint/commitlint-config/commitlint-config.ts +0 -37
  176. package/src/core/commitlint/index.ts +0 -1
  177. package/src/core/constants/index.ts +0 -8
  178. package/src/core/eslint/eslint-config/eslint-config.ts +0 -122
  179. package/src/core/eslint/index.ts +0 -1
  180. package/src/core/index.ts +0 -7
  181. package/src/core/prettier/index.ts +0 -1
  182. package/src/core/prettier/prettier-config/prettier-config.ts +0 -48
  183. package/src/core/rollup/index.ts +0 -2
  184. package/src/core/rollup/rollup-config/dev-config.ts +0 -135
  185. package/src/core/rollup/rollup-plugins/copy-file.ts +0 -57
  186. package/src/core/rollup/rollup-plugins/ignore-compiler-file.ts +0 -25
  187. package/src/core/rollup/rollup-plugins/index.ts +0 -2
  188. package/src/core/stylelint/index.ts +0 -1
  189. package/src/core/stylelint/stylelint-config/stylelint-config.ts +0 -28
  190. package/src/core/util/index.ts +0 -27
  191. package/src/core/util/watcher/watcher.ts +0 -129
  192. package/src/core/vite/index.ts +0 -1
  193. package/src/core/vite/vite-config/vite-config.ts +0 -59
  194. package/src/index.ts +0 -36
  195. package/src/interface/i-command/i-command.ts +0 -29
  196. package/src/utils/index.ts +0 -4
  197. package/src/utils/local-binaries/local-binaries.ts +0 -16
  198. /package/{src/interface/index.ts → dist/interface/index.d.ts} +0 -0
  199. /package/{src → dist}/types/index.d.ts +0 -0
  200. /package/{dist → es}/bin.mjs +0 -0
  201. /package/{dist → es}/index.mjs +0 -0
@@ -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';
@@ -0,0 +1 @@
1
+ export { GenApiAction } from "./gen-api/gen-api.mjs";
package/es/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,44 @@
1
+ import { Command } from 'commander';
2
+ import { ICommand } from '../../interface';
3
+ export interface GenApiOptions {
4
+ /**
5
+ * 模板目录
6
+ *
7
+ * @author chitanda
8
+ * @date 2021-12-19 20:12:32
9
+ * @type {string}
10
+ */
11
+ template: string;
12
+ /**
13
+ * 模板输出目录
14
+ *
15
+ * @author chitanda
16
+ * @date 2021-12-19 20:12:37
17
+ * @type {string}
18
+ */
19
+ output: string;
20
+ /**
21
+ * 清理输出目录
22
+ *
23
+ * @author chitanda
24
+ * @date 2021-12-21 10:12:47
25
+ * @type {boolean}
26
+ */
27
+ clean: boolean;
28
+ /**
29
+ * swagger 地址
30
+ *
31
+ * @type {string}
32
+ */
33
+ url: string;
34
+ /**
35
+ * api标识
36
+ *
37
+ * @type {string}
38
+ */
39
+ tag: string;
40
+ }
41
+ export declare class GenApiCommand implements ICommand {
42
+ load(program: Command): void;
43
+ action(args: GenApiOptions): Promise<void>;
44
+ }
@@ -0,0 +1,15 @@
1
+ import { GenApiAction } from "../../actions/index.mjs";
2
+ export class GenApiCommand {
3
+ load(program) {
4
+ program.command("gen-api").description("\u751F\u6210 api \u6587\u4EF6").option("--url <base-url>", "\u6307\u5B9Aapi\u83B7\u53D6\u7684swagger\u5730\u5740").option("-t --template <template>", "\u6307\u5B9A\u6A21\u677F\u76EE\u5F55").option("-o --output <output>", "\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55").option("--tag <tag>", "\u6307\u5B9A\u5F53\u524D\u53D1\u5E03\u7684\u5206\u652F").option("--clean", "\u6E05\u7406\u8F93\u51FA\u76EE\u5F55").action(this.action.bind(this));
5
+ }
6
+ async action(args) {
7
+ await new GenApiAction().run(
8
+ args.url,
9
+ args.tag,
10
+ args.template,
11
+ args.output,
12
+ args.clean
13
+ );
14
+ }
15
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from 'commander';
2
+ export declare class CommandLoader {
3
+ static load(program: Command): void;
4
+ private static handleInvalidCommand;
5
+ }
@@ -0,0 +1,16 @@
1
+ import { consola } from "consola";
2
+ import { GenApiCommand } from "./gen-api/gen-api.mjs";
3
+ export class CommandLoader {
4
+ static load(program) {
5
+ new GenApiCommand().load(program);
6
+ this.handleInvalidCommand(program);
7
+ }
8
+ static handleInvalidCommand(program) {
9
+ program.on("command:*", () => {
10
+ consola.error(`\u672A\u652F\u6301\u7684\u547D\u4EE4: `, program.args.join(" "));
11
+ consola.log(`\u8BF7\u4F7F\u7528 --help \u67E5\u770B\u5DF2\u652F\u6301\u7684\u547D\u4EE4.
12
+ `);
13
+ process.exit(1);
14
+ });
15
+ }
16
+ }
@@ -0,0 +1,2 @@
1
+ export declare const TEMP_EXTENSION = ".hbs";
2
+ export declare const MACRO_FOLDER = "@macro";
@@ -0,0 +1,2 @@
1
+ export const TEMP_EXTENSION = ".hbs";
2
+ export const MACRO_FOLDER = "@macro";
@@ -0,0 +1,74 @@
1
+ import Handlebars from 'handlebars';
2
+ import { IObject } from '../interface';
3
+ /**
4
+ * 生成器
5
+ *
6
+ * @export
7
+ * @class HandlebarsEngine
8
+ */
9
+ export declare class HandlebarsEngine {
10
+ /**
11
+ * 编译参数
12
+ *
13
+ * @protected
14
+ * @type {CompileOptions}
15
+ */
16
+ protected compileOpt: CompileOptions;
17
+ /**
18
+ * Handlebars 运行时参数
19
+ *
20
+ * @protected
21
+ * @type {Handlebars.RuntimeOptions}
22
+ */
23
+ protected runtimeOpt: Handlebars.RuntimeOptions;
24
+ /**
25
+ * 忽略编译的上下文标签规则
26
+ *
27
+ * @protected
28
+ */
29
+ protected tagReg: RegExp;
30
+ /**
31
+ * 模板映射内容
32
+ *
33
+ * @type {Map<string, string>} Map<模板路径, 模板内容>
34
+ */
35
+ readonly temps: Map<string, string>;
36
+ constructor();
37
+ /**
38
+ * 注册宏
39
+ *
40
+ * @param {string} key 宏标识
41
+ * @param {string} template 宏模板内容
42
+ */
43
+ registerMacro(key: string, template: string): void;
44
+ /**
45
+ * 注册模板
46
+ *
47
+ * @param {string} key
48
+ * @param {string} template
49
+ */
50
+ registerTemp(key: string, template: string): void;
51
+ /**
52
+ * 编译模板获取所有使用到的上下文级参数标识
53
+ *
54
+ * @param {string} template
55
+ * @return {*} {string[]}
56
+ */
57
+ parseContextTags(template: string): string[];
58
+ /**
59
+ * 计算编译模板中的参数标签
60
+ *
61
+ * @protected
62
+ * @param {Set<string>} set
63
+ * @param {Record<string, any>[]} tags
64
+ */
65
+ protected calcTemplateTags(set: Set<string>, tags: Record<string, any>[]): void;
66
+ /**
67
+ * 直接工具模板和数据编译
68
+ *
69
+ * @param {string} template
70
+ * @param {IObject} data
71
+ * @return {*} {string}
72
+ */
73
+ render(template: string, data: IObject): string;
74
+ }
@@ -0,0 +1,122 @@
1
+ import Handlebars from "handlebars";
2
+ import { installHelpers } from "./helpers/index.mjs";
3
+ import { HelperUtil, winToUnixPath } from "./utils/index.mjs";
4
+ import { TEMP_EXTENSION } from "./constant/index.mjs";
5
+ export class HandlebarsEngine {
6
+ /**
7
+ * 编译参数
8
+ *
9
+ * @protected
10
+ * @type {CompileOptions}
11
+ */
12
+ compileOpt = { compat: true, noEscape: true };
13
+ /**
14
+ * Handlebars 运行时参数
15
+ *
16
+ * @protected
17
+ * @type {Handlebars.RuntimeOptions}
18
+ */
19
+ runtimeOpt = {
20
+ allowProtoPropertiesByDefault: true
21
+ };
22
+ /**
23
+ * 忽略编译的上下文标签规则
24
+ *
25
+ * @protected
26
+ */
27
+ tagReg = /^[a-zA-Z0-9:_-]+$/;
28
+ /**
29
+ * 模板映射内容
30
+ *
31
+ * @type {Map<string, string>} Map<模板路径, 模板内容>
32
+ */
33
+ temps = /* @__PURE__ */ new Map();
34
+ constructor() {
35
+ installHelpers();
36
+ }
37
+ /**
38
+ * 注册宏
39
+ *
40
+ * @param {string} key 宏标识
41
+ * @param {string} template 宏模板内容
42
+ */
43
+ registerMacro(key, template) {
44
+ key = winToUnixPath(key);
45
+ if (key.endsWith(TEMP_EXTENSION)) {
46
+ key = key.replace(TEMP_EXTENSION, "");
47
+ Handlebars.registerPartial(key, template);
48
+ } else {
49
+ Handlebars.registerPartial(key, template);
50
+ }
51
+ }
52
+ /**
53
+ * 注册模板
54
+ *
55
+ * @param {string} key
56
+ * @param {string} template
57
+ */
58
+ registerTemp(key, template) {
59
+ key = winToUnixPath(key);
60
+ if (key.endsWith(TEMP_EXTENSION)) {
61
+ key = key.replace(TEMP_EXTENSION, "");
62
+ this.temps.set(key, template);
63
+ } else {
64
+ this.temps.set(key, template);
65
+ }
66
+ }
67
+ /**
68
+ * 编译模板获取所有使用到的上下文级参数标识
69
+ *
70
+ * @param {string} template
71
+ * @return {*} {string[]}
72
+ */
73
+ parseContextTags(template) {
74
+ const program = Handlebars.parse(template);
75
+ const set = /* @__PURE__ */ new Set();
76
+ this.calcTemplateTags(set, program.body);
77
+ return Array.from(set);
78
+ }
79
+ /**
80
+ * 计算编译模板中的参数标签
81
+ *
82
+ * @protected
83
+ * @param {Set<string>} set
84
+ * @param {Record<string, any>[]} tags
85
+ */
86
+ calcTemplateTags(set, tags) {
87
+ tags.forEach((item) => {
88
+ switch (item.type) {
89
+ case "SubExpression":
90
+ if (item.params?.length > 0) {
91
+ this.calcTemplateTags(set, item.params);
92
+ }
93
+ return;
94
+ case "MustacheStatement":
95
+ case "PathExpression": {
96
+ const tag = item.path ? item.path.original : item.original;
97
+ if (HelperUtil.isHelperName(tag)) {
98
+ if (item.params?.length > 0) {
99
+ this.calcTemplateTags(set, item.params);
100
+ }
101
+ return;
102
+ }
103
+ if (this.tagReg.test(tag)) {
104
+ set.add(tag);
105
+ }
106
+ break;
107
+ }
108
+ default:
109
+ }
110
+ });
111
+ }
112
+ /**
113
+ * 直接工具模板和数据编译
114
+ *
115
+ * @param {string} template
116
+ * @param {IObject} data
117
+ * @return {*} {string}
118
+ */
119
+ render(template, data) {
120
+ return Handlebars.compile(template, this.compileOpt)(data, this.runtimeOpt);
121
+ }
122
+ }
@@ -0,0 +1,13 @@
1
+ import { HelperBase } from '../helper-base';
2
+ /**
3
+ * 并且条件模式
4
+ *
5
+ * @description 判断: word wor2 word3 必须在判断中必须全部为 true, 用法: {{#and word word2 word3}}xxx{{else}}yyy{{/and}}、{{and word word2 word3}} 返回值为 boolean 类型
6
+ * @export
7
+ * @class HelperAnd
8
+ * @extends {HelperBase}
9
+ */
10
+ export declare class HelperAnd extends HelperBase {
11
+ constructor();
12
+ onExecute(...args: unknown[] | Handlebars.HelperOptions[]): string | boolean;
13
+ }
@@ -0,0 +1,14 @@
1
+ import { HelperUtil } from "../../utils/index.mjs";
2
+ import { HelperBase } from "../helper-base.mjs";
3
+ export class HelperAnd extends HelperBase {
4
+ constructor() {
5
+ super("and");
6
+ }
7
+ onExecute(...args) {
8
+ const options = args[args.length - 1];
9
+ args.pop();
10
+ const arr = args.filter((item) => !!item);
11
+ const bol = arr.length === args.length;
12
+ return HelperUtil.handleJudgmentExecute(this, bol, options);
13
+ }
14
+ }
@@ -0,0 +1,13 @@
1
+ import { HelperBase } from '../helper-base';
2
+ /**
3
+ * 转驼峰
4
+ *
5
+ * @description 用法 {{camelCase xxx}},效果: this-is-my-name => thisIsMyName
6
+ * @export
7
+ * @class HelperCamelCase
8
+ * @extends {HelperBase}
9
+ */
10
+ export declare class HelperCamelCase extends HelperBase {
11
+ constructor();
12
+ onExecute(param: string): string;
13
+ }
@@ -0,0 +1,13 @@
1
+ import { camelCase } from "lodash-es";
2
+ import { HelperBase } from "../helper-base.mjs";
3
+ export class HelperCamelCase extends HelperBase {
4
+ constructor() {
5
+ super("camelCase");
6
+ }
7
+ onExecute(param) {
8
+ if (!param) {
9
+ return "";
10
+ }
11
+ return camelCase(param);
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ import { HelperBase } from '../helper-base';
2
+ /**
3
+ * 字符串拼接
4
+ *
5
+ * @description 用法:{{concat string1 string2 string3}} 返回值为 string 类型
6
+ * @export
7
+ * @class HelperConcat
8
+ * @extends {HelperBase}
9
+ */
10
+ export declare class HelperConcat extends HelperBase {
11
+ constructor();
12
+ onExecute(...args: string[]): string;
13
+ }
@@ -0,0 +1,10 @@
1
+ import { HelperBase } from "../helper-base.mjs";
2
+ export class HelperConcat extends HelperBase {
3
+ constructor() {
4
+ super("concat");
5
+ }
6
+ onExecute(...args) {
7
+ args.pop();
8
+ return args.join("");
9
+ }
10
+ }
@@ -0,0 +1,14 @@
1
+ import * as Handlebars from 'handlebars';
2
+ import { HelperBase } from '../helper-base';
3
+ /**
4
+ * 等于
5
+ *
6
+ * @description 判断: word === word2, 用法: {{#eq word word2}}xxx{{else}}yyy{{/eq}}、{{eq word 'xxx'}} 返回值为 boolean 类型
7
+ * @export
8
+ * @class HelperEq
9
+ * @extends {HelperBase}
10
+ */
11
+ export declare class HelperEq extends HelperBase {
12
+ constructor();
13
+ onExecute(param: unknown, param2: unknown, options: Handlebars.HelperOptions): string | boolean;
14
+ }
@@ -0,0 +1,12 @@
1
+ import { eq } from "lodash-es";
2
+ import { HelperUtil } from "../../utils/index.mjs";
3
+ import { HelperBase } from "../helper-base.mjs";
4
+ export class HelperEq extends HelperBase {
5
+ constructor() {
6
+ super("eq");
7
+ }
8
+ onExecute(param, param2, options) {
9
+ const bol = eq(param, param2);
10
+ return HelperUtil.handleJudgmentExecute(this, bol, options);
11
+ }
12
+ }
@@ -0,0 +1,13 @@
1
+ import { HelperBase } from '../helper-base';
2
+ /**
3
+ * 格式化导入
4
+ *
5
+ * @description 专门格式化导入的 response 对象,效果: ResponseEntity«List«TraceSettingResponse»» => TraceSettingResponse
6
+ * @export
7
+ * @class HelperFormatImport
8
+ * @extends {HelperBase}
9
+ */
10
+ export declare class HelperFormatImport extends HelperBase {
11
+ constructor();
12
+ onExecute(param: string[]): string;
13
+ }
@@ -0,0 +1,34 @@
1
+ import { HelperBase } from "../helper-base.mjs";
2
+ export class HelperFormatImport extends HelperBase {
3
+ constructor() {
4
+ super("formatImport");
5
+ }
6
+ onExecute(param) {
7
+ if (!param || param.length === 0) {
8
+ return "";
9
+ }
10
+ const items = param.map((item) => {
11
+ if (item.indexOf("\xAB") > -1) {
12
+ const arr = item.split("\xAB");
13
+ return arr[arr.length - 1].split("\xBB")[0];
14
+ }
15
+ return item;
16
+ }).filter((item) => {
17
+ const keys = item.split(",");
18
+ const tag = keys[0];
19
+ switch (tag) {
20
+ case "string":
21
+ case "object":
22
+ case "void":
23
+ case "integer":
24
+ case "int":
25
+ case "long":
26
+ case "Map":
27
+ return false;
28
+ default:
29
+ return true;
30
+ }
31
+ });
32
+ return Array.from(new Set(items)).join(",");
33
+ }
34
+ }
@@ -0,0 +1,13 @@
1
+ import { HelperBase } from '../helper-base';
2
+ /**
3
+ * 格式化导入
4
+ *
5
+ * @description 专门格式化导入的 response 对象,效果: ResponseEntity«List«TraceSettingResponse»» => TraceSettingResponse
6
+ * @export
7
+ * @class HelperFormatImportItem
8
+ * @extends {HelperBase}
9
+ */
10
+ export declare class HelperFormatImportItem extends HelperBase {
11
+ constructor();
12
+ onExecute(param: string): string;
13
+ }
@@ -0,0 +1,30 @@
1
+ import { HelperBase } from "../helper-base.mjs";
2
+ export class HelperFormatImportItem extends HelperBase {
3
+ constructor() {
4
+ super("formatImportItem");
5
+ }
6
+ onExecute(param) {
7
+ if (!param) {
8
+ return "";
9
+ }
10
+ if (param.indexOf("\xAB") > -1) {
11
+ const arr = param.split("\xAB");
12
+ const text = arr[arr.length - 1].split("\xBB")[0];
13
+ let keys = text.split(",");
14
+ keys = keys.map((key) => {
15
+ if (key === "Void") {
16
+ return "void";
17
+ }
18
+ if (key === "int" || key === "long") {
19
+ return "number";
20
+ }
21
+ if (key === "Map") {
22
+ return "object";
23
+ }
24
+ return key;
25
+ });
26
+ return keys.join(",");
27
+ }
28
+ return param;
29
+ }
30
+ }
@@ -0,0 +1,14 @@
1
+ import { IObject } from '../../../interface';
2
+ import { HelperBase } from '../helper-base';
3
+ /**
4
+ * 格式化导入
5
+ *
6
+ * @description 针对后台的 swagger 生成的 js 类型,进行对 js 的类型转换
7
+ * @export
8
+ * @class HelperFormatJsType
9
+ * @extends {HelperBase}
10
+ */
11
+ export declare class HelperFormatJsType extends HelperBase {
12
+ constructor();
13
+ onExecute(param: string, cfg?: IObject): string;
14
+ }
@@ -0,0 +1,34 @@
1
+ import { HelperBase } from "../helper-base.mjs";
2
+ export class HelperFormatJsType extends HelperBase {
3
+ constructor() {
4
+ super("formatJsType");
5
+ }
6
+ onExecute(param, cfg) {
7
+ if (!param) {
8
+ return "unknown";
9
+ }
10
+ if (param === "array") {
11
+ if (cfg) {
12
+ let type = cfg.type || cfg.originalRef;
13
+ if (type) {
14
+ if (type === "integer") {
15
+ type = "number";
16
+ } else if (type.startsWith("Triple\xAB")) {
17
+ type = "unknown";
18
+ }
19
+ } else {
20
+ type = "unknown";
21
+ }
22
+ return type + "[]";
23
+ }
24
+ return "unknown[]";
25
+ }
26
+ if (param === "integer") {
27
+ return "number";
28
+ }
29
+ if (param === "object") {
30
+ return "Record<string, unknown>";
31
+ }
32
+ return param;
33
+ }
34
+ }