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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/README.md +249 -99
  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 +11 -0
  10. package/lib/actions/portal/copilot.js +49 -0
  11. package/lib/actions/portal/copilot.js.map +1 -0
  12. package/lib/actions/portal/generate.d.ts +13 -0
  13. package/lib/actions/portal/generate.js +61 -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 +0 -1
  55. package/lib/client-utils/sdk-client.js +25 -55
  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 +43 -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 +26 -33
  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 +12 -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 +105 -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 +15 -0
  106. package/lib/controllers/portal/quickstart.js +217 -0
  107. package/lib/controllers/portal/quickstart.js.map +1 -0
  108. package/lib/index.d.ts +1 -1
  109. package/lib/index.js +2 -4
  110. package/lib/index.js.map +1 -0
  111. package/lib/infrastructure/api-utils.d.ts +9 -0
  112. package/lib/infrastructure/api-utils.js +33 -0
  113. package/lib/infrastructure/api-utils.js.map +1 -0
  114. package/lib/infrastructure/env-info.d.ts +8 -0
  115. package/lib/infrastructure/env-info.js +37 -0
  116. package/lib/infrastructure/env-info.js.map +1 -0
  117. package/lib/infrastructure/file-service.d.ts +18 -0
  118. package/lib/infrastructure/file-service.js +76 -0
  119. package/lib/infrastructure/file-service.js.map +1 -0
  120. package/lib/infrastructure/services/api-service.d.ts +10 -0
  121. package/lib/infrastructure/services/api-service.js +54 -0
  122. package/lib/infrastructure/services/api-service.js.map +1 -0
  123. package/lib/infrastructure/services/auth-service.d.ts +11 -0
  124. package/lib/infrastructure/services/auth-service.js +33 -0
  125. package/lib/infrastructure/services/auth-service.js.map +1 -0
  126. package/lib/infrastructure/services/portal-service.d.ts +20 -0
  127. package/lib/infrastructure/services/portal-service.js +163 -0
  128. package/lib/infrastructure/services/portal-service.js.map +1 -0
  129. package/lib/infrastructure/services/telemetry-service.d.ts +8 -0
  130. package/lib/infrastructure/services/telemetry-service.js +40 -0
  131. package/lib/infrastructure/services/telemetry-service.js.map +1 -0
  132. package/lib/infrastructure/tmp-extensions.d.ts +2 -0
  133. package/lib/infrastructure/tmp-extensions.js +6 -0
  134. package/lib/infrastructure/tmp-extensions.js.map +1 -0
  135. package/lib/infrastructure/zip-service.d.ts +6 -0
  136. package/lib/infrastructure/zip-service.js +39 -0
  137. package/lib/infrastructure/zip-service.js.map +1 -0
  138. package/lib/prompts/auth/login.d.ts +5 -0
  139. package/lib/prompts/auth/login.js +13 -0
  140. package/lib/prompts/auth/login.js.map +1 -0
  141. package/lib/prompts/portal/common/base-prompts.d.ts +7 -0
  142. package/lib/prompts/portal/common/base-prompts.js +19 -0
  143. package/lib/prompts/portal/common/base-prompts.js.map +1 -0
  144. package/lib/prompts/portal/copilot.d.ts +8 -0
  145. package/lib/prompts/portal/copilot.js +54 -0
  146. package/lib/prompts/portal/copilot.js.map +1 -0
  147. package/lib/prompts/portal/generate.d.ts +11 -0
  148. package/lib/prompts/portal/generate.js +42 -0
  149. package/lib/prompts/portal/generate.js.map +1 -0
  150. package/lib/prompts/portal/quickstart.d.ts +30 -0
  151. package/lib/prompts/portal/quickstart.js +240 -0
  152. package/lib/prompts/portal/quickstart.js.map +1 -0
  153. package/lib/prompts/portal/recipe/new-recipe.d.ts +24 -0
  154. package/lib/prompts/portal/recipe/new-recipe.js +203 -0
  155. package/lib/prompts/portal/recipe/new-recipe.js.map +1 -0
  156. package/lib/prompts/portal/serve.d.ts +4 -0
  157. package/lib/prompts/portal/serve.js +14 -0
  158. package/lib/prompts/portal/serve.js.map +1 -0
  159. package/lib/prompts/portal/toc/new-toc.d.ts +11 -0
  160. package/lib/prompts/portal/toc/new-toc.js +39 -0
  161. package/lib/prompts/portal/toc/new-toc.js.map +1 -0
  162. package/lib/prompts/sdk/generate.d.ts +11 -0
  163. package/lib/prompts/sdk/generate.js +42 -0
  164. package/lib/prompts/sdk/generate.js.map +1 -0
  165. package/lib/types/api/account.d.ts +10 -0
  166. package/lib/types/api/account.js +2 -0
  167. package/lib/types/api/account.js.map +1 -0
  168. package/lib/types/api/transform.d.ts +19 -4
  169. package/lib/types/api/transform.js +19 -4
  170. package/lib/types/api/transform.js.map +1 -0
  171. package/lib/types/api/validate.d.ts +3 -3
  172. package/lib/types/api/validate.js +2 -2
  173. package/lib/types/api/validate.js.map +1 -0
  174. package/lib/types/build/build.d.ts +14 -0
  175. package/lib/types/build/build.js +4 -0
  176. package/lib/types/build/build.js.map +1 -0
  177. package/lib/types/build-context.d.ts +13 -0
  178. package/lib/types/build-context.js +30 -0
  179. package/lib/types/build-context.js.map +1 -0
  180. package/lib/types/common/result.d.ts +17 -0
  181. package/lib/types/common/result.js +32 -0
  182. package/lib/types/common/result.js.map +1 -0
  183. package/lib/types/events/domain-event.d.ts +8 -0
  184. package/lib/types/events/domain-event.js +11 -0
  185. package/lib/types/events/domain-event.js.map +1 -0
  186. package/lib/types/events/recipe-creation-failed.d.ts +5 -0
  187. package/lib/types/events/recipe-creation-failed.js +8 -0
  188. package/lib/types/events/recipe-creation-failed.js.map +1 -0
  189. package/lib/types/events/toc-creation-failed.d.ts +5 -0
  190. package/lib/types/events/toc-creation-failed.js +8 -0
  191. package/lib/types/events/toc-creation-failed.js.map +1 -0
  192. package/lib/types/file/directoryPath.d.ts +7 -0
  193. package/lib/types/file/directoryPath.js +16 -0
  194. package/lib/types/file/directoryPath.js.map +1 -0
  195. package/lib/types/file/fileName.d.ts +5 -0
  196. package/lib/types/file/fileName.js +9 -0
  197. package/lib/types/file/fileName.js.map +1 -0
  198. package/lib/types/file/filePath.d.ts +8 -0
  199. package/lib/types/file/filePath.js +11 -0
  200. package/lib/types/file/filePath.js.map +1 -0
  201. package/lib/types/flags-provider.d.ts +15 -0
  202. package/lib/types/flags-provider.js +34 -0
  203. package/lib/types/flags-provider.js.map +1 -0
  204. package/lib/types/portal/generate.d.ts +13 -9
  205. package/lib/types/portal/generate.js +3 -2
  206. package/lib/types/portal/generate.js.map +1 -0
  207. package/lib/types/portal/quickstart.d.ts +17 -0
  208. package/lib/types/portal/quickstart.js +2 -0
  209. package/lib/types/portal/quickstart.js.map +1 -0
  210. package/lib/types/portal/serve.d.ts +12 -0
  211. package/lib/types/portal/serve.js +2 -0
  212. package/lib/types/portal/serve.js.map +1 -0
  213. package/lib/types/portal-context.d.ts +11 -0
  214. package/lib/types/portal-context.js +28 -0
  215. package/lib/types/portal-context.js.map +1 -0
  216. package/lib/types/recipe/recipe.d.ts +37 -0
  217. package/lib/types/recipe/recipe.js +6 -0
  218. package/lib/types/recipe/recipe.js.map +1 -0
  219. package/lib/types/sdk/generate.d.ts +11 -10
  220. package/lib/types/sdk/generate.js +11 -12
  221. package/lib/types/sdk/generate.js.map +1 -0
  222. package/lib/types/sdk-context.d.ts +13 -0
  223. package/lib/types/sdk-context.js +28 -0
  224. package/lib/types/sdk-context.js.map +1 -0
  225. package/lib/types/sdl/sdl.d.ts +12 -0
  226. package/lib/types/sdl/sdl.js +2 -0
  227. package/lib/types/sdl/sdl.js.map +1 -0
  228. package/lib/types/spec-context.d.ts +7 -0
  229. package/lib/types/spec-context.js +12 -0
  230. package/lib/types/spec-context.js.map +1 -0
  231. package/lib/types/toc/toc.d.ts +31 -0
  232. package/lib/types/toc/toc.js +9 -0
  233. package/lib/types/toc/toc.js.map +1 -0
  234. package/lib/types/utils.d.ts +3 -3
  235. package/lib/types/utils.js +2 -2
  236. package/lib/types/utils.js.map +1 -0
  237. package/lib/utils/utils.d.ts +16 -7
  238. package/lib/utils/utils.js +142 -86
  239. package/lib/utils/utils.js.map +1 -0
  240. package/lib/validators/common/directoryValidator.d.ts +5 -0
  241. package/lib/validators/common/directoryValidator.js +22 -0
  242. package/lib/validators/common/directoryValidator.js.map +1 -0
  243. package/lib/validators/portal/serve-validator.d.ts +6 -0
  244. package/lib/validators/portal/serve-validator.js +15 -0
  245. package/lib/validators/portal/serve-validator.js.map +1 -0
  246. package/package.json +96 -40
  247. package/bin/run +0 -5
  248. package/lib/controllers/portal/generate.d.ts +0 -2
  249. package/lib/controllers/portal/generate.js +0 -49
  250. package/lib/controllers/sdk/generate.d.ts +0 -4
  251. package/lib/controllers/sdk/generate.js +0 -64
@@ -0,0 +1,49 @@
1
+ import { ApiService } from "../../infrastructure/services/api-service.js";
2
+ import { PortalCopilotPrompts } from "../../prompts/portal/copilot.js";
3
+ import { ActionResult } from "../action-result.js";
4
+ import { BuildContext } from "../../types/build-context.js";
5
+ export class CopilotAction {
6
+ constructor(configDir, authKey = null) {
7
+ this.apiService = new ApiService();
8
+ this.prompts = new PortalCopilotPrompts();
9
+ this.configDir = configDir;
10
+ this.authKey = authKey;
11
+ }
12
+ async execute(buildDirectory, enable) {
13
+ const buildContext = new BuildContext(buildDirectory);
14
+ if (!(await buildContext.validate())) {
15
+ return ActionResult.error("'src' directory is empty or not valid.");
16
+ }
17
+ const buildJson = await buildContext.getBuildFileContents();
18
+ if (buildJson.apiCopilotConfig != null && !(await this.prompts.confirmOverwrite()))
19
+ return ActionResult.error("Exiting without making any change.");
20
+ const response = await this.apiService.getAccountInfo(this.configDir, this.authKey);
21
+ if (response.isErr()) {
22
+ return ActionResult.error(response._unsafeUnwrapErr());
23
+ }
24
+ const apiCopilotKey = await this.selectCopilotKey(response._unsafeUnwrap());
25
+ if (apiCopilotKey === null) {
26
+ return ActionResult.error("No copilot key found for the current subscription. Please contact support at support@apimatic.io.");
27
+ }
28
+ const welcomeMessage = await this.prompts.getWelcomeMessage();
29
+ if (welcomeMessage === undefined)
30
+ return ActionResult.error("Exiting without making any change.");
31
+ buildJson.apiCopilotConfig = {
32
+ isEnabled: enable,
33
+ key: apiCopilotKey,
34
+ welcomeMessage: welcomeMessage
35
+ };
36
+ await buildContext.updateBuildFileContents(buildJson);
37
+ this.prompts.copilotConfigured(buildJson.apiCopilotConfig);
38
+ return ActionResult.success();
39
+ }
40
+ async selectCopilotKey(subscription) {
41
+ if (subscription === undefined ||
42
+ subscription.ApiCopilotKeys === undefined ||
43
+ subscription.ApiCopilotKeys.length === 0) {
44
+ return null;
45
+ }
46
+ return await this.prompts.selectCopilotKey(subscription.ApiCopilotKeys);
47
+ }
48
+ }
49
+ //# sourceMappingURL=copilot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot.js","sourceRoot":"","sources":["../../../src/actions/portal/copilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,MAAM,OAAO,aAAa;IAMxB,YAAY,SAAwB,EAAE,UAAyB,IAAI;QALlD,eAAU,GAAG,IAAI,UAAU,EAAE,CA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,CAAC,oCAAoC,CAAC,CAAC;QAElE,SAAS,CAAC,gBAAgB,GAAG;YAC3B,SAAS,EAAE,MAAM;YACjB,GAAG,EAAE,aAAa;YAClB,cAAc,EAAE,cAAc;SAC/B,CAAC;QAEF,MAAM,YAAY,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAEtD,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QAC3D,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;IAEO,KAAK,CAAC,gBAAgB,CAAC,YAA0C;QACvE,IACE,YAAY,KAAK,SAAS;YAC1B,YAAY,CAAC,cAAc,KAAK,SAAS;YACzC,YAAY,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,EACxC,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;IAC1E,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
2
+ import { ActionResult } from "../action-result.js";
3
+ export declare class GenerateAction {
4
+ private readonly prompts;
5
+ private readonly zipArchiver;
6
+ private readonly fileService;
7
+ private readonly portalService;
8
+ private readonly configDir;
9
+ private readonly authKey;
10
+ constructor(configDir: DirectoryPath, authKey?: string | null);
11
+ readonly execute: (buildDirectory: DirectoryPath, portalDirectory: DirectoryPath, force: boolean, zipPortal: boolean) => Promise<ActionResult>;
12
+ private parseError;
13
+ }
@@ -0,0 +1,61 @@
1
+ import { PortalGeneratePrompts } from "../../prompts/portal/generate.js";
2
+ import { ZipService } from "../../infrastructure/zip-service.js";
3
+ import { FileService } from "../../infrastructure/file-service.js";
4
+ import { PortalService } from "../../infrastructure/services/portal-service.js";
5
+ import { FilePath } from "../../types/file/filePath.js";
6
+ import { FileName } from "../../types/file/fileName.js";
7
+ import { ActionResult } from "../action-result.js";
8
+ import { BuildContext } from "../../types/build-context.js";
9
+ import { PortalContext } from "../../types/portal-context.js";
10
+ import { withDirPath } from "../../infrastructure/tmp-extensions.js";
11
+ export class GenerateAction {
12
+ constructor(configDir, authKey = null) {
13
+ this.prompts = new PortalGeneratePrompts();
14
+ this.zipArchiver = new ZipService();
15
+ this.fileService = new FileService();
16
+ this.portalService = new PortalService();
17
+ this.execute = async (buildDirectory, portalDirectory, force, zipPortal) => {
18
+ if (buildDirectory.isEqual(portalDirectory)) {
19
+ return ActionResult.error(`The 'src' and 'portal' directory cannot be the same: "${portalDirectory}"`);
20
+ }
21
+ const buildContext = new BuildContext(buildDirectory);
22
+ if (!await buildContext.validate()) {
23
+ return ActionResult.error(`The 'src' directory is either empty or invalid: "${buildDirectory}"`);
24
+ }
25
+ const portalContext = new PortalContext(portalDirectory);
26
+ if (!force && (await portalContext.exists()) && !(await this.prompts.overwritePortal(portalDirectory))) {
27
+ return ActionResult.error("Please enter a different destination folder or remove the existing files and try again.");
28
+ }
29
+ return await withDirPath(async (tempDirectory) => {
30
+ this.prompts.displayPortalGenerationMessage();
31
+ const buildZipPath = new FilePath(tempDirectory, new FileName("build.zip"));
32
+ await this.zipArchiver.archive(buildDirectory, buildZipPath);
33
+ const response = await this.portalService.generatePortal(buildZipPath, this.configDir, this.authKey);
34
+ if (!response.isSuccess()) {
35
+ this.prompts.displayPortalGenerationErrorMessage();
36
+ return ActionResult.error(await this.parseError(response.error, portalDirectory, tempDirectory));
37
+ }
38
+ const tempPortalFilePath = new FilePath(tempDirectory, new FileName("portal.zip"));
39
+ await this.fileService.writeFile(tempPortalFilePath, response.value);
40
+ await portalContext.save(tempPortalFilePath, zipPortal);
41
+ this.prompts.displayPortalGenerationSuccessMessage();
42
+ return ActionResult.success();
43
+ });
44
+ };
45
+ this.configDir = configDir;
46
+ this.authKey = authKey;
47
+ }
48
+ async parseError(error, portalDirectory, tempDirectory) {
49
+ if (typeof error === 'string') {
50
+ return error;
51
+ }
52
+ const tempErrorFilePath = new FilePath(tempDirectory, new FileName("error.zip"));
53
+ await this.fileService.writeFile(tempErrorFilePath, error);
54
+ await this.fileService.cleanDirectory(portalDirectory);
55
+ await this.zipArchiver.unArchive(tempErrorFilePath, portalDirectory);
56
+ const errorReportPath = portalDirectory.join("apimatic-debug");
57
+ return "An error occurred during portal generation due to an issue with the input. An error report has been written at the destination path: " +
58
+ errorReportPath;
59
+ }
60
+ }
61
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/actions/portal/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,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,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AAGrE,MAAM,OAAO,cAAc;IAQzB,YAAY,SAAwB,EAAE,UAAyB,IAAI;QAPlD,YAAO,GAA0B,IAAI,qBAAqB,EAAE,CAAC;QAC7D,gBAAW,GAAe,IAAI,UAAU,EAAE,CAAC;QAC3C,gBAAW,GAAgB,IAAI,WAAW,EAAE,CAAC;QAC7C,kBAAa,GAAkB,IAAI,aAAa,EAAE,CAAC;QASpD,YAAO,GAAG,KAAK,EAC7B,cAA6B,EAC7B,eAA8B,EAC9B,KAAc,EACd,SAAkB,EACK,EAAE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"../../../types/common/result.js";
2
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
3
+ export declare class PortalRecipeAction {
4
+ private readonly prompts;
5
+ private readonly sdlParser;
6
+ private readonly BUILD_FILE_NAME;
7
+ constructor();
8
+ createRecipe(buildDirectoryPath: DirectoryPath, configDir: string, name?: string): Promise<Result<string, string>>;
9
+ private createRecipeFileName;
10
+ private toPascalCase;
11
+ private validateBuildDirectoryPath;
12
+ private promptUserAndBuildNewRecipe;
13
+ private promptUserAndAddContentStepToRecipe;
14
+ private promptUserAndAddEndpointStepToRecipe;
15
+ private parseTocFile;
16
+ private createPermalink;
17
+ private getBuildConfigFilePath;
18
+ private parseBuildConfig;
19
+ private checkRecipeAlreadyExists;
20
+ private getBuildDirectoryStructure;
21
+ private extractEndpointGroupsFromSdl;
22
+ private getSpecFolderPath;
23
+ private getContentFolderPath;
24
+ }
@@ -0,0 +1,250 @@
1
+ import * as path from "path";
2
+ import fs from "fs";
3
+ import fsExtra from "fs-extra";
4
+ import { parse } from "yaml";
5
+ import { tmpdir } from "os";
6
+ import { execa } from "execa";
7
+ import { PortalRecipePrompts } from "../../../prompts/portal/recipe/new-recipe.js";
8
+ import { StepType } from "../../../types/recipe/recipe.js";
9
+ import { Result } from "../../../types/common/result.js";
10
+ import { PortalRecipe } from "../../../application/portal/recipe/portal-recipe.js";
11
+ import { PortalRecipeGenerator } from "../../../application/portal/recipe/recipe-generator.js";
12
+ import { SdlParser } from "../../../application/portal/toc/sdl-parser.js";
13
+ import { PortalService } from "../../../infrastructure/services/portal-service.js";
14
+ export class PortalRecipeAction {
15
+ constructor() {
16
+ this.BUILD_FILE_NAME = "APIMATIC-BUILD.json";
17
+ this.prompts = new PortalRecipePrompts();
18
+ this.sdlParser = new SdlParser(new PortalService());
19
+ }
20
+ async createRecipe(buildDirectoryPath, configDir, name) {
21
+ this.prompts.displayWelcomeMessage();
22
+ const recipeName = name !== null && name !== void 0 ? name : (await this.prompts.recipeNamePrompt());
23
+ const recipeFileName = this.createRecipeFileName(recipeName);
24
+ const validateBuildDirectoryPathResult = await this.validateBuildDirectoryPath(buildDirectoryPath);
25
+ if (validateBuildDirectoryPathResult.isFailed()) {
26
+ return Result.failure(`Unable to generate API Recipe: ${validateBuildDirectoryPathResult.error}`);
27
+ }
28
+ //TODO: Create a type for the build config and use that here instead of any.
29
+ const buildConfigFilePath = await this.getBuildConfigFilePath(buildDirectoryPath);
30
+ const buildConfigResult = await this.parseBuildConfig(buildConfigFilePath);
31
+ if (buildConfigResult.isFailed()) {
32
+ return Result.failure(`Unable to generate API Recipe: ${buildConfigResult.error}`);
33
+ }
34
+ const contentFolderPath = this.getContentFolderPath(buildConfigResult.value, buildDirectoryPath);
35
+ const tocFilePath = path.join(contentFolderPath, "content", "toc.yml");
36
+ //TODO: Replace any type of tocFileResult.value to concrete type.
37
+ const tocFileResult = await this.parseTocFile(tocFilePath);
38
+ if (tocFileResult.isFailed()) {
39
+ return Result.failure(`Unable to generate API Recipe: ${tocFileResult.error}`);
40
+ }
41
+ const recipeAlreadyExists = this.checkRecipeAlreadyExists(tocFileResult.value, recipeName, recipeFileName);
42
+ if (recipeAlreadyExists && !(await this.prompts.overwriteApiRecipeInTocPrompt())) {
43
+ return Result.cancelled("Operation was cancelled by the user.");
44
+ }
45
+ const recipeResult = await this.promptUserAndBuildNewRecipe(buildConfigResult.value, contentFolderPath, recipeName, configDir);
46
+ if (recipeResult.isFailed()) {
47
+ return Result.failure(`Unable to generate API Recipe: ${recipeResult.error}`);
48
+ }
49
+ const recipeGenerator = new PortalRecipeGenerator();
50
+ await recipeGenerator.createRecipe(recipeResult.value, buildConfigResult.value, tocFileResult.value, tocFilePath, recipeName, recipeFileName, buildConfigFilePath, contentFolderPath);
51
+ const buildDirectoryStructure = await this.getBuildDirectoryStructure(recipeFileName);
52
+ this.prompts.displayBuildDirectoryStructureAsTree(buildDirectoryStructure);
53
+ this.prompts.displayRecipeGenerationSuccessMessage(contentFolderPath);
54
+ return Result.success("Generated recipe successfully.");
55
+ }
56
+ createRecipeFileName(recipeName) {
57
+ return this.toPascalCase(recipeName.trim());
58
+ }
59
+ toPascalCase(str) {
60
+ return str
61
+ .split(" ")
62
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
63
+ .join("");
64
+ }
65
+ async validateBuildDirectoryPath(buildDirectoryPath) {
66
+ if (!(await fsExtra.pathExists(buildDirectoryPath.toString()))) {
67
+ return Result.failure(`Portal build input folder ${buildDirectoryPath.toString()} does not exist.`);
68
+ }
69
+ return Result.success("Portal build input folder path validated successfully.");
70
+ }
71
+ //TODO: Figure out a better way to do this without the while loop.
72
+ async promptUserAndBuildNewRecipe(buildConfig, contentFolderPath, recipeName, configDir) {
73
+ const recipe = new PortalRecipe(recipeName);
74
+ let endpointGroups;
75
+ let idx = 1;
76
+ let addAnotherStep = true;
77
+ this.prompts.displayStepsInformation();
78
+ while (addAnotherStep) {
79
+ const stepType = await this.prompts.stepTypeSelectionPrompt();
80
+ const stepName = await this.prompts.stepNamePrompt("Step " + idx);
81
+ switch (stepType) {
82
+ case StepType.Content: {
83
+ const addContentStepResult = await this.promptUserAndAddContentStepToRecipe(recipe, stepName);
84
+ if (addContentStepResult.isFailed()) {
85
+ return Result.failure(addContentStepResult.error);
86
+ }
87
+ break;
88
+ }
89
+ case StepType.Endpoint: {
90
+ if (!endpointGroups) {
91
+ const extractEndpointGroupsFromSdlResult = await this.extractEndpointGroupsFromSdl(buildConfig, contentFolderPath, configDir);
92
+ if (extractEndpointGroupsFromSdlResult.isFailed()) {
93
+ return Result.failure(`${extractEndpointGroupsFromSdlResult.error}`);
94
+ }
95
+ endpointGroups = extractEndpointGroupsFromSdlResult.value;
96
+ }
97
+ await this.promptUserAndAddEndpointStepToRecipe(recipe, endpointGroups, stepName);
98
+ break;
99
+ }
100
+ }
101
+ addAnotherStep = await this.prompts.addAnotherStepSelectionPrompt();
102
+ idx++;
103
+ }
104
+ return Result.success(recipe.toSerializableRecipe());
105
+ }
106
+ async promptUserAndAddContentStepToRecipe(recipe, stepName) {
107
+ this.prompts.displayContentStepInfo();
108
+ let editor = process.env.EDITOR;
109
+ let editorArgs = [];
110
+ const tempFilePath = path.join(tmpdir(), `recipe-markdown-content-${Date.now()}.txt`);
111
+ const template = `# The Heading Goes Here\n\nThis is placeholder text for your API Recipe content step. Feel free to edit this. Save your changes and then close the file once you're done.`;
112
+ await fsExtra.writeFile(tempFilePath, template, "utf-8");
113
+ try {
114
+ if (!editor) {
115
+ if (process.platform === "win32") {
116
+ await execa("cmd", ["/c", "start", "/wait", "notepad", tempFilePath], { stdio: "ignore" });
117
+ }
118
+ else if (process.platform === "darwin" || process.platform === "linux") {
119
+ editor = "vim";
120
+ try {
121
+ await execa(editor, [tempFilePath], { stdio: "inherit" });
122
+ }
123
+ catch (_a) {
124
+ // User exiting vim can throw a non-zero exit code leading to exception, ignore it.
125
+ }
126
+ }
127
+ }
128
+ else {
129
+ if (editor === "code" || editor.endsWith("code.cmd") || editor.endsWith("code.exe")) {
130
+ editorArgs.push("--wait");
131
+ }
132
+ editorArgs.push(tempFilePath);
133
+ await execa(editor, editorArgs, { stdio: "ignore" });
134
+ }
135
+ const fileContent = await fsExtra.readFile(tempFilePath, "utf-8");
136
+ recipe.addContentStep(stepName, stepName, fileContent);
137
+ this.prompts.displayStepAddedSuccessfullyMessage();
138
+ return Result.success("Added content step successfully.");
139
+ }
140
+ catch (error) {
141
+ return Result.failure(`Unable to add content step. Please try again later.`);
142
+ }
143
+ finally {
144
+ await fsExtra.unlink(tempFilePath);
145
+ }
146
+ }
147
+ async promptUserAndAddEndpointStepToRecipe(recipe, endpointGroups, stepName) {
148
+ const endpointGroupName = await this.prompts.endpointGroupNamePrompt(endpointGroups);
149
+ const endpointName = await this.prompts.endpointNamePrompt(endpointGroups, endpointGroupName);
150
+ const description = await this.prompts.endpointDescriptionPrompt(endpointGroups, endpointGroupName, endpointName);
151
+ const endpointPermalink = await this.createPermalink([endpointGroupName, endpointName]);
152
+ recipe.addEndpointStep(stepName, stepName, description, endpointPermalink);
153
+ this.prompts.displayStepAddedSuccessfullyMessage();
154
+ }
155
+ //TODO: Replace any with concrete toc file object.
156
+ async parseTocFile(tocFilePath) {
157
+ // Check if the file exists
158
+ if (!fs.existsSync(tocFilePath)) {
159
+ return Result.failure(`toc.yml file not found at ${tocFilePath}. Please run 'apimatic:toc:new' to create your toc.yml file first.`);
160
+ }
161
+ try {
162
+ const tocContent = await fs.promises.readFile(tocFilePath, "utf-8");
163
+ return Result.success(parse(tocContent));
164
+ }
165
+ catch (_a) {
166
+ return Result.failure(`Unable to parse the toc.yml file located at ${tocFilePath}. Please make sure that the toc.yml is a valid YAML file.`);
167
+ }
168
+ }
169
+ async createPermalink(pathPieces) {
170
+ return `$e/${pathPieces.map(encodeURIComponent).join("/")}`;
171
+ }
172
+ async getBuildConfigFilePath(buildDirectoryPath) {
173
+ const files = await fs.promises.readdir(buildDirectoryPath.toString());
174
+ const buildFileExists = files.find((file) => file === this.BUILD_FILE_NAME);
175
+ if (!buildFileExists) {
176
+ return await this.prompts.buildConfigFilePathPrompt(buildDirectoryPath.toString());
177
+ }
178
+ return path.join(buildDirectoryPath.toString(), this.BUILD_FILE_NAME);
179
+ }
180
+ //TODO: Create a type for the build config and use that here instead of any.
181
+ async parseBuildConfig(buildConfigFilePath) {
182
+ try {
183
+ const fileData = await fs.promises.readFile(buildConfigFilePath, "utf-8");
184
+ return Result.success(JSON.parse(fileData));
185
+ }
186
+ catch (_a) {
187
+ return Result.failure(`There was an error parsing the build config file located at "${buildConfigFilePath}". Please check your build config file and try again later.`);
188
+ }
189
+ }
190
+ checkRecipeAlreadyExists(tocData, recipeName, recipeFileName) {
191
+ var _a;
192
+ let apiRecipesGroup = (_a = tocData.toc) === null || _a === void 0 ? void 0 : _a.find((item) => item.group === "API Recipes");
193
+ if (!apiRecipesGroup) {
194
+ return false;
195
+ }
196
+ // Check if recipe name or file name already exists
197
+ const existingRecipe = apiRecipesGroup.items.find((item) => item.page === recipeName || item.file === `recipes/${recipeFileName}.md`);
198
+ if (existingRecipe) {
199
+ return true;
200
+ }
201
+ return false;
202
+ }
203
+ async getBuildDirectoryStructure(recipeFileName) {
204
+ return {
205
+ content: {
206
+ "toc.yml : # Contains the API Recipes group with a new page for your API recipe": null
207
+ },
208
+ static: {
209
+ scripts: {
210
+ recipes: {
211
+ [`${recipeFileName}.js : # Generated recipe script file containing all of the steps`]: null
212
+ }
213
+ }
214
+ }
215
+ };
216
+ }
217
+ async extractEndpointGroupsFromSdl(buildConfig, contentFolderPath, configDir) {
218
+ const specFolderPath = this.getSpecFolderPath(buildConfig, contentFolderPath);
219
+ if (!(await fsExtra.pathExists(specFolderPath))) {
220
+ return Result.failure(`API specification file not found at ${specFolderPath}.`);
221
+ }
222
+ this.prompts.startProgressIndicatorWithMessage("Extracting endpoint groups and endpoints from the API specification.");
223
+ const endpointGroupsResult = await this.sdlParser.getEndpointGroupsFromSdl(specFolderPath, configDir);
224
+ if (endpointGroupsResult.isFailed()) {
225
+ this.prompts.stopProgressIndicatorWithMessage("Unable to extract endpoints from your API specification.");
226
+ return Result.failure(`${endpointGroupsResult.error}`);
227
+ }
228
+ this.prompts.stopProgressIndicatorWithMessage("Successfully extracted endpoint groups and endpoints from the API specification.");
229
+ return Result.success(endpointGroupsResult.value);
230
+ }
231
+ //TODO: Replace type of buildConfig from any to actual BuildConfig type after creating it.
232
+ getSpecFolderPath(buildConfig, contentFolderPath) {
233
+ var _a;
234
+ const apiSpecPath = (_a = buildConfig.generatePortal) === null || _a === void 0 ? void 0 : _a.apiSpecPath;
235
+ if (apiSpecPath) {
236
+ return path.join(contentFolderPath, apiSpecPath);
237
+ }
238
+ return path.join(contentFolderPath, "spec");
239
+ }
240
+ //TODO: Replace type of buildConfig from any to actual BuildConfig type after creating it.
241
+ getContentFolderPath(buildConfig, buildDirectoryPath) {
242
+ var _a;
243
+ const contentFolder = (_a = buildConfig.generatePortal) === null || _a === void 0 ? void 0 : _a.contentFolder;
244
+ if (contentFolder) {
245
+ return path.join(buildDirectoryPath.toString(), contentFolder);
246
+ }
247
+ return buildDirectoryPath.toString();
248
+ }
249
+ }
250
+ //# sourceMappingURL=new-recipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new-recipe.js","sourceRoot":"","sources":["../../../../src/actions/portal/recipe/new-recipe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAsB,QAAQ,EAAiB,MAAM,iCAAiC,CAAC;AAC9F,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qDAAqD,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wDAAwD,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,oDAAoD,CAAC;AAInF,MAAM,OAAO,kBAAkB;IAK7B;QAFiB,oBAAe,GAAW,qBAAqB,CAAC;QAG/D,IAAI,CAAC,OAAO,GAAG,IAAI,mBAAmB,EAAE,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;IACtD,CAAC;IAEM,KAAK,CAAC,YAAY,CACvB,kBAAiC,EACjC,SAAiB,EACjB,IAAa;QAEb,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;QAErC,MAAM,UAAU,GAAG,IAAI,aAAJ,IAAI,cAAJ,IA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AAE,CAAC;YACpC,IAAI,CAAC,OAAO,CAAC,gCAAgC,CAAC,0DAA0D,CAAC,CAAC;YAC1G,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,oBAAoB,CAAC,KAAM,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,gCAAgC,CAC3C,kFAAkF,CACnF,CAAC;QACF,OAAO,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,KAAM,CAAC,CAAC;IACrD,CAAC;IAED,0FAA0F;IAClF,iBAAiB,CAAC,WAAgB,EAAE,iBAAyB;;QACnE,MAAM,WAAW,GAAG,MAAA,WAAW,CAAC,cAAc,0CAAE,WAAW,CAAC;QAC5D,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED,0FAA0F;IAClF,oBAAoB,CAAC,WAAgB,EAAE,kBAAiC;;QAC9E,MAAM,aAAa,GAAG,MAAA,WAAW,CAAC,cAAc,0CAAE,aAAa,CAAC;QAChE,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,EAAE,aAAa,CAAC,CAAC;QACjE,CAAC;QAED,OAAO,kBAAkB,CAAC,QAAQ,EAAE,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import { PortalServePrompts } from "../../prompts/portal/serve.js";
2
+ import { ServeFlags, ServePaths } from "../../types/portal/serve.js";
3
+ import { ServeHandler } from "../../application/portal/serve/serve-handler.js";
4
+ import { Result } from "../../types/common/result.js";
5
+ import { PortalService } from "../../infrastructure/services/portal-service.js";
6
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
7
+ import { ActionResult } from "../action-result.js";
8
+ export declare class PortalServeAction {
9
+ protected readonly prompts: PortalServePrompts;
10
+ protected readonly serveHandler: ServeHandler;
11
+ protected readonly docsPortalService: PortalService;
12
+ constructor(prompts: PortalServePrompts, serveHandler: ServeHandler, docsPortalService: PortalService);
13
+ servePortal(flags: ServeFlags, paths: ServePaths, generatePortal: (buildDirectory: DirectoryPath, portalDirectory: DirectoryPath, force: boolean, zipPortal: boolean) => Promise<ActionResult>): Promise<Result<string, string>>;
14
+ }
@@ -0,0 +1,24 @@
1
+ import { Result } from "../../types/common/result.js";
2
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
3
+ export class PortalServeAction {
4
+ constructor(prompts, serveHandler, docsPortalService) {
5
+ this.prompts = prompts;
6
+ this.serveHandler = serveHandler;
7
+ this.docsPortalService = docsPortalService;
8
+ }
9
+ async servePortal(flags, paths, generatePortal) {
10
+ const result = await generatePortal(new DirectoryPath(paths.sourceDirectoryPath), new DirectoryPath(paths.destinationDirectoryPath), false, false);
11
+ return result.mapAll(async () => {
12
+ const setupServerResult = await this.serveHandler.setupServer(paths.destinationDirectoryPath);
13
+ if (setupServerResult.isFailed()) {
14
+ return Result.failure(setupServerResult.error);
15
+ }
16
+ const startServerResult = await this.serveHandler.startServer(paths, flags, generatePortal);
17
+ if (startServerResult.isFailed()) {
18
+ return Result.failure(startServerResult.error);
19
+ }
20
+ return Result.success(`Portal was successfully served.`);
21
+ }, async (message) => Result.failure(message));
22
+ }
23
+ }
24
+ //# sourceMappingURL=serve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../../../src/actions/portal/serve.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAGlE,MAAM,OAAO,iBAAiB;IAK5B,YAAmB,OAA2B,EAAE,YAA0B,EAAE,iBAAgC;QAC1G,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,KAAiB,EACjB,KAAiB,EACjB,cAK0B;QAE1B,MAAM,MAAM,GAAG,MAAM,cAAc,CACjC,IAAI,aAAa,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAC5C,IAAI,aAAa,CAAC,KAAK,CAAC,wBAAwB,CAAC,EACjD,KAAK,EACL,KAAK,CACN,CAAC;QAEF,OAAO,MAAM,CAAC,MAAM,CAClB,KAAK,IAAI,EAAE;YACT,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;YAC9F,IAAI,iBAAiB,CAAC,QAAQ,EAAE,EAAE,CAAC;gBACjC,OAAO,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAM,CAAC,CAAC;YAClD,CAAC;YAED,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;YAC5F,IAAI,iBAAiB,CAAC,QAAQ,EAAE,EAAE,CAAC;gBACjC,OAAO,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAM,CAAC,CAAC;YAClD,CAAC;YAED,OAAO,MAAM,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAC;QAC3D,CAAC,EACD,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAC3C,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import { Result } from "../../../types/common/result.js";
2
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
3
+ export declare class PortalNewTocAction {
4
+ private readonly prompts;
5
+ private readonly sdlParser;
6
+ private readonly tocGenerator;
7
+ private readonly contentParser;
8
+ private readonly DEFAULT_TOC_FILENAME;
9
+ private readonly APIMATIC_BUILD_FILENAME;
10
+ constructor();
11
+ createToc(buildDirectory: DirectoryPath, configDir: string, tocDirectory?: DirectoryPath, force?: boolean, expandEndpoints?: boolean, expandModels?: boolean): Promise<Result<string, string>>;
12
+ private writeToc;
13
+ private handleExistingToc;
14
+ private extractSdlComponents;
15
+ private extractContentGroups;
16
+ private getDestinationPath;
17
+ private checkExistingToc;
18
+ private getContentFolderPath;
19
+ private getSpecFolderPath;
20
+ }
@@ -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, 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, 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, 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);
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