@apimatic/cli 1.1.0-alpha.2 → 1.1.0-alpha.21

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 (269) hide show
  1. package/README.md +257 -101
  2. package/bin/run.js +5 -0
  3. package/lib/actions/action-result.d.ts +8 -0
  4. package/lib/actions/action-result.js +25 -0
  5. package/lib/actions/action-result.js.map +1 -0
  6. package/lib/actions/auth/login.d.ts +12 -0
  7. package/lib/actions/auth/login.js +63 -0
  8. package/lib/actions/auth/login.js.map +1 -0
  9. package/lib/actions/portal/copilot.d.ts +14 -0
  10. package/lib/actions/portal/copilot.js +79 -0
  11. package/lib/actions/portal/copilot.js.map +1 -0
  12. package/lib/actions/portal/generate.d.ts +14 -0
  13. package/lib/actions/portal/generate.js +66 -0
  14. package/lib/actions/portal/generate.js.map +1 -0
  15. package/lib/actions/portal/recipe/new-recipe.d.ts +24 -0
  16. package/lib/actions/portal/recipe/new-recipe.js +250 -0
  17. package/lib/actions/portal/recipe/new-recipe.js.map +1 -0
  18. package/lib/actions/portal/serve.d.ts +14 -0
  19. package/lib/actions/portal/serve.js +24 -0
  20. package/lib/actions/portal/serve.js.map +1 -0
  21. package/lib/actions/portal/toc/new-toc.d.ts +20 -0
  22. package/lib/actions/portal/toc/new-toc.js +133 -0
  23. package/lib/actions/portal/toc/new-toc.js.map +1 -0
  24. package/lib/actions/sdk/generate.d.ts +14 -0
  25. package/lib/actions/sdk/generate.js +72 -0
  26. package/lib/actions/sdk/generate.js.map +1 -0
  27. package/lib/application/portal/recipe/portal-recipe.d.ts +8 -0
  28. package/lib/application/portal/recipe/portal-recipe.js +33 -0
  29. package/lib/application/portal/recipe/portal-recipe.js.map +1 -0
  30. package/lib/application/portal/recipe/recipe-generator.d.ts +16 -0
  31. package/lib/application/portal/recipe/recipe-generator.js +147 -0
  32. package/lib/application/portal/recipe/recipe-generator.js.map +1 -0
  33. package/lib/application/portal/serve/portal-watcher.d.ts +11 -0
  34. package/lib/application/portal/serve/portal-watcher.js +64 -0
  35. package/lib/application/portal/serve/portal-watcher.js.map +1 -0
  36. package/lib/application/portal/serve/serve-handler.d.ts +16 -0
  37. package/lib/application/portal/serve/serve-handler.js +91 -0
  38. package/lib/application/portal/serve/serve-handler.js.map +1 -0
  39. package/lib/application/portal/serve/watcher-handler.d.ts +10 -0
  40. package/lib/application/portal/serve/watcher-handler.js +51 -0
  41. package/lib/application/portal/serve/watcher-handler.js.map +1 -0
  42. package/lib/application/portal/toc/sdl-parser.d.ts +19 -0
  43. package/lib/application/portal/toc/sdl-parser.js +90 -0
  44. package/lib/application/portal/toc/sdl-parser.js.map +1 -0
  45. package/lib/application/portal/toc/toc-content-parser.d.ts +5 -0
  46. package/lib/application/portal/toc/toc-content-parser.js +44 -0
  47. package/lib/application/portal/toc/toc-content-parser.js.map +1 -0
  48. package/lib/application/portal/toc/toc-structure-generator.d.ts +6 -0
  49. package/lib/application/portal/toc/toc-structure-generator.js +84 -0
  50. package/lib/application/portal/toc/toc-structure-generator.js.map +1 -0
  51. package/lib/client-utils/auth-manager.d.ts +8 -3
  52. package/lib/client-utils/auth-manager.js +23 -10
  53. package/lib/client-utils/auth-manager.js.map +1 -0
  54. package/lib/client-utils/sdk-client.d.ts +4 -9
  55. package/lib/client-utils/sdk-client.js +9 -87
  56. package/lib/client-utils/sdk-client.js.map +1 -0
  57. package/lib/commands/api/transform.d.ts +7 -7
  58. package/lib/commands/api/transform.js +46 -51
  59. package/lib/commands/api/transform.js.map +1 -0
  60. package/lib/commands/api/validate.d.ts +4 -4
  61. package/lib/commands/api/validate.js +35 -36
  62. package/lib/commands/api/validate.js.map +1 -0
  63. package/lib/commands/auth/login.d.ts +3 -2
  64. package/lib/commands/auth/login.js +22 -53
  65. package/lib/commands/auth/login.js.map +1 -0
  66. package/lib/commands/auth/logout.d.ts +1 -1
  67. package/lib/commands/auth/logout.js +8 -13
  68. package/lib/commands/auth/logout.js.map +1 -0
  69. package/lib/commands/auth/status.d.ts +1 -1
  70. package/lib/commands/auth/status.js +9 -13
  71. package/lib/commands/auth/status.js.map +1 -0
  72. package/lib/commands/portal/copilot.d.ts +13 -0
  73. package/lib/commands/portal/copilot.js +32 -0
  74. package/lib/commands/portal/copilot.js.map +1 -0
  75. package/lib/commands/portal/generate.d.ts +10 -8
  76. package/lib/commands/portal/generate.js +28 -107
  77. package/lib/commands/portal/generate.js.map +1 -0
  78. package/lib/commands/portal/quickstart.d.ts +10 -0
  79. package/lib/commands/portal/quickstart.js +114 -0
  80. package/lib/commands/portal/quickstart.js.map +1 -0
  81. package/lib/commands/portal/recipe/new.d.ts +10 -0
  82. package/lib/commands/portal/recipe/new.js +38 -0
  83. package/lib/commands/portal/recipe/new.js.map +1 -0
  84. package/lib/commands/portal/serve.d.ts +16 -0
  85. package/lib/commands/portal/serve.js +80 -0
  86. package/lib/commands/portal/serve.js.map +1 -0
  87. package/lib/commands/portal/toc/new.d.ts +14 -0
  88. package/lib/commands/portal/toc/new.js +52 -0
  89. package/lib/commands/portal/toc/new.js.map +1 -0
  90. package/lib/commands/sdk/generate.d.ts +9 -8
  91. package/lib/commands/sdk/generate.js +39 -128
  92. package/lib/commands/sdk/generate.js.map +1 -0
  93. package/lib/config/axios-config.d.ts +2 -0
  94. package/lib/config/axios-config.js +10 -0
  95. package/lib/config/axios-config.js.map +1 -0
  96. package/lib/config/env.d.ts +26 -1
  97. package/lib/config/env.js +27 -4
  98. package/lib/config/env.js.map +1 -0
  99. package/lib/controllers/api/transform.d.ts +1 -1
  100. package/lib/controllers/api/transform.js +23 -22
  101. package/lib/controllers/api/transform.js.map +1 -0
  102. package/lib/controllers/api/validate.d.ts +3 -3
  103. package/lib/controllers/api/validate.js +19 -12
  104. package/lib/controllers/api/validate.js.map +1 -0
  105. package/lib/controllers/portal/quickstart.d.ts +13 -0
  106. package/lib/controllers/portal/quickstart.js +214 -0
  107. package/lib/controllers/portal/quickstart.js.map +1 -0
  108. package/lib/hooks/not-found.d.ts +3 -0
  109. package/lib/hooks/not-found.js +52 -0
  110. package/lib/hooks/not-found.js.map +1 -0
  111. package/lib/hooks/utils.d.ts +5 -0
  112. package/lib/hooks/utils.js +51 -0
  113. package/lib/hooks/utils.js.map +1 -0
  114. package/lib/index.d.ts +1 -1
  115. package/lib/index.js +2 -4
  116. package/lib/index.js.map +1 -0
  117. package/lib/infrastructure/api-client-utils.d.ts +6 -0
  118. package/lib/infrastructure/api-client-utils.js +34 -0
  119. package/lib/infrastructure/api-client-utils.js.map +1 -0
  120. package/lib/infrastructure/api-utils.d.ts +9 -0
  121. package/lib/infrastructure/api-utils.js +33 -0
  122. package/lib/infrastructure/api-utils.js.map +1 -0
  123. package/lib/infrastructure/env-info.d.ts +12 -0
  124. package/lib/infrastructure/env-info.js +58 -0
  125. package/lib/infrastructure/env-info.js.map +1 -0
  126. package/lib/infrastructure/file-service.d.ts +18 -0
  127. package/lib/infrastructure/file-service.js +76 -0
  128. package/lib/infrastructure/file-service.js.map +1 -0
  129. package/lib/infrastructure/launcher-service.d.ts +5 -0
  130. package/lib/infrastructure/launcher-service.js +47 -0
  131. package/lib/infrastructure/launcher-service.js.map +1 -0
  132. package/lib/infrastructure/services/api-service.d.ts +10 -0
  133. package/lib/infrastructure/services/api-service.js +55 -0
  134. package/lib/infrastructure/services/api-service.js.map +1 -0
  135. package/lib/infrastructure/services/auth-service.d.ts +11 -0
  136. package/lib/infrastructure/services/auth-service.js +35 -0
  137. package/lib/infrastructure/services/auth-service.js.map +1 -0
  138. package/lib/infrastructure/services/portal-service.d.ts +23 -0
  139. package/lib/infrastructure/services/portal-service.js +186 -0
  140. package/lib/infrastructure/services/portal-service.js.map +1 -0
  141. package/lib/infrastructure/services/telemetry-service.d.ts +8 -0
  142. package/lib/infrastructure/services/telemetry-service.js +40 -0
  143. package/lib/infrastructure/services/telemetry-service.js.map +1 -0
  144. package/lib/infrastructure/tmp-extensions.d.ts +2 -0
  145. package/lib/infrastructure/tmp-extensions.js +6 -0
  146. package/lib/infrastructure/tmp-extensions.js.map +1 -0
  147. package/lib/infrastructure/zip-service.d.ts +6 -0
  148. package/lib/infrastructure/zip-service.js +39 -0
  149. package/lib/infrastructure/zip-service.js.map +1 -0
  150. package/lib/prompts/auth/login.d.ts +5 -0
  151. package/lib/prompts/auth/login.js +13 -0
  152. package/lib/prompts/auth/login.js.map +1 -0
  153. package/lib/prompts/portal/common/base-prompts.d.ts +7 -0
  154. package/lib/prompts/portal/common/base-prompts.js +19 -0
  155. package/lib/prompts/portal/common/base-prompts.js.map +1 -0
  156. package/lib/prompts/portal/copilot.d.ts +14 -0
  157. package/lib/prompts/portal/copilot.js +71 -0
  158. package/lib/prompts/portal/copilot.js.map +1 -0
  159. package/lib/prompts/portal/generate.d.ts +11 -0
  160. package/lib/prompts/portal/generate.js +42 -0
  161. package/lib/prompts/portal/generate.js.map +1 -0
  162. package/lib/prompts/portal/quickstart.d.ts +30 -0
  163. package/lib/prompts/portal/quickstart.js +240 -0
  164. package/lib/prompts/portal/quickstart.js.map +1 -0
  165. package/lib/prompts/portal/recipe/new-recipe.d.ts +24 -0
  166. package/lib/prompts/portal/recipe/new-recipe.js +203 -0
  167. package/lib/prompts/portal/recipe/new-recipe.js.map +1 -0
  168. package/lib/prompts/portal/serve.d.ts +4 -0
  169. package/lib/prompts/portal/serve.js +14 -0
  170. package/lib/prompts/portal/serve.js.map +1 -0
  171. package/lib/prompts/portal/toc/new-toc.d.ts +11 -0
  172. package/lib/prompts/portal/toc/new-toc.js +39 -0
  173. package/lib/prompts/portal/toc/new-toc.js.map +1 -0
  174. package/lib/prompts/sdk/generate.d.ts +11 -0
  175. package/lib/prompts/sdk/generate.js +42 -0
  176. package/lib/prompts/sdk/generate.js.map +1 -0
  177. package/lib/types/api/account.d.ts +10 -0
  178. package/lib/types/api/account.js +2 -0
  179. package/lib/types/api/account.js.map +1 -0
  180. package/lib/types/api/transform.d.ts +19 -4
  181. package/lib/types/api/transform.js +19 -4
  182. package/lib/types/api/transform.js.map +1 -0
  183. package/lib/types/api/validate.d.ts +3 -3
  184. package/lib/types/api/validate.js +2 -2
  185. package/lib/types/api/validate.js.map +1 -0
  186. package/lib/types/build/build.d.ts +14 -0
  187. package/lib/types/build/build.js +4 -0
  188. package/lib/types/build/build.js.map +1 -0
  189. package/lib/types/build-context.d.ts +13 -0
  190. package/lib/types/build-context.js +30 -0
  191. package/lib/types/build-context.js.map +1 -0
  192. package/lib/types/common/result.d.ts +17 -0
  193. package/lib/types/common/result.js +32 -0
  194. package/lib/types/common/result.js.map +1 -0
  195. package/lib/types/events/domain-event.d.ts +8 -0
  196. package/lib/types/events/domain-event.js +11 -0
  197. package/lib/types/events/domain-event.js.map +1 -0
  198. package/lib/types/events/quickstart-completed.d.ts +7 -0
  199. package/lib/types/events/quickstart-completed.js +10 -0
  200. package/lib/types/events/quickstart-completed.js.map +1 -0
  201. package/lib/types/events/quickstart-initiated.d.ts +7 -0
  202. package/lib/types/events/quickstart-initiated.js +10 -0
  203. package/lib/types/events/quickstart-initiated.js.map +1 -0
  204. package/lib/types/events/recipe-creation-failed.d.ts +5 -0
  205. package/lib/types/events/recipe-creation-failed.js +8 -0
  206. package/lib/types/events/recipe-creation-failed.js.map +1 -0
  207. package/lib/types/events/toc-creation-failed.d.ts +5 -0
  208. package/lib/types/events/toc-creation-failed.js +8 -0
  209. package/lib/types/events/toc-creation-failed.js.map +1 -0
  210. package/lib/types/file/directoryPath.d.ts +7 -0
  211. package/lib/types/file/directoryPath.js +16 -0
  212. package/lib/types/file/directoryPath.js.map +1 -0
  213. package/lib/types/file/fileName.d.ts +5 -0
  214. package/lib/types/file/fileName.js +9 -0
  215. package/lib/types/file/fileName.js.map +1 -0
  216. package/lib/types/file/filePath.d.ts +8 -0
  217. package/lib/types/file/filePath.js +11 -0
  218. package/lib/types/file/filePath.js.map +1 -0
  219. package/lib/types/flags-provider.d.ts +15 -0
  220. package/lib/types/flags-provider.js +34 -0
  221. package/lib/types/flags-provider.js.map +1 -0
  222. package/lib/types/portal/generate.d.ts +13 -9
  223. package/lib/types/portal/generate.js +3 -2
  224. package/lib/types/portal/generate.js.map +1 -0
  225. package/lib/types/portal/quickstart.d.ts +17 -0
  226. package/lib/types/portal/quickstart.js +2 -0
  227. package/lib/types/portal/quickstart.js.map +1 -0
  228. package/lib/types/portal/serve.d.ts +12 -0
  229. package/lib/types/portal/serve.js +2 -0
  230. package/lib/types/portal/serve.js.map +1 -0
  231. package/lib/types/portal-context.d.ts +11 -0
  232. package/lib/types/portal-context.js +28 -0
  233. package/lib/types/portal-context.js.map +1 -0
  234. package/lib/types/recipe/recipe.d.ts +37 -0
  235. package/lib/types/recipe/recipe.js +6 -0
  236. package/lib/types/recipe/recipe.js.map +1 -0
  237. package/lib/types/sdk/generate.d.ts +11 -10
  238. package/lib/types/sdk/generate.js +11 -12
  239. package/lib/types/sdk/generate.js.map +1 -0
  240. package/lib/types/sdk-context.d.ts +13 -0
  241. package/lib/types/sdk-context.js +28 -0
  242. package/lib/types/sdk-context.js.map +1 -0
  243. package/lib/types/sdl/sdl.d.ts +12 -0
  244. package/lib/types/sdl/sdl.js +2 -0
  245. package/lib/types/sdl/sdl.js.map +1 -0
  246. package/lib/types/spec-context.d.ts +7 -0
  247. package/lib/types/spec-context.js +12 -0
  248. package/lib/types/spec-context.js.map +1 -0
  249. package/lib/types/toc/toc.d.ts +31 -0
  250. package/lib/types/toc/toc.js +9 -0
  251. package/lib/types/toc/toc.js.map +1 -0
  252. package/lib/types/utils.d.ts +3 -3
  253. package/lib/types/utils.js +2 -2
  254. package/lib/types/utils.js.map +1 -0
  255. package/lib/utils/utils.d.ts +16 -7
  256. package/lib/utils/utils.js +142 -86
  257. package/lib/utils/utils.js.map +1 -0
  258. package/lib/validators/common/directoryValidator.d.ts +5 -0
  259. package/lib/validators/common/directoryValidator.js +22 -0
  260. package/lib/validators/common/directoryValidator.js.map +1 -0
  261. package/lib/validators/portal/serve-validator.d.ts +6 -0
  262. package/lib/validators/portal/serve-validator.js +15 -0
  263. package/lib/validators/portal/serve-validator.js.map +1 -0
  264. package/package.json +100 -43
  265. package/bin/run +0 -5
  266. package/lib/controllers/portal/generate.d.ts +0 -2
  267. package/lib/controllers/portal/generate.js +0 -49
  268. package/lib/controllers/sdk/generate.d.ts +0 -4
  269. package/lib/controllers/sdk/generate.js +0 -64
@@ -0,0 +1,133 @@
1
+ import * as path from "path";
2
+ import fsExtra from "fs-extra";
3
+ import { PortalNewTocPrompts } from "../../../prompts/portal/toc/new-toc.js";
4
+ import { Result } from "../../../types/common/result.js";
5
+ import { getMessageInRedColor } from "../../../utils/utils.js";
6
+ import { SdlParser } from "../../../application/portal/toc/sdl-parser.js";
7
+ import { TocStructureGenerator } from "../../../application/portal/toc/toc-structure-generator.js";
8
+ import { TocContentParser } from "../../../application/portal/toc/toc-content-parser.js";
9
+ import { PortalService } from "../../../infrastructure/services/portal-service.js";
10
+ import { FilePath } from "../../../types/file/filePath.js";
11
+ import { FileName } from "../../../types/file/fileName.js";
12
+ import { BuildContext } from "../../../types/build-context.js";
13
+ export class PortalNewTocAction {
14
+ constructor() {
15
+ this.DEFAULT_TOC_FILENAME = "toc.yml";
16
+ this.APIMATIC_BUILD_FILENAME = "APIMATIC-BUILD.json";
17
+ this.prompts = new PortalNewTocPrompts();
18
+ this.sdlParser = new SdlParser(new PortalService());
19
+ this.tocGenerator = new TocStructureGenerator();
20
+ this.contentParser = new TocContentParser();
21
+ }
22
+ async createToc(buildDirectory, configDir, commandName, tocDirectory, force = false, expandEndpoints = false, expandModels = false) {
23
+ try {
24
+ const tocDir = await this.getDestinationPath(buildDirectory, tocDirectory);
25
+ const tocPath = new FilePath(tocDir, new FileName(this.DEFAULT_TOC_FILENAME));
26
+ const tocCheckResult = await this.handleExistingToc(tocPath, force);
27
+ if (!tocCheckResult.isSuccess()) {
28
+ return Result.cancelled(tocCheckResult.value);
29
+ }
30
+ const { endpointGroups, models } = await this.extractSdlComponents(buildDirectory, configDir, commandName, expandEndpoints, expandModels);
31
+ const contentGroups = await this.extractContentGroups(buildDirectory);
32
+ const toc = this.tocGenerator.createTocStructure(endpointGroups, models, expandEndpoints, expandModels, contentGroups);
33
+ const yamlString = this.tocGenerator.transformToYaml(toc);
34
+ await this.writeToc(tocPath.toString(), yamlString, "utf8");
35
+ this.prompts.displayOutroMessage(tocPath);
36
+ return Result.success(tocPath.toString());
37
+ }
38
+ catch (error) {
39
+ this.prompts.logError(getMessageInRedColor(`${error.message}`));
40
+ return Result.failure(`An unexpected error occurred while generating the TOC file.`);
41
+ }
42
+ }
43
+ async writeToc(path, content, encoding) {
44
+ await fsExtra.ensureFile(path);
45
+ await fsExtra.writeFile(path, content, encoding);
46
+ }
47
+ async handleExistingToc(tocPath, force) {
48
+ const shouldContinue = await this.checkExistingToc(tocPath, force);
49
+ if (!shouldContinue) {
50
+ return Result.cancelled("Operation was cancelled by the user.");
51
+ }
52
+ return Result.success("TOC check passed.");
53
+ }
54
+ async extractSdlComponents(buildDirectory, configDir, commandName, expandEndpoints, expandModels) {
55
+ if (!expandEndpoints && !expandModels) {
56
+ return { endpointGroups: new Map(), models: [] };
57
+ }
58
+ this.prompts.startProgressIndicatorWithMessage("Extracting endpoints and/or models from the API specification...");
59
+ const specFolderPath = await this.getSpecFolderPath(buildDirectory);
60
+ if (!(await fsExtra.pathExists(specFolderPath))) {
61
+ this.prompts.stopProgressIndicatorWithMessage(`⚠️ Could not find the specification folder at: ${specFolderPath}`);
62
+ this.prompts.displayInfo("Falling back to default TOC structure without expanded endpoints or models...");
63
+ return { endpointGroups: new Map(), models: [] };
64
+ }
65
+ const sdlResult = await this.sdlParser.getTocComponentsFromSdl(specFolderPath, configDir, commandName);
66
+ if (!sdlResult.isSuccess()) {
67
+ this.prompts.stopProgressIndicatorWithMessage(`⚠️ ${sdlResult.error}`);
68
+ this.prompts.displayInfo("Falling back to default TOC structure without expanded endpoints or models...");
69
+ return { endpointGroups: new Map(), models: [] };
70
+ }
71
+ this.prompts.stopProgressIndicatorWithMessage("Successfully extracted endpoints and/or models from the specification.");
72
+ return sdlResult.value;
73
+ }
74
+ async extractContentGroups(buildDirectory) {
75
+ const contentFolderPath = await this.getContentFolderPath(buildDirectory);
76
+ if (!(await fsExtra.pathExists(contentFolderPath.toString()))) {
77
+ this.prompts.displayInfo(`⚠️ Could not locate the content folder at: ${contentFolderPath}`);
78
+ this.prompts.displayInfo("Skipping custom content addition in TOC...");
79
+ return [];
80
+ }
81
+ return await this.contentParser.parseContentFolder(contentFolderPath.toString(), contentFolderPath.toString());
82
+ }
83
+ async getDestinationPath(buildDirectory, providedTocDirectory) {
84
+ if (providedTocDirectory === undefined) {
85
+ const inferredDestination = await this.getContentFolderPath(buildDirectory);
86
+ return inferredDestination;
87
+ }
88
+ return providedTocDirectory;
89
+ }
90
+ async checkExistingToc(tocPath, force) {
91
+ if ((await fsExtra.pathExists(tocPath.toString())) && !force) {
92
+ return await this.prompts.overwriteExistingTocPrompt(tocPath);
93
+ }
94
+ return true;
95
+ }
96
+ async getContentFolderPath(buildDirectory) {
97
+ var _a;
98
+ const buildContext = new BuildContext(buildDirectory);
99
+ const defaultContentFolder = buildDirectory.join("content");
100
+ if (!(await buildContext.validate())) {
101
+ return defaultContentFolder;
102
+ }
103
+ try {
104
+ const buildConfig = await buildContext.getBuildFileContents();
105
+ if (((_a = buildConfig.generatePortal) === null || _a === void 0 ? void 0 : _a.contentFolder) == null) {
106
+ return defaultContentFolder;
107
+ }
108
+ return buildDirectory.join(buildConfig.generatePortal.contentFolder).join("content");
109
+ }
110
+ catch (_b) {
111
+ return defaultContentFolder;
112
+ }
113
+ }
114
+ async getSpecFolderPath(buildDirectory) {
115
+ var _a;
116
+ const buildFilePath = path.join(buildDirectory.toString(), this.APIMATIC_BUILD_FILENAME);
117
+ const defaultSpecFolder = path.join(buildDirectory.toString(), "spec");
118
+ if (!(await fsExtra.pathExists(buildFilePath))) {
119
+ return defaultSpecFolder;
120
+ }
121
+ try {
122
+ const buildConfig = await fsExtra.readJson(buildFilePath, "utf8");
123
+ if (((_a = buildConfig.generatePortal) === null || _a === void 0 ? void 0 : _a.apiSpecPath) == null) {
124
+ return defaultSpecFolder;
125
+ }
126
+ return path.join(buildDirectory.toString(), buildConfig.generatePortal.apiSpecPath);
127
+ }
128
+ catch (_b) {
129
+ return defaultSpecFolder;
130
+ }
131
+ }
132
+ }
133
+ //# sourceMappingURL=new-toc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new-toc.js","sourceRoot":"","sources":["../../../../src/actions/portal/toc/new-toc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4DAA4D,CAAC;AACnG,OAAO,EAAE,gBAAgB,EAAE,MAAM,uDAAuD,CAAC;AAEzF,OAAO,EAAE,aAAa,EAAE,MAAM,oDAAoD,CAAC;AAEnF,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,MAAM,OAAO,kBAAkB;IAQ7B;QAHiB,yBAAoB,GAAW,SAAkB,CAAC;QAClD,4BAAuB,GAAW,qBAA8B,CAAC;QAGhF,IAAI,CAAC,OAAO,GAAG,IAAI,mBAAmB,EAAE,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAqB,EAAE,CAAC;QAChD,I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,IAAI,CAAC,SAAS,CAAC,CAAC;QACvF,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,oBAAoB,CAAC;QAC9B,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAAC,cAA6B;;QAC3D,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;QACzF,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAC;QAEvE,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC;YAC/C,OAAO,iBAAiB,CAAC;QAC3B,CAAC;QAED,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;YAElE,IAAI,CAAA,MAAA,WAAW,CAAC,cAAc,0CAAE,WAAW,KAAI,IAAI,EAAE,CAAC;gBACpD,OAAO,iBAAiB,CAAC;YAC3B,CAAC;YACD,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,WAAW,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QACtF,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,iBAAiB,CAAC;QAC3B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
2
+ import { ActionResult } from "../action-result.js";
3
+ import { LanguagePlatform } from "../../types/sdk/generate.js";
4
+ export declare class GenerateAction {
5
+ private readonly prompts;
6
+ private readonly zipArchiver;
7
+ private readonly fileService;
8
+ private readonly portalService;
9
+ private readonly configDir;
10
+ private readonly authKey;
11
+ constructor(configDir: DirectoryPath, authKey?: string | null);
12
+ readonly execute: (specDirectory: DirectoryPath, sdkDirectory: DirectoryPath, platform: LanguagePlatform, commandName: string, force: boolean, zipSdk: boolean) => Promise<ActionResult>;
13
+ private convertSimplePlatformToPlatform;
14
+ }
@@ -0,0 +1,72 @@
1
+ import { ZipService } from "../../infrastructure/zip-service.js";
2
+ import { FileService } from "../../infrastructure/file-service.js";
3
+ import { PortalService } from "../../infrastructure/services/portal-service.js";
4
+ import { FilePath } from "../../types/file/filePath.js";
5
+ import { FileName } from "../../types/file/fileName.js";
6
+ import { ActionResult } from "../action-result.js";
7
+ import { withDirPath } from "../../infrastructure/tmp-extensions.js";
8
+ import { SdkContext } from "../../types/sdk-context.js";
9
+ import { Platforms } from "@apimatic/sdk";
10
+ import { SpecContext } from "../../types/spec-context.js";
11
+ import { SdkGeneratePrompts } from "../../prompts/sdk/generate.js";
12
+ import { LanguagePlatform } from "../../types/sdk/generate.js";
13
+ export class GenerateAction {
14
+ constructor(configDir, authKey = null) {
15
+ this.prompts = new SdkGeneratePrompts();
16
+ this.zipArchiver = new ZipService();
17
+ this.fileService = new FileService();
18
+ this.portalService = new PortalService();
19
+ this.execute = async (specDirectory, sdkDirectory, platform, commandName, force, zipSdk) => {
20
+ if (specDirectory.isEqual(sdkDirectory)) {
21
+ return ActionResult.error(`The spec directory and sdk directory cannot be the same: "${specDirectory}"`);
22
+ }
23
+ const specContext = new SpecContext(specDirectory);
24
+ if (!(await specContext.validate())) {
25
+ return ActionResult.error(`Unable to locate a valid "src" directory. Navigate to the directory containing your APIMatic Portal source or set up a new project by running apimatic portal:quickstart.`);
26
+ }
27
+ const sdkContext = new SdkContext(sdkDirectory, platform);
28
+ if (!force && (await sdkContext.exists()) && !(await this.prompts.overwriteSdk(sdkDirectory))) {
29
+ return ActionResult.error("Please enter a different destination folder or remove the existing files and try again.");
30
+ }
31
+ return await withDirPath(async (tempDirectory) => {
32
+ this.prompts.displaySdkGenerationMessage();
33
+ const specZipPath = new FilePath(tempDirectory, new FileName("spec.zip"));
34
+ await this.zipArchiver.archive(specDirectory, specZipPath);
35
+ const sdkPlatform = this.convertSimplePlatformToPlatform(platform);
36
+ const response = await this.portalService.generateSdk(specZipPath, sdkPlatform, this.configDir, commandName, this.authKey);
37
+ if (!response.isSuccess()) {
38
+ this.prompts.displaySdkGenerationErrorMessage();
39
+ return ActionResult.error(response.error);
40
+ }
41
+ const tempSdkFilePath = new FilePath(tempDirectory, new FileName("sdk.zip"));
42
+ await this.fileService.writeFile(tempSdkFilePath, response.value);
43
+ await sdkContext.save(tempSdkFilePath, zipSdk);
44
+ this.prompts.displaySdkGenerationSuccessMessage();
45
+ return ActionResult.success();
46
+ });
47
+ };
48
+ this.configDir = configDir;
49
+ this.authKey = authKey;
50
+ }
51
+ convertSimplePlatformToPlatform(languagePlatform) {
52
+ switch (languagePlatform) {
53
+ case LanguagePlatform.CSHARP:
54
+ return Platforms.CsNetStandardLib;
55
+ case LanguagePlatform.JAVA:
56
+ return Platforms.JavaEclipseJreLib;
57
+ case LanguagePlatform.PHP:
58
+ return Platforms.PhpGenericLibV2;
59
+ case LanguagePlatform.PYTHON:
60
+ return Platforms.PythonGenericLib;
61
+ case LanguagePlatform.RUBY:
62
+ return Platforms.RubyGenericLib;
63
+ case LanguagePlatform.TYPESCRIPT:
64
+ return Platforms.TsGenericLib;
65
+ case LanguagePlatform.GO:
66
+ return Platforms.GoGenericLib;
67
+ default:
68
+ throw new Error(`Unknown LanguagePlatform: ${languagePlatform}`);
69
+ }
70
+ }
71
+ }
72
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/actions/sdk/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,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E,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAlDA,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAkDO,+BAA+B,CAAC,gBAAkC;QACxE,QAAQ,gBAAgB,EAAE,CAAC;YACzB,KAAK,gBAAgB,CAAC,MAAM;gBAC1B,OAAO,SAAS,CAAC,gBAAgB,CAAC;YACpC,KAAK,gBAAgB,CAAC,IAAI;gBACxB,OAAO,SAAS,CAAC,iBAAiB,CAAC;YACrC,KAAK,gBAAgB,CAAC,GAAG;gBACvB,OAAO,SAAS,CAAC,eAAe,CAAC;YACnC,KAAK,gBAAgB,CAAC,MAAM;gBAC1B,OAAO,SAAS,CAAC,gBAAgB,CAAC;YACpC,KAAK,gBAAgB,CAAC,IAAI;gBACxB,OAAO,SAAS,CAAC,cAAc,CAAC;YAClC,KAAK,gBAAgB,CAAC,UAAU;gBAC9B,OAAO,SAAS,CAAC,YAAY,CAAC;YAChC,KAAK,gBAAgB,CAAC,EAAE;gBACtB,OAAO,SAAS,CAAC,YAAY,CAAC;YAChC;gBACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,gBAAgB,EAAE,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ import { SerializableRecipe } from "../../../types/recipe/recipe.js";
2
+ export declare class PortalRecipe {
3
+ private readonly recipe;
4
+ constructor(name: string);
5
+ addContentStep(key: string, name: string, content: string): this;
6
+ addEndpointStep(key: string, name: string, description: string, endpointPermalink: string): this;
7
+ toSerializableRecipe(): SerializableRecipe;
8
+ }
@@ -0,0 +1,33 @@
1
+ export class PortalRecipe {
2
+ constructor(name) {
3
+ this.recipe = {
4
+ name,
5
+ steps: []
6
+ };
7
+ }
8
+ addContentStep(key, name, content) {
9
+ this.recipe.steps.push({
10
+ key,
11
+ name,
12
+ type: 'content',
13
+ config: { content }
14
+ });
15
+ return this;
16
+ }
17
+ addEndpointStep(key, name, description, endpointPermalink) {
18
+ this.recipe.steps.push({
19
+ key,
20
+ name,
21
+ type: 'endpoint',
22
+ config: {
23
+ description,
24
+ endpointPermalink,
25
+ }
26
+ });
27
+ return this;
28
+ }
29
+ toSerializableRecipe() {
30
+ return this.recipe;
31
+ }
32
+ }
33
+ //# sourceMappingURL=portal-recipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-recipe.js","sourceRoot":"","sources":["../../../../src/application/portal/recipe/portal-recipe.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,YAAY;IAGvB,YAAY,IAAY;QACtB,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI;YACJ,KAAK,EAAE,EAAE;SACV,CAAC;IACJ,CAAC;IAED,cAAc,CAAC,GAAW,EAAE,IAAY,EAAE,OAAe;QACvD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;YACrB,GAAG;YACH,IAAI;YACJ,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE,OAAO,EAAE;SACpB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,eAAe,CACb,GAAW,EACX,IAAY,EACZ,WAAmB,EACnB,iBAAyB;QAEzB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;YACrB,GAAG;YACH,IAAI;YACJ,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE;gBACN,WAAW;gBACX,iBAAiB;aAClB;SACF,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import { SerializableRecipe } from "../../../types/recipe/recipe.js";
2
+ export declare class PortalRecipeGenerator {
3
+ createRecipe(recipe: SerializableRecipe, buildConfig: any, tocFileContent: any, tocFilePath: string, recipeName: string, recipeFileName: string, buildConfigFilePath: string, contentFolderPath: string): Promise<void>;
4
+ private addRecipeToToc;
5
+ private registerRecipeInBuildConfigFile;
6
+ private writeRecipesConfigToBuildConfigFile;
7
+ private createMarkdownFile;
8
+ private createScriptFromRecipe;
9
+ private saveGeneratedRecipeScriptToBuildDirectory;
10
+ private generateVerifyFunction;
11
+ private addContentStepToScript;
12
+ private addEndpointStepToScript;
13
+ private getMarkdownFileContent;
14
+ private formatScript;
15
+ private toPascalCase;
16
+ }
@@ -0,0 +1,147 @@
1
+ import * as path from "path";
2
+ import fs from "fs";
3
+ import prettier from "prettier";
4
+ import { stringify } from "yaml";
5
+ export class PortalRecipeGenerator {
6
+ //TODO: Replace tocFileContent any type with concrete type.
7
+ async createRecipe(recipe, buildConfig, tocFileContent, tocFilePath, recipeName, recipeFileName, buildConfigFilePath, contentFolderPath) {
8
+ await this.addRecipeToToc(tocFileContent, tocFilePath, recipeName, recipeFileName);
9
+ await this.registerRecipeInBuildConfigFile(buildConfig, recipeName, recipeFileName, buildConfigFilePath);
10
+ await this.createMarkdownFile(recipeFileName, contentFolderPath);
11
+ const generatedRecipeScript = await this.createScriptFromRecipe(recipe);
12
+ const generatedRecipeScriptsDirectoryPath = path.join(contentFolderPath, "static", "scripts", "recipes");
13
+ await this.saveGeneratedRecipeScriptToBuildDirectory(generatedRecipeScript, generatedRecipeScriptsDirectoryPath, recipeFileName);
14
+ }
15
+ async addRecipeToToc(tocData, tocFilePath, recipeName, recipeFileName) {
16
+ let toc = tocData.toc;
17
+ let apiRecipesGroup = toc.find((item) => item.group === "API Recipes");
18
+ if (!apiRecipesGroup) {
19
+ // If the group doesn't exist, create and insert it after the last group
20
+ apiRecipesGroup = {
21
+ group: "API Recipes",
22
+ items: []
23
+ };
24
+ // Insert after the last group section, before any generate sections
25
+ let lastGroupIdx = -1;
26
+ for (let i = 0; i < toc.length; i++) {
27
+ if (toc[i].group)
28
+ lastGroupIdx = i;
29
+ }
30
+ toc.splice(lastGroupIdx + 1, 0, apiRecipesGroup);
31
+ }
32
+ // Only add the recipe if it doesn't already exist
33
+ const existingRecipe = apiRecipesGroup.items.find((item) => item.page === recipeName || item.file === `recipes/${recipeFileName}.md`);
34
+ if (!existingRecipe) {
35
+ apiRecipesGroup.items.push({
36
+ page: recipeName,
37
+ file: `recipes/${recipeFileName}.md`
38
+ });
39
+ await fs.promises.writeFile(tocFilePath, stringify(tocData));
40
+ }
41
+ }
42
+ async registerRecipeInBuildConfigFile(buildConfig, recipeName, recipeFileName, buildConfigFilePath) {
43
+ if (!buildConfig.recipes) {
44
+ buildConfig.recipes = {};
45
+ }
46
+ const recipesConfig = buildConfig.recipes;
47
+ if (!recipesConfig.workflows) {
48
+ recipesConfig.workflows = [];
49
+ }
50
+ const existingIndex = recipesConfig.workflows.findIndex((workflow) => workflow.permalink === `page:recipes/${recipeFileName}`);
51
+ const newWorkflow = {
52
+ name: recipeName,
53
+ permalink: `page:recipes/${recipeFileName}`,
54
+ functionName: this.toPascalCase(recipeName),
55
+ scriptPath: `./static/scripts/recipes/${recipeFileName}.js`
56
+ };
57
+ if (existingIndex !== -1) {
58
+ // Replace the existing workflow
59
+ recipesConfig.workflows[existingIndex] = newWorkflow;
60
+ }
61
+ else {
62
+ // Add as new workflow
63
+ recipesConfig.workflows.push(newWorkflow);
64
+ }
65
+ await this.writeRecipesConfigToBuildConfigFile(recipesConfig, buildConfigFilePath);
66
+ }
67
+ async writeRecipesConfigToBuildConfigFile(recipesConfig, buildConfigFilePath) {
68
+ const fileData = await fs.promises.readFile(buildConfigFilePath, "utf-8");
69
+ const buildConfig = JSON.parse(fileData);
70
+ buildConfig.recipes = recipesConfig;
71
+ await fs.promises.writeFile(buildConfigFilePath, JSON.stringify(buildConfig, null, 2));
72
+ }
73
+ async createMarkdownFile(recipeFileName, contentFolder) {
74
+ const directory = path.join(contentFolder, "content", "recipes");
75
+ const markdownFileContent = this.getMarkdownFileContent();
76
+ fs.mkdirSync(directory, { recursive: true });
77
+ fs.writeFileSync(`${directory}/${recipeFileName}.md`, markdownFileContent);
78
+ }
79
+ async createScriptFromRecipe(recipe) {
80
+ let script = `export default function ${this.toPascalCase(recipe.name)}(workflowCtx, portal) {`;
81
+ script += "return {";
82
+ recipe.steps.forEach((step, index) => {
83
+ script += `"${step.key}": {`;
84
+ script += `name: "${step.name}",`;
85
+ script += "stepCallback: async () => {";
86
+ if (step.type === "content") {
87
+ script += this.addContentStepToScript(step.config);
88
+ }
89
+ else if (step.type === "endpoint") {
90
+ script += this.addEndpointStepToScript(step.config);
91
+ }
92
+ script += "},";
93
+ script += "}";
94
+ if (index < recipe.steps.length - 1) {
95
+ script += ",";
96
+ }
97
+ });
98
+ script += "};";
99
+ script += "}";
100
+ return script;
101
+ }
102
+ async saveGeneratedRecipeScriptToBuildDirectory(generatedRecipeScript, generatedRecipeScriptsDirectoryPath, recipeFileName, format = false) {
103
+ if (format) {
104
+ generatedRecipeScript = await this.formatScript(generatedRecipeScript);
105
+ }
106
+ fs.mkdirSync(generatedRecipeScriptsDirectoryPath, { recursive: true });
107
+ await fs.promises.writeFile(`${generatedRecipeScriptsDirectoryPath}/${recipeFileName}.js`, generatedRecipeScript, "utf8");
108
+ }
109
+ generateVerifyFunction() {
110
+ return `if (response.StatusCode == 200) { return true; } else { setError("API Call wasn't able to get a valid response. Please try again."); return false; }`;
111
+ }
112
+ addContentStepToScript(contentConfig) {
113
+ return `return workflowCtx.showContent(${JSON.stringify(contentConfig.content)});`;
114
+ }
115
+ addEndpointStepToScript(endpointConfig) {
116
+ let script = "return workflowCtx.showEndpoint({";
117
+ if (endpointConfig.description !== "") {
118
+ script += `description: ${JSON.stringify(endpointConfig.description)},`;
119
+ }
120
+ script += `endpointPermalink: "${endpointConfig.endpointPermalink}",`;
121
+ script += "verify: (response, setError) => {";
122
+ script += this.generateVerifyFunction();
123
+ script += "},";
124
+ script += "});";
125
+ return script;
126
+ }
127
+ getMarkdownFileContent() {
128
+ return `# This is a Guided Walkthrough File
129
+ This is the starter content`;
130
+ }
131
+ async formatScript(code) {
132
+ return prettier.format(code, {
133
+ parser: "babel",
134
+ semi: true,
135
+ singleQuote: false,
136
+ tabWidth: 2,
137
+ trailingComma: "es5"
138
+ });
139
+ }
140
+ toPascalCase(str) {
141
+ return str
142
+ .split(" ")
143
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
144
+ .join("");
145
+ }
146
+ }
147
+ //# sourceMappingURL=recipe-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recipe-generator.js","sourceRoot":"","sources":["../../../../src/application/portal/recipe/recipe-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,MAAM,OAAO,qBAAqB;IAChC,2DAA2D;IACpD,KAAK,CAAC,YAAY,CACvB,MAA0B,EAC1B,WAAgB,EAChB,cAAmB,EACnB,WAAmB,EACnB,UAAkB,EAClB,cAAsB,EACtB,mBAA2B,EAC3B,iBAAyB;QAEzB,MAAM,IAAI,CAAC,cAAc,CAAC,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;QACnF,MAAM,IAAI,CAAC,+BAA+B,CAAC,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,mBAAmB,CAAC,CAAC;QACzG,MAAM,IAAI,CAAC,kBAAkB,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;QAEjE,MAAM,qBAAqB,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QACxE,MAAM,mCAAmC,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QACzG,MAAM,IAAI,CAAC,yCAAyC,CAClD,qBAAqB,EACrB,mCAAmC,EACnC,cAAc,CACf,CAAC;IACJ,CAAC;I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CAAC;QACxC,MAAM,IAAI,IAAI,CAAC;QACf,MAAM,IAAI,KAAK,CAAC;QAChB,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,sBAAsB;QAC5B,OAAO;4BACiB,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,YAAY,CAAC,IAAY;QACrC,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE;YAC3B,MAAM,EAAE,OAAO;YACf,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,KAAK;YAClB,QAAQ,EAAE,CAAC;YACX,aAAa,EAAE,KAAK;SACrB,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,GAAW;QAC9B,OAAO,GAAG;aACP,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;aACzE,IAAI,CAAC,EAAE,CAAC,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import chokidar from "chokidar";
2
+ import { ServePaths } from "../../../types/portal/serve.js";
3
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
4
+ import { ActionResult } from "../../../actions/action-result.js";
5
+ export declare class PortalWatcher {
6
+ private watcherHandler;
7
+ constructor();
8
+ watchAndRegeneratePortalOnChange(paths: ServePaths, commandName: string, generatePortal: (buildDirectory: DirectoryPath, portalDirectory: DirectoryPath, commandName: string, force: boolean, zipPortal: boolean) => Promise<ActionResult>): Promise<chokidar.FSWatcher>;
9
+ cancelPendingOperations(): void;
10
+ protected handleFileChange(paths: ServePaths, eventQueue: Map<string, string>, eventId: string, commandName: string, generatePortal: (buildDirectory: DirectoryPath, portalDirectory: DirectoryPath, commandName: string, force: boolean, zipPortal: boolean) => Promise<ActionResult>): Promise<void>;
11
+ }
@@ -0,0 +1,64 @@
1
+ import chokidar from "chokidar";
2
+ import crypto from "crypto";
3
+ import console from "console";
4
+ import { Mutex } from "async-mutex";
5
+ import { WatcherHandler } from "./watcher-handler.js";
6
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
7
+ export class PortalWatcher {
8
+ constructor() {
9
+ this.watcherHandler = new WatcherHandler();
10
+ }
11
+ async watchAndRegeneratePortalOnChange(paths, commandName, generatePortal) {
12
+ //Regex matches any hidden files and folders.
13
+ const watcher = chokidar.watch(paths.sourceDirectoryPath, {
14
+ ignored: [/(^|[/\\])\..+/],
15
+ ignoreInitial: true,
16
+ persistent: true,
17
+ awaitWriteFinish: true,
18
+ atomic: true
19
+ });
20
+ const deletedDirectories = new Set();
21
+ const eventQueue = new Map();
22
+ const mutex = new Mutex();
23
+ watcher
24
+ .on("all", async (event, path) => {
25
+ if (event == "unlinkDir") {
26
+ deletedDirectories.add(path);
27
+ }
28
+ if (event == "unlink") {
29
+ for (const dir of deletedDirectories) {
30
+ if (path.startsWith(dir)) {
31
+ return;
32
+ }
33
+ }
34
+ }
35
+ const eventId = `${Date.now()}-${crypto.randomUUID()}`;
36
+ await mutex.runExclusive(async () => {
37
+ eventQueue.clear();
38
+ eventQueue.set(eventId, path);
39
+ });
40
+ await this.watcherHandler.execute(async () => {
41
+ await this.handleFileChange(paths, eventQueue, eventId, commandName, generatePortal);
42
+ });
43
+ })
44
+ .on("error", () => {
45
+ console.error("An unexpected error occurred while watching your build folder for changes. Please try again later. If the issue persists, contact our team at support@apimatic.io");
46
+ watcher.close();
47
+ });
48
+ return watcher;
49
+ }
50
+ // TODO: Remove this method. Figure out a better way to do this.
51
+ cancelPendingOperations() {
52
+ if (this.watcherHandler) {
53
+ this.watcherHandler.cancel();
54
+ }
55
+ }
56
+ async handleFileChange(paths, eventQueue, eventId, commandName, generatePortal) {
57
+ if (!eventQueue.has(eventId)) {
58
+ return;
59
+ }
60
+ const result = await generatePortal(new DirectoryPath(paths.sourceDirectoryPath), new DirectoryPath(paths.destinationDirectoryPath), commandName, true, false);
61
+ result.map((error) => console.log(error));
62
+ }
63
+ }
64
+ //# sourceMappingURL=portal-watcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-watcher.js","sourceRoot":"","sources":["../../../../src/application/portal/serve/portal-watcher.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAGrE,MAAM,OAAO,aAAa;IAGxB;QACE,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,gCAAgC,CAC3C,KAAiB,EACjB,WAAmB,EACnB,cAM0B;QAE1B,6CAA6C;QAC7C,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,EAAE;YACxD,OAAO,EAAE,CAAC,eAAe,CAAC;YAC1B,aAAa,EAAE,IAAI;YACnB,UAAU,EAAE,IAAI;YAChB,gBAAgB,EAAE,IAAI;YACtB,MAAM,EAAE,IAAI;SACb,CAAC,CAAC;QAEH,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;QAC7C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;QAE1B,OAAO;aACJ,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAC/B,IAAI,KAAK,IAAI,WAAW,EAAE,CAAC;gBACzB,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YAED,IAAI,KAAK,IAAI,QAAQ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KAAK,CAAC,mBAAmB,CAAC,EAC5C,IAAI,aAAa,CAAC,KAAK,CAAC,wBAAwB,CAAC,EACjD,WAAW,EACX,IAAI,EACJ,KAAK,CACN,CAAC;QACF,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5C,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import { Result } from "../../../types/common/result.js";
2
+ import { ServeFlags, ServePaths } from "../../../types/portal/serve.js";
3
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
4
+ import { ActionResult } from "../../../actions/action-result.js";
5
+ export declare class ServeHandler {
6
+ private server;
7
+ private liveReloadServer;
8
+ private readonly app;
9
+ private readonly portalWatcher;
10
+ constructor();
11
+ setupServer(generatedPortalArtifactsDirectoryPath: string): Promise<Result<string, string>>;
12
+ startServer(paths: ServePaths, flags: ServeFlags, commandName: string, generatePortal: (buildDirectory: DirectoryPath, portalDirectory: DirectoryPath, commandName: string, force: boolean, zipPortal: boolean) => Promise<ActionResult>, displayShutdownMessages?: boolean): Promise<Result<boolean, string>>;
13
+ private stopServer;
14
+ private createLiveReloadServer;
15
+ private getPortForReloadServer;
16
+ }