wormajs 0.0.1

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 (236) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +49 -0
  3. package/dist/bin/actions.js +245 -0
  4. package/dist/bin/cli.js +27 -0
  5. package/dist/bin/progressRenderer.js +47 -0
  6. package/dist/bin/renderer.js +551 -0
  7. package/dist/bin/theme.js +26 -0
  8. package/dist/config.js +19 -0
  9. package/dist/constant.js +162 -0
  10. package/dist/core/WorkerPool.js +102 -0
  11. package/dist/core/loader/astLoader/generates/array.js +34 -0
  12. package/dist/core/loader/astLoader/generates/enum.js +61 -0
  13. package/dist/core/loader/astLoader/generates/group.js +41 -0
  14. package/dist/core/loader/astLoader/generates/index.js +71 -0
  15. package/dist/core/loader/astLoader/generates/interface.js +59 -0
  16. package/dist/core/loader/astLoader/generates/simple.js +67 -0
  17. package/dist/core/loader/astLoader/generates/tuple.js +54 -0
  18. package/dist/core/loader/astLoader/generates/type.js +2 -0
  19. package/dist/core/loader/astLoader/generates/utils.js +86 -0
  20. package/dist/core/loader/astLoader/helper.js +21 -0
  21. package/dist/core/loader/astLoader/index.js +24 -0
  22. package/dist/core/loader/astLoader/normalize/index.js +70 -0
  23. package/dist/core/loader/astLoader/normalize/normalizer.js +69 -0
  24. package/dist/core/loader/astLoader/normalize/rules/convertTypeArray.js +68 -0
  25. package/dist/core/loader/astLoader/normalize/rules/handleEmptyType.js +8 -0
  26. package/dist/core/loader/astLoader/normalize/rules/inferType.js +43 -0
  27. package/dist/core/loader/astLoader/normalize/rules/mergeAnyOf.js +45 -0
  28. package/dist/core/loader/astLoader/normalize/rules/normalizeCombiningKeywords.js +26 -0
  29. package/dist/core/loader/astLoader/normalize/rules/normalizeEnum.js +38 -0
  30. package/dist/core/loader/astLoader/normalize/rules/normalizeNullType.js +24 -0
  31. package/dist/core/loader/astLoader/normalize/rules/removeRedundantKeywords.js +27 -0
  32. package/dist/core/loader/astLoader/normalize/rules/simplifySingleType.js +8 -0
  33. package/dist/core/loader/astLoader/normalize/rules/validateSchema.js +14 -0
  34. package/dist/core/loader/astLoader/parsers/array.js +28 -0
  35. package/dist/core/loader/astLoader/parsers/enum.js +49 -0
  36. package/dist/core/loader/astLoader/parsers/forward/array.js +12 -0
  37. package/dist/core/loader/astLoader/parsers/forward/enum.js +10 -0
  38. package/dist/core/loader/astLoader/parsers/forward/group.js +12 -0
  39. package/dist/core/loader/astLoader/parsers/forward/index.js +20 -0
  40. package/dist/core/loader/astLoader/parsers/forward/object.js +12 -0
  41. package/dist/core/loader/astLoader/parsers/forward/tuple.js +11 -0
  42. package/dist/core/loader/astLoader/parsers/forward/type.js +2 -0
  43. package/dist/core/loader/astLoader/parsers/group.js +50 -0
  44. package/dist/core/loader/astLoader/parsers/index.js +66 -0
  45. package/dist/core/loader/astLoader/parsers/object.js +44 -0
  46. package/dist/core/loader/astLoader/parsers/reference.js +41 -0
  47. package/dist/core/loader/astLoader/parsers/simple.js +48 -0
  48. package/dist/core/loader/astLoader/parsers/tuple.js +36 -0
  49. package/dist/core/loader/astLoader/parsers/type.js +2 -0
  50. package/dist/core/loader/astLoader/parsers/utils.js +58 -0
  51. package/dist/core/loader/callingCodeLoader/helper.js +183 -0
  52. package/dist/core/loader/callingCodeLoader/index.js +40 -0
  53. package/dist/core/loader/index.js +20 -0
  54. package/dist/core/loader/schemaLoader/index.js +101 -0
  55. package/dist/core/loader/standardLoader/helper.js +142 -0
  56. package/dist/core/loader/standardLoader/index.js +38 -0
  57. package/dist/core/loader/standardLoader/standards.js +105 -0
  58. package/dist/core/parser/index.js +18 -0
  59. package/dist/core/parser/openApiParser/helper.js +165 -0
  60. package/dist/core/parser/openApiParser/index.js +14 -0
  61. package/dist/core/parser/templateParser/helper.js +333 -0
  62. package/dist/core/parser/templateParser/index.js +314 -0
  63. package/dist/core/workerPool/index.js +6 -0
  64. package/dist/core/workerPool/poolManager.js +45 -0
  65. package/dist/core/workerPool/swagger2Worker.js +24 -0
  66. package/dist/core/workerPool/worker.js +61 -0
  67. package/dist/createConfig.js +37 -0
  68. package/dist/defineConfig.js +6 -0
  69. package/dist/functions/getAutoTemplateType.js +37 -0
  70. package/dist/functions/getFrameworkTag.js +18 -0
  71. package/dist/functions/prepareConfig.js +41 -0
  72. package/dist/functions/readWormaRc.js +155 -0
  73. package/dist/functions/wormaJson.js +232 -0
  74. package/dist/generate.js +84 -0
  75. package/dist/helper/PluginDriver.js +98 -0
  76. package/dist/helper/comment.js +88 -0
  77. package/dist/helper/config/ConfigHelper.js +79 -0
  78. package/dist/helper/config/ConfigManager.js +88 -0
  79. package/dist/helper/config/GeneratorHelper.js +343 -0
  80. package/dist/helper/config/index.js +19 -0
  81. package/dist/helper/config/type.js +2 -0
  82. package/dist/helper/config/zType.js +170 -0
  83. package/dist/helper/document/index.js +160 -0
  84. package/dist/helper/index.js +23 -0
  85. package/dist/helper/logger/index.js +76 -0
  86. package/dist/helper/progress.js +66 -0
  87. package/dist/helper/template/index.js +475 -0
  88. package/dist/index.js +33 -0
  89. package/dist/plugins/createPlugin.js +30 -0
  90. package/dist/plugins/index.js +34 -0
  91. package/dist/plugins/presets/aiDoc.js +173 -0
  92. package/dist/plugins/presets/apifox.js +56 -0
  93. package/dist/plugins/presets/filterApi.js +129 -0
  94. package/dist/plugins/presets/importType.js +49 -0
  95. package/dist/plugins/presets/payloadModifier/hepler.js +195 -0
  96. package/dist/plugins/presets/payloadModifier/index.js +122 -0
  97. package/dist/plugins/presets/payloadModifier/type.js +2 -0
  98. package/dist/plugins/presets/platform.js +73 -0
  99. package/dist/plugins/presets/rename.js +209 -0
  100. package/dist/plugins/presets/tagModifier.js +104 -0
  101. package/dist/plugins/presets/utils.js +36 -0
  102. package/dist/readConfig.js +92 -0
  103. package/dist/resolveWorkspaces.js +83 -0
  104. package/dist/template/index.js +180 -0
  105. package/dist/template/presets/ai-doc/SKILL.md.handlebars +29 -0
  106. package/dist/template/presets/ai-doc/references/{tag}/{api}.md.handlebars +54 -0
  107. package/dist/template/presets/alova/common/#index.cjs.handlebars +12 -0
  108. package/dist/template/presets/alova/common/components.d.cts.handlebars +1 -0
  109. package/dist/template/presets/alova/common/helper.cjs.handlebars +13 -0
  110. package/dist/template/presets/alova/common/services/#index.cjs.handlebars +13 -0
  111. package/dist/template/presets/alova/common/services/{tag}.cjs.handlebars +28 -0
  112. package/dist/template/presets/alova/common/services/{tag}.d.cts.handlebars +15 -0
  113. package/dist/template/presets/alova/common/typed.d.cts.handlebars +1 -0
  114. package/dist/template/presets/alova/module/#index.js.handlebars +12 -0
  115. package/dist/template/presets/alova/module/components.d.ts.handlebars +1 -0
  116. package/dist/template/presets/alova/module/helper.js.handlebars +11 -0
  117. package/dist/template/presets/alova/module/services/#index.js.handlebars +9 -0
  118. package/dist/template/presets/alova/module/services/{tag}.d.ts.handlebars +15 -0
  119. package/dist/template/presets/alova/module/services/{tag}.js.handlebars +21 -0
  120. package/dist/template/presets/alova/module/typed.d.ts.handlebars +1 -0
  121. package/dist/template/presets/alova/partials/api-jsdoc.handlebars +44 -0
  122. package/dist/template/presets/alova/partials/build-payload-body.handlebars +22 -0
  123. package/dist/template/presets/alova/partials/comment.handlebars +19 -0
  124. package/dist/template/presets/alova/partials/components-body.handlebars +4 -0
  125. package/dist/template/presets/alova/partials/dts-extra-config.handlebars +8 -0
  126. package/dist/template/presets/alova/partials/dts-fn-declare.handlebars +1 -0
  127. package/dist/template/presets/alova/partials/extract-responded.handlebars +11 -0
  128. package/dist/template/presets/alova/partials/stateshook-import.handlebars +9 -0
  129. package/dist/template/presets/alova/partials/stateshook-option.handlebars +9 -0
  130. package/dist/template/presets/alova/partials/typed-body.handlebars +43 -0
  131. package/dist/template/presets/alova/typescript/#index.ts.handlebars +14 -0
  132. package/dist/template/presets/alova/typescript/components.d.ts.handlebars +1 -0
  133. package/dist/template/presets/alova/typescript/helper.ts.handlebars +9 -0
  134. package/dist/template/presets/alova/typescript/services/#index.ts.handlebars +9 -0
  135. package/dist/template/presets/alova/typescript/services/{tag}.ts.handlebars +35 -0
  136. package/dist/template/presets/alova/typescript/typed.ts.handlebars +1 -0
  137. package/dist/template/presets/alova-globals/common/#index.cjs.handlebars +41 -0
  138. package/dist/template/presets/alova-globals/common/apiDefinitions.cjs.handlebars +12 -0
  139. package/dist/template/presets/alova-globals/common/createApis.cjs.handlebars +48 -0
  140. package/dist/template/presets/alova-globals/common/globals.d.cts.handlebars +2 -0
  141. package/dist/template/presets/alova-globals/module/#index.js.handlebars +2 -0
  142. package/dist/template/presets/alova-globals/module/apiDefinitions.js.handlebars +12 -0
  143. package/dist/template/presets/alova-globals/module/createApis.js.handlebars +44 -0
  144. package/dist/template/presets/alova-globals/module/globals.d.ts.handlebars +2 -0
  145. package/dist/template/presets/alova-globals/partials/comment.handlebars +19 -0
  146. package/dist/template/presets/alova-globals/partials/createApis-proxy-js.handlebars +55 -0
  147. package/dist/template/presets/alova-globals/partials/globals-d-ts.handlebars +148 -0
  148. package/dist/template/presets/alova-globals/partials/index-esm.handlebars +38 -0
  149. package/dist/template/presets/alova-globals/partials/withConfigType-jsdoc.handlebars +22 -0
  150. package/dist/template/presets/alova-globals/typescript/#index.ts.handlebars +2 -0
  151. package/dist/template/presets/alova-globals/typescript/apiDefinitions.ts.handlebars +12 -0
  152. package/dist/template/presets/alova-globals/typescript/createApis.ts.handlebars +99 -0
  153. package/dist/template/presets/alova-globals/typescript/globals.d.ts.handlebars +2 -0
  154. package/dist/template/presets/axios/common/#index.cjs.handlebars +22 -0
  155. package/dist/template/presets/axios/common/components.d.cts.handlebars +1 -0
  156. package/dist/template/presets/axios/common/helper.cjs.handlebars +27 -0
  157. package/dist/template/presets/axios/common/services/#index.cjs.handlebars +13 -0
  158. package/dist/template/presets/axios/common/services/{tag}.cjs.handlebars +28 -0
  159. package/dist/template/presets/axios/common/services/{tag}.d.cts.handlebars +11 -0
  160. package/dist/template/presets/axios/module/#index.js.handlebars +20 -0
  161. package/dist/template/presets/axios/module/components.d.ts.handlebars +1 -0
  162. package/dist/template/presets/axios/module/helper.js.handlebars +25 -0
  163. package/dist/template/presets/axios/module/services/#index.js.handlebars +9 -0
  164. package/dist/template/presets/axios/module/services/{tag}.d.ts.handlebars +11 -0
  165. package/dist/template/presets/axios/module/services/{tag}.js.handlebars +20 -0
  166. package/dist/template/presets/axios/partials/api-jsdoc.handlebars +44 -0
  167. package/dist/template/presets/axios/partials/comment.handlebars +19 -0
  168. package/dist/template/presets/axios/partials/components-body.handlebars +4 -0
  169. package/dist/template/presets/axios/partials/dts-fn-declare.handlebars +1 -0
  170. package/dist/template/presets/axios/partials/dts-types.handlebars +7 -0
  171. package/dist/template/presets/axios/typescript/#index.ts.handlebars +20 -0
  172. package/dist/template/presets/axios/typescript/components.d.ts.handlebars +1 -0
  173. package/dist/template/presets/axios/typescript/helper.ts.handlebars +28 -0
  174. package/dist/template/presets/axios/typescript/services/#index.ts.handlebars +9 -0
  175. package/dist/template/presets/axios/typescript/services/{tag}.ts.handlebars +31 -0
  176. package/dist/template/presets/config/common/worma.config.js.handlebars +9 -0
  177. package/dist/template/presets/config/module/worma.config.js.handlebars +9 -0
  178. package/dist/template/presets/config/partials/generator-content.handlebars +45 -0
  179. package/dist/template/presets/config/typescript/worma.config.ts.handlebars +9 -0
  180. package/dist/template/presets/fetch/common/#index.cjs.handlebars +17 -0
  181. package/dist/template/presets/fetch/common/FetchClient.cjs.handlebars +48 -0
  182. package/dist/template/presets/fetch/common/components.d.cts.handlebars +1 -0
  183. package/dist/template/presets/fetch/common/helper.cjs.handlebars +27 -0
  184. package/dist/template/presets/fetch/common/services/#index.cjs.handlebars +13 -0
  185. package/dist/template/presets/fetch/common/services/{tag}.cjs.handlebars +23 -0
  186. package/dist/template/presets/fetch/common/services/{tag}.d.cts.handlebars +10 -0
  187. package/dist/template/presets/fetch/module/#index.js.handlebars +15 -0
  188. package/dist/template/presets/fetch/module/FetchClient.js.handlebars +46 -0
  189. package/dist/template/presets/fetch/module/components.d.ts.handlebars +1 -0
  190. package/dist/template/presets/fetch/module/helper.js.handlebars +25 -0
  191. package/dist/template/presets/fetch/module/services/#index.js.handlebars +9 -0
  192. package/dist/template/presets/fetch/module/services/{tag}.d.ts.handlebars +10 -0
  193. package/dist/template/presets/fetch/module/services/{tag}.js.handlebars +15 -0
  194. package/dist/template/presets/fetch/partials/api-jsdoc.handlebars +44 -0
  195. package/dist/template/presets/fetch/partials/comment.handlebars +19 -0
  196. package/dist/template/presets/fetch/partials/components-body.handlebars +4 -0
  197. package/dist/template/presets/fetch/partials/dts-fn-declare.handlebars +1 -0
  198. package/dist/template/presets/fetch/partials/dts-types.handlebars +7 -0
  199. package/dist/template/presets/fetch/typescript/#index.ts.handlebars +15 -0
  200. package/dist/template/presets/fetch/typescript/FetchClient.ts.handlebars +59 -0
  201. package/dist/template/presets/fetch/typescript/components.d.ts.handlebars +1 -0
  202. package/dist/template/presets/fetch/typescript/helper.ts.handlebars +28 -0
  203. package/dist/template/presets/fetch/typescript/services/#index.ts.handlebars +9 -0
  204. package/dist/template/presets/fetch/typescript/services/{tag}.ts.handlebars +25 -0
  205. package/dist/template/presets/ky/module/#index.js.handlebars +14 -0
  206. package/dist/template/presets/ky/module/components.d.ts.handlebars +1 -0
  207. package/dist/template/presets/ky/module/helper.js.handlebars +27 -0
  208. package/dist/template/presets/ky/module/services/#index.js.handlebars +9 -0
  209. package/dist/template/presets/ky/module/services/{tag}.d.ts.handlebars +11 -0
  210. package/dist/template/presets/ky/module/services/{tag}.js.handlebars +19 -0
  211. package/dist/template/presets/ky/partials/api-jsdoc.handlebars +44 -0
  212. package/dist/template/presets/ky/partials/comment.handlebars +19 -0
  213. package/dist/template/presets/ky/partials/components-body.handlebars +4 -0
  214. package/dist/template/presets/ky/partials/dts-fn-declare.handlebars +1 -0
  215. package/dist/template/presets/ky/partials/dts-types.handlebars +9 -0
  216. package/dist/template/presets/ky/typescript/#index.ts.handlebars +14 -0
  217. package/dist/template/presets/ky/typescript/components.d.ts.handlebars +1 -0
  218. package/dist/template/presets/ky/typescript/helper.ts.handlebars +30 -0
  219. package/dist/template/presets/ky/typescript/services/#index.ts.handlebars +9 -0
  220. package/dist/template/presets/ky/typescript/services/{tag}.ts.handlebars +30 -0
  221. package/dist/tsconfig.build.tsbuildinfo +1 -0
  222. package/dist/type/api.js +14 -0
  223. package/dist/type/ast.js +24 -0
  224. package/dist/type/base.js +17 -0
  225. package/dist/type/index.js +20 -0
  226. package/dist/type/lib.js +17 -0
  227. package/dist/type/openapi.js +2 -0
  228. package/dist/utils/base.js +212 -0
  229. package/dist/utils/format.js +64 -0
  230. package/dist/utils/index.js +21 -0
  231. package/dist/utils/openapi.js +417 -0
  232. package/dist/utils/readPackageJson.js +35 -0
  233. package/dist/utils/template.js +93 -0
  234. package/package.json +88 -0
  235. package/typings/index.d.ts +512 -0
  236. package/typings/plugins.d.ts +727 -0
@@ -0,0 +1,83 @@
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
+ exports.default = resolveWorkspaces;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const promises_1 = __importDefault(require("node:fs/promises"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const glob_1 = require("glob");
11
+ const js_yaml_1 = __importDefault(require("js-yaml"));
12
+ const utils_1 = require("./utils");
13
+ const readPackageJson_1 = require("./utils/readPackageJson");
14
+ /**
15
+ * Search for all directories containing worma.config configuration files under the monorepo project. It will search for configuration files based on `workspaces` in `package.json` or sub packages defined in `pnpm-workspace.yaml`
16
+ * @param projectPath The project path to search, defaults to `process.cwd()`.
17
+ * @returns An array of relative paths to directories containing worma.config configuration files.
18
+ */
19
+ async function resolveWorkspaces(projectPath = process.cwd()) {
20
+ const resultDirs = [];
21
+ // Check if there is worma.config.js in the root directory
22
+ const rootConfigPath = await (0, utils_1.resolveConfigFile)(projectPath);
23
+ if (rootConfigPath) {
24
+ resultDirs.push(projectPath);
25
+ }
26
+ // Find sub packages based on workspaces in package.json or pnpm-workspace.yaml
27
+ const pnpmWorkspacePathYaml = node_path_1.default.join(projectPath, 'pnpm-workspace.yaml');
28
+ const pnpmWorkspacePathYml = node_path_1.default.join(projectPath, 'pnpm-workspace.yml');
29
+ let workspaces = [];
30
+ // If package.json exists, read workspaces
31
+ const packageJson = await (0, readPackageJson_1.readPackageJson)(projectPath);
32
+ const workspacesField = packageJson?.workspaces;
33
+ if (workspacesField) {
34
+ workspaces = Array.isArray(workspacesField) ? workspacesField : (workspacesField.packages ?? []);
35
+ }
36
+ // If pnpm-workspace.yaml exists, read the path in it
37
+ const pnpmWorkspacePath = (await (0, utils_1.existsPromise)(pnpmWorkspacePathYaml))
38
+ ? pnpmWorkspacePathYaml
39
+ : (await (0, utils_1.existsPromise)(pnpmWorkspacePathYml))
40
+ ? pnpmWorkspacePathYml
41
+ : undefined;
42
+ if (pnpmWorkspacePath) {
43
+ const pnpmConfig = js_yaml_1.default.load(await promises_1.default.readFile(pnpmWorkspacePath, 'utf-8'));
44
+ if (pnpmConfig.packages) {
45
+ workspaces = workspaces.concat(pnpmConfig.packages);
46
+ }
47
+ }
48
+ // Deduplication
49
+ workspaces = [...new Set(workspaces)];
50
+ // Iterate through each sub-package and check if worma.config.js exists
51
+ for (const workspace of workspaces) {
52
+ const workspaceDirs = await globPaths(projectPath, workspace);
53
+ for (const dir of workspaceDirs) {
54
+ const configFile = await (0, utils_1.resolveConfigFile)(dir);
55
+ if (configFile) {
56
+ resultDirs.push(dir);
57
+ }
58
+ }
59
+ }
60
+ return resultDirs;
61
+ }
62
+ /**
63
+ * Parse workspace path
64
+ * @param {string} rootPath root directory
65
+ * @param {string} workspacePattern Path pattern defined by workspace
66
+ * @returns {Promise<string[]>} Parsed path list
67
+ */
68
+ async function globPaths(rootPath, workspacePattern) {
69
+ const resolvedPaths = [];
70
+ const dirs = await (0, glob_1.glob)(workspacePattern, {
71
+ ignore: 'node_modules/**',
72
+ cwd: rootPath,
73
+ fs: {
74
+ ...node_fs_1.default,
75
+ promises: promises_1.default,
76
+ },
77
+ }); // Using the glob module to handle wildcards
78
+ for (const dir of dirs) {
79
+ const absDir = node_path_1.default.resolve(rootPath, dir);
80
+ resolvedPaths.push(absDir);
81
+ }
82
+ return resolvedPaths;
83
+ }
@@ -0,0 +1,180 @@
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
+ exports.getPresetTemplatePath = getPresetTemplatePath;
7
+ exports.registerProcessTypeHelper = registerProcessTypeHelper;
8
+ exports.config = config;
9
+ exports.alovaGlobals = alovaGlobals;
10
+ exports.alova = alova;
11
+ exports.axios = axios;
12
+ exports.fetch = fetch;
13
+ exports.ky = ky;
14
+ const node_path_1 = __importDefault(require("node:path"));
15
+ const constant_1 = require("../constant");
16
+ /**
17
+ * 获取预设模板的完整路径
18
+ */
19
+ function getPresetTemplatePath(presetName) {
20
+ // 预设模板在 src/template/presets 目录中
21
+ // 编译后在 dist/template/presets 目录
22
+ return node_path_1.default.join(__dirname, 'presets', presetName);
23
+ }
24
+ /**
25
+ * Register processType helper on an hbs instance.
26
+ *
27
+ * Scans the type string for every PascalCase identifier that is in componentNames
28
+ * (and not already prefixed with "ComponentTypes.") and prefixes it.
29
+ * Works uniformly for top-level names, generics, object literals, and arrays.
30
+ */
31
+ function registerProcessTypeHelper(hbs) {
32
+ hbs.registerHelper('processType', (_typeStr, _componentNames) => {
33
+ const typeStr = _typeStr;
34
+ const componentNames = _componentNames;
35
+ if (!typeStr || !Array.isArray(componentNames) || componentNames.length === 0) {
36
+ return new hbs.SafeString(typeStr || 'unknown');
37
+ }
38
+ const componentSet = new Set(componentNames);
39
+ const result = typeStr.replace(/(?<!ComponentTypes\.)(\b[A-Z]\w*\b)/g, (match) => {
40
+ return componentSet.has(match) ? `ComponentTypes.${match}` : match;
41
+ });
42
+ return new hbs.SafeString(result);
43
+ });
44
+ }
45
+ // ========== Template Preset Plugins ==========
46
+ /**
47
+ * worma.config 模板预设 - plugin mode
48
+ */
49
+ function config() {
50
+ return {
51
+ name: constant_1.PluginName.TEMPLATE_CONFIG,
52
+ getTemplate() {
53
+ return { path: getPresetTemplatePath(constant_1.PresetTemplateName.CONFIG) };
54
+ },
55
+ beforeCodeGenerate({ data }) {
56
+ data.config = { ...data.config, templateName: 'config' };
57
+ },
58
+ };
59
+ }
60
+ /**
61
+ * globals 模板预设 - plugin mode
62
+ * 全局模板,现有的全局模板,通过全局挂载的方式使用
63
+ */
64
+ function alovaGlobals(opts) {
65
+ return {
66
+ name: constant_1.PluginName.TEMPLATE_ALOVA_GLOBALS,
67
+ getTemplate() {
68
+ return { path: getPresetTemplatePath(constant_1.PresetTemplateName.GLOBALS) };
69
+ },
70
+ beforeCodeGenerate({ data }) {
71
+ const global = opts?.global ?? 'Apis';
72
+ const globalHost = opts?.globalHost ?? 'globalThis';
73
+ // Inject template config into templateData
74
+ data.config = {
75
+ ...data.config,
76
+ templateName: 'alova-globals',
77
+ global,
78
+ globalHost,
79
+ useImportType: opts?.useImportType ?? false,
80
+ };
81
+ // Prefix callingCode with global.tag for full call chain
82
+ // Also compute apiKey for globals-specific identifiers
83
+ for (const api of data.allApis) {
84
+ const fullKey = `${global}.${api.tag}.${api.name}`;
85
+ api.apiKey = fullKey;
86
+ if (api.callingCode) {
87
+ api.callingCode = `${global}.${api.tag}.${api.callingCode}`;
88
+ }
89
+ }
90
+ },
91
+ };
92
+ }
93
+ /**
94
+ * functional 模板预设 - plugin mode
95
+ * 函数式模板,生成函数式API调用,支持tree-shaking,仅支持alova v3
96
+ */
97
+ function alova(opts) {
98
+ return {
99
+ name: constant_1.PluginName.TEMPLATE_ALOVA,
100
+ getTemplate() {
101
+ return { path: getPresetTemplatePath(constant_1.PresetTemplateName.ALOVA) };
102
+ },
103
+ onHandlebarsCreated({ hbs }) {
104
+ registerProcessTypeHelper(hbs);
105
+ },
106
+ beforeCodeGenerate({ data }) {
107
+ data.config = {
108
+ ...data.config,
109
+ templateName: 'alova',
110
+ useImportType: opts?.useImportType ?? false,
111
+ };
112
+ },
113
+ };
114
+ }
115
+ /**
116
+ * axios 模板预设 - plugin mode
117
+ * Axios相关模板
118
+ */
119
+ function axios(opts) {
120
+ return {
121
+ name: constant_1.PluginName.TEMPLATE_AXIOS,
122
+ getTemplate() {
123
+ return { path: getPresetTemplatePath(constant_1.PresetTemplateName.AXIOS) };
124
+ },
125
+ onHandlebarsCreated({ hbs }) {
126
+ registerProcessTypeHelper(hbs);
127
+ },
128
+ beforeCodeGenerate({ data }) {
129
+ data.config = {
130
+ ...data.config,
131
+ templateName: 'axios',
132
+ useImportType: opts?.useImportType ?? false,
133
+ };
134
+ },
135
+ };
136
+ }
137
+ /**
138
+ * fetch 模板预设 - plugin mode
139
+ * Fetch相关模板
140
+ */
141
+ function fetch(opts) {
142
+ return {
143
+ name: constant_1.PluginName.TEMPLATE_FETCH,
144
+ getTemplate() {
145
+ return { path: getPresetTemplatePath(constant_1.PresetTemplateName.FETCH) };
146
+ },
147
+ onHandlebarsCreated({ hbs }) {
148
+ registerProcessTypeHelper(hbs);
149
+ },
150
+ beforeCodeGenerate({ data }) {
151
+ data.config = {
152
+ ...data.config,
153
+ templateName: 'fetch',
154
+ useImportType: opts?.useImportType ?? false,
155
+ };
156
+ },
157
+ };
158
+ }
159
+ /**
160
+ * ky 模板预设 - plugin mode
161
+ * Ky相关模板
162
+ */
163
+ function ky(opts) {
164
+ return {
165
+ name: constant_1.PluginName.TEMPLATE_KY,
166
+ getTemplate() {
167
+ return { path: getPresetTemplatePath(constant_1.PresetTemplateName.KY) };
168
+ },
169
+ onHandlebarsCreated({ hbs }) {
170
+ registerProcessTypeHelper(hbs);
171
+ },
172
+ beforeCodeGenerate({ data }) {
173
+ data.config = {
174
+ ...data.config,
175
+ templateName: 'ky',
176
+ useImportType: opts?.useImportType ?? false,
177
+ };
178
+ },
179
+ };
180
+ }
@@ -0,0 +1,29 @@
1
+ ---
2
+ name: {{{title}}}-api-reference
3
+ description: >-
4
+ API reference documentation for {{{serverName}}} ({{{title}}} v{{{version}}}).
5
+ Contains specifications for all REST API endpoints, including HTTP request methods,
6
+ URL paths, path/query parameters, request body schemas, and response types.
7
+ Use this skill whenever you need to: call {{{serverName}}} backend APIs,
8
+ look up endpoint details and parameter requirements, understand request/response
9
+ data structures, or integrate frontend code with {{{serverName}}} services.
10
+ Key domains covered: {{#each tagedApis}}{{{tagName}}}{{#unless @last}}, {{/unless}}{{/each}}.
11
+ ---
12
+
13
+ > version {{{version}}}
14
+
15
+ ## Overview
16
+
17
+ This skill provides complete API reference documentation for {{{serverName}}}.
18
+ When you need to call any endpoint in this service, consult the corresponding
19
+ API document in the references directory for detailed parameter schemas,
20
+ request/response formats, and usage examples.
21
+
22
+ ## API Directory ({{{serverName}}})
23
+
24
+ {{#each tagedApis}}
25
+ - **{{{tagName}}}**
26
+ {{#each apis}}
27
+ - [{{{summary}}}](./references/{{{../tagName}}}/{{{name}}}.md) `[{{{method}}}] {{{path}}}`
28
+ {{/each}}
29
+ {{/each}}
@@ -0,0 +1,54 @@
1
+ # IMPORTANT: Enforce before generating code (must not be violated)!!!
2
+
3
+ Before executing the code generation task, recite the following usage conventions and ensure compliance when generating.
4
+
5
+ ## Usage Conventions
6
+
7
+ {{#if currentApi.fileLocation}}
8
+ 1. The API defined in this document is located at `{{{currentApi.fileLocation}}}`
9
+ 2. Follow the calling method shown in the example below.
10
+ {{else}}
11
+ 1. Follow the calling method shown in the example below.
12
+ {{/if}}
13
+
14
+ ## API
15
+
16
+ {{{currentApi.summary}}}
17
+
18
+ `[{{{currentApi.method}}}] {{{currentApi.path}}}`
19
+
20
+ {{#if currentApi.pathParametersComment}}
21
+ ## Path Parameters
22
+
23
+ Pass the required parameters in `pathParams`:
24
+
25
+ ```typescript
26
+ {{{stripStarPrefix currentApi.pathParametersComment}}}
27
+ ```
28
+ {{/if}}
29
+
30
+ {{#if currentApi.requestBodyComment}}
31
+ ## Request Body
32
+
33
+ Pass the required request body in `data`:
34
+
35
+ ```typescript
36
+ {{{stripStarPrefix currentApi.requestBodyComment}}}
37
+ ```
38
+ {{/if}}
39
+
40
+ {{#if currentApi.responseComment}}
41
+ ## Response
42
+
43
+ Use the response data as needed:
44
+
45
+ ```typescript
46
+ {{{stripStarPrefix currentApi.responseComment}}}
47
+ ```
48
+ {{/if}}
49
+
50
+ ## Usage Example
51
+
52
+ ```typescript
53
+ {{{currentApi.callingCode}}}
54
+ ```
@@ -0,0 +1,12 @@
1
+ {{> comment}}
2
+ const { createAlova } = require('alova');
3
+ const adapterFetch = require('alova/fetch');
4
+
5
+ const alovaInstance = createAlova({
6
+ baseURL: '{{{baseUrl}}}',
7
+ requestAdapter: adapterFetch(),
8
+ beforeRequest: method => { },
9
+ responded: (res, method) => method.config?.blob ? res.blob() : res.json(),
10
+ });
11
+
12
+ module.exports = { alovaInstance };
@@ -0,0 +1 @@
1
+ {{> components-body}}
@@ -0,0 +1,13 @@
1
+ {{> comment}}
2
+ function buildPayload(url, defaultConfig, apiName, config) {
3
+ {{> build-payload-body}}
4
+ }
5
+
6
+ /**
7
+ * @param {Record<string, any>} _ - tagged api map (unused at runtime)
8
+ * @param {Record<string, any>} configMap - default config per api name
9
+ * @returns {Record<string, any>}
10
+ */
11
+ const setMethodDefaultConfig = (_, configMap) => configMap;
12
+
13
+ module.exports = { buildPayload, setMethodDefaultConfig };
@@ -0,0 +1,13 @@
1
+ {{> comment}}
2
+ const { setMethodDefaultConfig } = require('../helper.cjs');
3
+ {{#each tagedApis}}
4
+ const {{{tagName}}} = require('./{{{tagName}}}.cjs');
5
+ {{/each}}
6
+
7
+ {{#each tagedApis}}
8
+ const {{{tagName}}}DefaultConfig = setMethodDefaultConfig({{{tagName}}}, {});
9
+ {{/each}}
10
+
11
+ {{#each tagedApis}}
12
+ module.exports.{{{tagName}}}DefaultConfig = {{{tagName}}}DefaultConfig;
13
+ {{/each}}
@@ -0,0 +1,28 @@
1
+ {{> comment}}
2
+ const { alovaInstance } = require('../index.cjs');
3
+ const { buildPayload } = require('../helper.cjs');
4
+ const _index = require('./index.cjs');
5
+
6
+ {{#each tagedApis}}
7
+ {{#each apis}}
8
+ {{> api-jsdoc}}
9
+ function {{{name}}}(config) {
10
+ const { url, data, mergedConfig } = buildPayload('{{{path}}}', _index.{{{tag}}}DefaultConfig, {{{name}}}.name, config);
11
+ return alovaInstance.Request({
12
+ ...mergedConfig,
13
+ url,
14
+ data,
15
+ method: '{{method}}',{{#if (eq response "Blob")}}
16
+ blob: true,{{/if}}
17
+ });
18
+ }
19
+
20
+ {{/each}}
21
+ {{/each}}
22
+ module.exports = {
23
+ {{#each tagedApis}}
24
+ {{#each apis}}
25
+ {{{name}}},
26
+ {{/each}}
27
+ {{/each}}
28
+ };
@@ -0,0 +1,15 @@
1
+ import type { Alova2Method, Alova2MethodConfig } from '../typed';
2
+ {{#each tagedApis}}
3
+ import type { {{{tagName}}}DefaultConfig } from '.';
4
+ {{/each}}
5
+ import type * as ComponentTypes from '../components';
6
+
7
+ {{#each tagedApis}}
8
+ {{> extract-responded}}
9
+ {{#each apis}}
10
+ {{> dts-extra-config}}
11
+ {{> api-jsdoc}}
12
+ {{> dts-fn-declare}}
13
+
14
+ {{/each}}
15
+ {{/each}}
@@ -0,0 +1 @@
1
+ {{> typed-body}}
@@ -0,0 +1,12 @@
1
+ {{> comment}}
2
+ import { createAlova } from 'alova';
3
+ import adapterFetch from 'alova/fetch';
4
+ {{> stateshook-import}}
5
+
6
+ export const alovaInstance = createAlova({
7
+ baseURL: '{{{baseUrl}}}',
8
+ {{> stateshook-option}}
9
+ requestAdapter: adapterFetch(),
10
+ beforeRequest: method => { },
11
+ responded: (res, method) => method.config?.blob ? res.blob() : res.json(),
12
+ });
@@ -0,0 +1 @@
1
+ {{> components-body}}
@@ -0,0 +1,11 @@
1
+ {{> comment}}
2
+ export function buildPayload(url, defaultConfig, apiName, config) {
3
+ {{> build-payload-body}}
4
+ }
5
+
6
+ /**
7
+ * @param {Record<string, any>} _ - tagged api map (unused at runtime)
8
+ * @param {Record<string, any>} configMap - default config per api name
9
+ * @returns {Record<string, any>}
10
+ */
11
+ export const setMethodDefaultConfig = (_, configMap) => configMap;
@@ -0,0 +1,9 @@
1
+ {{> comment}}
2
+ import { setMethodDefaultConfig } from '../helper.js';
3
+ {{#each tagedApis}}
4
+ import * as {{{tagName}}} from './{{{tagName}}}.js';
5
+ {{/each}}
6
+
7
+ {{#each tagedApis}}
8
+ export const {{{tagName}}}DefaultConfig = setMethodDefaultConfig({{{tagName}}}, {});
9
+ {{/each}}
@@ -0,0 +1,15 @@
1
+ import type { Alova2Method, Alova2MethodConfig } from '../typed';
2
+ {{#each tagedApis}}
3
+ import type { {{{tagName}}}DefaultConfig } from '.';
4
+ {{/each}}
5
+ import type * as ComponentTypes from '../components';
6
+
7
+ {{#each tagedApis}}
8
+ {{> extract-responded}}
9
+ {{#each apis}}
10
+ {{> dts-extra-config}}
11
+ {{> api-jsdoc}}
12
+ {{> dts-fn-declare}}
13
+
14
+ {{/each}}
15
+ {{/each}}
@@ -0,0 +1,21 @@
1
+ {{> comment}}
2
+ import { alovaInstance } from '../index.js';
3
+ import { buildPayload } from '../helper.js';
4
+ import { {{currentTag.tagName}}DefaultConfig } from './index.js';
5
+
6
+ {{#each tagedApis}}
7
+ {{#each apis}}
8
+ {{> api-jsdoc}}
9
+ export function {{{name}}}(config) {
10
+ const { url, data, mergedConfig } = buildPayload('{{{path}}}', {{{tag}}}DefaultConfig, {{{name}}}.name, config);
11
+ return alovaInstance.Request({
12
+ ...mergedConfig,
13
+ url,
14
+ data,
15
+ method: '{{method}}',{{#if (eq response "Blob")}}
16
+ blob: true,{{/if}}
17
+ });
18
+ }
19
+
20
+ {{/each}}
21
+ {{/each}}
@@ -0,0 +1 @@
1
+ {{> typed-body}}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * ---
3
+ *
4
+ * [{{method}}] {{{summary}}}
5
+ *
6
+ * **path:** {{{path}}}
7
+ *
8
+ {{#if pathParametersComment}}
9
+ * ---
10
+ *
11
+ * **Path Parameters**
12
+ * ```ts
13
+ * type PathParameters = {{{pathParametersComment}}}
14
+ * ```
15
+ *
16
+ {{/if}}
17
+ {{#if queryParametersComment}}
18
+ * ---
19
+ *
20
+ * **Query Parameters**
21
+ * ```ts
22
+ * type QueryParameters = {{{queryParametersComment}}}
23
+ * ```
24
+ *
25
+ {{/if}}
26
+ {{#if requestBodyComment}}
27
+ * ---
28
+ *
29
+ * **RequestBody**
30
+ * ```ts
31
+ * type RequestBody = {{{requestBodyComment}}}
32
+ * ```
33
+ *
34
+ {{/if}}
35
+ {{#if responseComment}}
36
+ * ---
37
+ *
38
+ * **Response**
39
+ * ```ts
40
+ * type Response = {{{responseComment}}}
41
+ * ```
42
+ *
43
+ {{/if}}
44
+ */
@@ -0,0 +1,22 @@
1
+ const mergedConfig = {
2
+ ...defaultConfig[apiName],
3
+ ...config,
4
+ };
5
+ const pathParams = mergedConfig.pathParams;
6
+ const urlReplaced = url.replace(/\{([^}]+)\}/g, (_, key) => {
7
+ return pathParams?.[key] ?? _;
8
+ });
9
+ delete mergedConfig.pathParams;
10
+ let data = mergedConfig.data;
11
+ if (Object.prototype.toString.call(data) === '[object Object]' && typeof FormData !== 'undefined') {
12
+ let hasBlobData = false;
13
+ const formData = new FormData();
14
+ for (const key in data) {
15
+ formData.append(key, data[key]);
16
+ if (data[key] instanceof Blob) {
17
+ hasBlobData = true;
18
+ }
19
+ }
20
+ data = hasBlobData ? formData : data;
21
+ }
22
+ return { url: urlReplaced, data, mergedConfig };
@@ -0,0 +1,19 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * {{title}} - version {{version}}
5
+ *
6
+ * {{description}}
7
+ *
8
+ * OpenAPI version: {{openapi}}
9
+ *
10
+ {{#contact}}
11
+ * Contact: {{#contact.name}}[{{contact.name}}]{{/contact.name}}{{#contact.url}}{{{contact.url}}}{{/contact.url}}{{^contact.url}}{{{contact.email}}}{{/contact.url}}
12
+ {{/contact}}
13
+ *
14
+ * NOTE: This file is auto generated by the alova's vscode plugin.
15
+ *
16
+ * https://alova.js.org/devtools/vscode
17
+ *
18
+ * **Do not edit the file manually.**
19
+ */
@@ -0,0 +1,4 @@
1
+ {{> comment}}
2
+ {{#each components}}
3
+ {{{this}}}
4
+ {{/each}}
@@ -0,0 +1,8 @@
1
+ {{#or pathParameters queryParameters requestBody}}
2
+ type {{{name}}}ExtraConfig = {
3
+ {{#if pathParameters}}pathParams: {{processType pathParameters @root.componentNames}};
4
+ {{/if}}{{#if queryParameters}}params: {{processType queryParameters @root.componentNames}};
5
+ {{/if}}{{#if requestBody}}data: {{processType requestBody @root.componentNames}};
6
+ {{/if}}
7
+ };
8
+ {{/or}}
@@ -0,0 +1 @@
1
+ export declare function {{{name}}}<Config extends Alova2MethodConfig<{{processType response @root.componentNames}}> & {{{name}}}ExtraConfig>(config: Config): Alova2Method<ExtractResponded<Config, '{{{name}}}', {{processType response @root.componentNames}}>>;
@@ -0,0 +1,11 @@
1
+ export type ExtractResponded<
2
+ UserDefinedConfig extends Alova2MethodConfig<any>,
3
+ UnifiedConfigKey extends string,
4
+ Default,
5
+ > = UserDefinedConfig extends { transform: (...args: any[]) => any }
6
+ ? Awaited<ReturnType<UserDefinedConfig['transform']>>
7
+ : UnifiedConfigKey extends keyof typeof {{{tagName}}}DefaultConfig
8
+ ? typeof {{{tagName}}}DefaultConfig[UnifiedConfigKey] extends { transform: (...args: any[]) => any }
9
+ ? Awaited<ReturnType<typeof {{{tagName}}}DefaultConfig[UnifiedConfigKey]['transform']>>
10
+ : Default
11
+ : Default;
@@ -0,0 +1,9 @@
1
+ {{#if (eq framework "vue")}}
2
+ import vueHook from 'alova/vue';
3
+ {{else if (eq framework "react")}}
4
+ import reactHook from 'alova/react';
5
+ {{else if (eq framework "svelte")}}
6
+ import svelteHook from 'alova/svelte';
7
+ {{else if (eq framework "solid")}}
8
+ import solidHook from 'alova/solid';
9
+ {{/if}}
@@ -0,0 +1,9 @@
1
+ {{#if (eq framework "vue")}}
2
+ statesHook: vueHook,
3
+ {{else if (eq framework "react")}}
4
+ statesHook: reactHook,
5
+ {{else if (eq framework "svelte")}}
6
+ statesHook: svelteHook,
7
+ {{else if (eq framework "solid")}}
8
+ statesHook: solidHook,
9
+ {{/if}}