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

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 (299) hide show
  1. package/README.md +112 -90
  2. package/lib/actions/action-result.d.ts +8 -3
  3. package/lib/actions/action-result.js +34 -15
  4. package/lib/actions/action-result.js.map +1 -1
  5. package/lib/actions/api/transform.d.ts +15 -0
  6. package/lib/actions/api/transform.js +48 -0
  7. package/lib/actions/api/transform.js.map +1 -0
  8. package/lib/actions/api/validate.d.ts +12 -0
  9. package/lib/actions/api/validate.js +41 -0
  10. package/lib/actions/api/validate.js.map +1 -0
  11. package/lib/actions/auth/login.d.ts +6 -5
  12. package/lib/actions/auth/login.js +25 -33
  13. package/lib/actions/auth/login.js.map +1 -1
  14. package/lib/actions/auth/logout.d.ts +8 -0
  15. package/lib/actions/auth/logout.js +15 -0
  16. package/lib/actions/auth/logout.js.map +1 -0
  17. package/lib/actions/auth/status.d.ts +11 -0
  18. package/lib/actions/auth/status.js +26 -0
  19. package/lib/actions/auth/status.js.map +1 -0
  20. package/lib/actions/portal/copilot.d.ts +5 -3
  21. package/lib/actions/portal/copilot.js +47 -37
  22. package/lib/actions/portal/copilot.js.map +1 -1
  23. package/lib/actions/portal/generate.d.ts +4 -5
  24. package/lib/actions/portal/generate.js +30 -37
  25. package/lib/actions/portal/generate.js.map +1 -1
  26. package/lib/actions/portal/quickstart.d.ts +16 -0
  27. package/lib/actions/portal/quickstart.js +145 -0
  28. package/lib/actions/portal/quickstart.js.map +1 -0
  29. package/lib/actions/portal/recipe/new-recipe.d.ts +11 -20
  30. package/lib/actions/portal/recipe/new-recipe.js +147 -221
  31. package/lib/actions/portal/recipe/new-recipe.js.map +1 -1
  32. package/lib/actions/portal/serve.d.ts +12 -10
  33. package/lib/actions/portal/serve.js +112 -17
  34. package/lib/actions/portal/serve.js.map +1 -1
  35. package/lib/actions/portal/toc/new-toc.d.ts +16 -15
  36. package/lib/actions/portal/toc/new-toc.js +80 -116
  37. package/lib/actions/portal/toc/new-toc.js.map +1 -1
  38. package/lib/actions/sdk/generate.d.ts +5 -6
  39. package/lib/actions/sdk/generate.js +22 -47
  40. package/lib/actions/sdk/generate.js.map +1 -1
  41. package/lib/application/portal/recipe/portal-recipe.d.ts +2 -2
  42. package/lib/application/portal/recipe/portal-recipe.js +9 -9
  43. package/lib/application/portal/recipe/portal-recipe.js.map +1 -1
  44. package/lib/application/portal/recipe/recipe-generator.d.ts +7 -2
  45. package/lib/application/portal/recipe/recipe-generator.js +21 -22
  46. package/lib/application/portal/recipe/recipe-generator.js.map +1 -1
  47. package/lib/client-utils/auth-manager.d.ts +1 -1
  48. package/lib/client-utils/auth-manager.js +3 -4
  49. package/lib/client-utils/auth-manager.js.map +1 -1
  50. package/lib/commands/api/transform.d.ts +6 -3
  51. package/lib/commands/api/transform.js +43 -94
  52. package/lib/commands/api/transform.js.map +1 -1
  53. package/lib/commands/api/validate.d.ts +6 -3
  54. package/lib/commands/api/validate.js +27 -66
  55. package/lib/commands/api/validate.js.map +1 -1
  56. package/lib/commands/auth/login.d.ts +2 -1
  57. package/lib/commands/auth/login.js +15 -9
  58. package/lib/commands/auth/login.js.map +1 -1
  59. package/lib/commands/auth/logout.d.ts +3 -1
  60. package/lib/commands/auth/logout.js +12 -13
  61. package/lib/commands/auth/logout.js.map +1 -1
  62. package/lib/commands/auth/status.d.ts +1 -0
  63. package/lib/commands/auth/status.js +13 -11
  64. package/lib/commands/auth/status.js.map +1 -1
  65. package/lib/commands/portal/copilot.d.ts +2 -2
  66. package/lib/commands/portal/copilot.js +22 -20
  67. package/lib/commands/portal/copilot.js.map +1 -1
  68. package/lib/commands/portal/generate.d.ts +3 -4
  69. package/lib/commands/portal/generate.js +19 -14
  70. package/lib/commands/portal/generate.js.map +1 -1
  71. package/lib/commands/portal/quickstart.d.ts +3 -4
  72. package/lib/commands/portal/quickstart.js +24 -101
  73. package/lib/commands/portal/quickstart.js.map +1 -1
  74. package/lib/commands/portal/recipe/new.d.ts +3 -1
  75. package/lib/commands/portal/recipe/new.js +31 -23
  76. package/lib/commands/portal/recipe/new.js.map +1 -1
  77. package/lib/commands/portal/serve.d.ts +5 -5
  78. package/lib/commands/portal/serve.js +31 -57
  79. package/lib/commands/portal/serve.js.map +1 -1
  80. package/lib/commands/portal/toc/new.d.ts +2 -2
  81. package/lib/commands/portal/toc/new.js +35 -26
  82. package/lib/commands/portal/toc/new.js.map +1 -1
  83. package/lib/commands/sdk/generate.d.ts +5 -4
  84. package/lib/commands/sdk/generate.js +26 -17
  85. package/lib/commands/sdk/generate.js.map +1 -1
  86. package/lib/hooks/not-found.js +1 -1
  87. package/lib/hooks/not-found.js.map +1 -1
  88. package/lib/infrastructure/api-utils.js +3 -2
  89. package/lib/infrastructure/api-utils.js.map +1 -1
  90. package/lib/{application/portal/serve/watcher-handler.d.ts → infrastructure/debounce-service.d.ts} +3 -3
  91. package/lib/{application/portal/serve/watcher-handler.js → infrastructure/debounce-service.js} +5 -4
  92. package/lib/infrastructure/debounce-service.js.map +1 -0
  93. package/lib/infrastructure/env-info.d.ts +1 -1
  94. package/lib/infrastructure/env-info.js +2 -2
  95. package/lib/infrastructure/env-info.js.map +1 -1
  96. package/lib/infrastructure/file-service.d.ts +7 -2
  97. package/lib/infrastructure/file-service.js +46 -5
  98. package/lib/infrastructure/file-service.js.map +1 -1
  99. package/lib/infrastructure/launcher-service.d.ts +2 -0
  100. package/lib/infrastructure/launcher-service.js +4 -0
  101. package/lib/infrastructure/launcher-service.js.map +1 -1
  102. package/lib/infrastructure/network-service.d.ts +3 -0
  103. package/lib/infrastructure/network-service.js +7 -0
  104. package/lib/infrastructure/network-service.js.map +1 -0
  105. package/lib/infrastructure/services/api-client-factory.d.ts +6 -0
  106. package/lib/infrastructure/services/api-client-factory.js +20 -0
  107. package/lib/infrastructure/services/api-client-factory.js.map +1 -0
  108. package/lib/infrastructure/services/api-service.d.ts +2 -2
  109. package/lib/infrastructure/services/api-service.js +6 -6
  110. package/lib/infrastructure/services/api-service.js.map +1 -1
  111. package/lib/infrastructure/services/auth-service.d.ts +1 -1
  112. package/lib/infrastructure/services/auth-service.js +7 -5
  113. package/lib/infrastructure/services/auth-service.js.map +1 -1
  114. package/lib/infrastructure/services/file-download-service.d.ts +15 -0
  115. package/lib/infrastructure/services/file-download-service.js +104 -0
  116. package/lib/infrastructure/services/file-download-service.js.map +1 -0
  117. package/lib/infrastructure/services/portal-service.d.ts +11 -13
  118. package/lib/infrastructure/services/portal-service.js +73 -102
  119. package/lib/infrastructure/services/portal-service.js.map +1 -1
  120. package/lib/infrastructure/services/telemetry-service.d.ts +3 -2
  121. package/lib/infrastructure/services/telemetry-service.js +4 -6
  122. package/lib/infrastructure/services/telemetry-service.js.map +1 -1
  123. package/lib/infrastructure/services/transformation-service.d.ts +23 -0
  124. package/lib/infrastructure/services/transformation-service.js +56 -0
  125. package/lib/infrastructure/services/transformation-service.js.map +1 -0
  126. package/lib/infrastructure/services/validation-service.d.ts +17 -0
  127. package/lib/infrastructure/services/validation-service.js +49 -0
  128. package/lib/infrastructure/services/validation-service.js.map +1 -0
  129. package/lib/prompts/api/transform.d.ts +11 -0
  130. package/lib/prompts/api/transform.js +30 -0
  131. package/lib/prompts/api/transform.js.map +1 -0
  132. package/lib/prompts/api/validate.d.ts +12 -0
  133. package/lib/prompts/api/validate.js +41 -0
  134. package/lib/prompts/api/validate.js.map +1 -0
  135. package/lib/prompts/auth/login.d.ts +6 -1
  136. package/lib/prompts/auth/login.js +12 -3
  137. package/lib/prompts/auth/login.js.map +1 -1
  138. package/lib/prompts/auth/logout.d.ts +3 -0
  139. package/lib/prompts/auth/logout.js +7 -0
  140. package/lib/prompts/auth/logout.js.map +1 -0
  141. package/lib/prompts/auth/status.d.ts +8 -0
  142. package/lib/prompts/auth/status.js +21 -0
  143. package/lib/prompts/auth/status.js.map +1 -0
  144. package/lib/prompts/format.d.ts +33 -0
  145. package/lib/prompts/format.js +99 -0
  146. package/lib/prompts/format.js.map +1 -0
  147. package/lib/prompts/portal/copilot.d.ts +8 -4
  148. package/lib/prompts/portal/copilot.js +35 -24
  149. package/lib/prompts/portal/copilot.js.map +1 -1
  150. package/lib/prompts/portal/generate.d.ts +9 -7
  151. package/lib/prompts/portal/generate.js +22 -23
  152. package/lib/prompts/portal/generate.js.map +1 -1
  153. package/lib/prompts/portal/quickstart.d.ts +30 -29
  154. package/lib/prompts/portal/quickstart.js +99 -193
  155. package/lib/prompts/portal/quickstart.js.map +1 -1
  156. package/lib/prompts/portal/recipe/new-recipe.d.ts +23 -18
  157. package/lib/prompts/portal/recipe/new-recipe.js +70 -108
  158. package/lib/prompts/portal/recipe/new-recipe.js.map +1 -1
  159. package/lib/prompts/portal/serve.d.ts +10 -3
  160. package/lib/prompts/portal/serve.js +30 -11
  161. package/lib/prompts/portal/serve.js.map +1 -1
  162. package/lib/prompts/portal/toc/new-toc.d.ts +12 -8
  163. package/lib/prompts/portal/toc/new-toc.js +20 -22
  164. package/lib/prompts/portal/toc/new-toc.js.map +1 -1
  165. package/lib/prompts/sdk/generate.d.ts +7 -7
  166. package/lib/prompts/sdk/generate.js +17 -23
  167. package/lib/prompts/sdk/generate.js.map +1 -1
  168. package/lib/types/api/account.d.ts +1 -1
  169. package/lib/types/api/transform.d.ts +14 -25
  170. package/lib/types/api/transform.js +16 -16
  171. package/lib/types/api/transform.js.map +1 -1
  172. package/lib/types/build/build.d.ts +9 -1
  173. package/lib/types/build/build.js +5 -2
  174. package/lib/types/build/build.js.map +1 -1
  175. package/lib/types/build-context.d.ts +5 -1
  176. package/lib/types/build-context.js +21 -4
  177. package/lib/types/build-context.js.map +1 -1
  178. package/lib/types/common/command-metadata.d.ts +4 -0
  179. package/lib/types/common/command-metadata.js +2 -0
  180. package/lib/types/common/command-metadata.js.map +1 -0
  181. package/lib/types/events/domain-event.d.ts +1 -1
  182. package/lib/types/events/domain-event.js.map +1 -1
  183. package/lib/types/events/quickstart-completed.js +1 -1
  184. package/lib/types/events/quickstart-initiated.js +1 -1
  185. package/lib/types/events/recipe-creation-failed.d.ts +1 -1
  186. package/lib/types/events/recipe-creation-failed.js +1 -1
  187. package/lib/types/events/recipe-creation-failed.js.map +1 -1
  188. package/lib/types/events/toc-creation-failed.d.ts +1 -1
  189. package/lib/types/events/toc-creation-failed.js +1 -1
  190. package/lib/types/events/toc-creation-failed.js.map +1 -1
  191. package/lib/types/file/directory.d.ts +17 -0
  192. package/lib/types/file/directory.js +86 -0
  193. package/lib/types/file/directory.js.map +1 -0
  194. package/lib/types/file/directoryPath.d.ts +3 -1
  195. package/lib/types/file/directoryPath.js +8 -2
  196. package/lib/types/file/directoryPath.js.map +1 -1
  197. package/lib/types/file/fileName.d.ts +2 -0
  198. package/lib/types/file/fileName.js +12 -0
  199. package/lib/types/file/fileName.js.map +1 -1
  200. package/lib/types/file/filePath.d.ts +2 -0
  201. package/lib/types/file/filePath.js +21 -0
  202. package/lib/types/file/filePath.js.map +1 -1
  203. package/lib/types/file/resource-input.d.ts +5 -0
  204. package/lib/types/file/resource-input.js +42 -0
  205. package/lib/types/file/resource-input.js.map +1 -0
  206. package/lib/types/file/urlPath.d.ts +6 -0
  207. package/lib/types/file/urlPath.js +22 -0
  208. package/lib/types/file/urlPath.js.map +1 -0
  209. package/lib/types/portal-context.d.ts +3 -1
  210. package/lib/types/portal-context.js +10 -0
  211. package/lib/types/portal-context.js.map +1 -1
  212. package/lib/types/recipe/recipe.d.ts +2 -17
  213. package/lib/types/recipe-context.d.ts +8 -0
  214. package/lib/types/recipe-context.js +21 -0
  215. package/lib/types/recipe-context.js.map +1 -0
  216. package/lib/types/resource-context.d.ts +12 -0
  217. package/lib/types/resource-context.js +30 -0
  218. package/lib/types/resource-context.js.map +1 -0
  219. package/lib/types/sdk/generate.d.ts +2 -15
  220. package/lib/types/sdk/generate.js +24 -10
  221. package/lib/types/sdk/generate.js.map +1 -1
  222. package/lib/types/sdk-context.d.ts +6 -5
  223. package/lib/types/sdk-context.js +12 -8
  224. package/lib/types/sdk-context.js.map +1 -1
  225. package/lib/types/sdl/sdl.d.ts +9 -0
  226. package/lib/types/sdl/sdl.js +46 -1
  227. package/lib/types/sdl/sdl.js.map +1 -1
  228. package/lib/types/spec-context.d.ts +3 -0
  229. package/lib/types/spec-context.js +7 -2
  230. package/lib/types/spec-context.js.map +1 -1
  231. package/lib/types/temp-context.d.ts +11 -0
  232. package/lib/types/temp-context.js +27 -0
  233. package/lib/types/temp-context.js.map +1 -0
  234. package/lib/types/toc-context.d.ts +12 -0
  235. package/lib/types/toc-context.js +26 -0
  236. package/lib/types/toc-context.js.map +1 -0
  237. package/lib/types/transform-context.d.ts +13 -0
  238. package/lib/types/transform-context.js +30 -0
  239. package/lib/types/transform-context.js.map +1 -0
  240. package/lib/types/utils.d.ts +0 -9
  241. package/lib/utils/string-utils.d.ts +1 -0
  242. package/lib/utils/string-utils.js +10 -0
  243. package/lib/utils/string-utils.js.map +1 -0
  244. package/lib/utils/utils.d.ts +2 -27
  245. package/lib/utils/utils.js +6 -145
  246. package/lib/utils/utils.js.map +1 -1
  247. package/package.json +4 -4
  248. package/lib/application/portal/serve/portal-watcher.d.ts +0 -11
  249. package/lib/application/portal/serve/portal-watcher.js +0 -64
  250. package/lib/application/portal/serve/portal-watcher.js.map +0 -1
  251. package/lib/application/portal/serve/serve-handler.d.ts +0 -16
  252. package/lib/application/portal/serve/serve-handler.js +0 -91
  253. package/lib/application/portal/serve/serve-handler.js.map +0 -1
  254. package/lib/application/portal/serve/watcher-handler.js.map +0 -1
  255. package/lib/application/portal/toc/sdl-parser.d.ts +0 -19
  256. package/lib/application/portal/toc/sdl-parser.js +0 -90
  257. package/lib/application/portal/toc/sdl-parser.js.map +0 -1
  258. package/lib/client-utils/sdk-client.d.ts +0 -18
  259. package/lib/client-utils/sdk-client.js +0 -41
  260. package/lib/client-utils/sdk-client.js.map +0 -1
  261. package/lib/config/env.d.ts +0 -26
  262. package/lib/config/env.js +0 -27
  263. package/lib/config/env.js.map +0 -1
  264. package/lib/controllers/api/transform.d.ts +0 -5
  265. package/lib/controllers/api/transform.js +0 -50
  266. package/lib/controllers/api/transform.js.map +0 -1
  267. package/lib/controllers/api/validate.d.ts +0 -3
  268. package/lib/controllers/api/validate.js +0 -29
  269. package/lib/controllers/api/validate.js.map +0 -1
  270. package/lib/controllers/portal/quickstart.d.ts +0 -13
  271. package/lib/controllers/portal/quickstart.js +0 -214
  272. package/lib/controllers/portal/quickstart.js.map +0 -1
  273. package/lib/infrastructure/api-client-utils.d.ts +0 -6
  274. package/lib/infrastructure/api-client-utils.js +0 -34
  275. package/lib/infrastructure/api-client-utils.js.map +0 -1
  276. package/lib/prompts/portal/common/base-prompts.d.ts +0 -7
  277. package/lib/prompts/portal/common/base-prompts.js +0 -19
  278. package/lib/prompts/portal/common/base-prompts.js.map +0 -1
  279. package/lib/types/api/validate.d.ts +0 -12
  280. package/lib/types/api/validate.js +0 -2
  281. package/lib/types/api/validate.js.map +0 -1
  282. package/lib/types/common/result.d.ts +0 -17
  283. package/lib/types/common/result.js +0 -32
  284. package/lib/types/common/result.js.map +0 -1
  285. package/lib/types/portal/generate.d.ts +0 -13
  286. package/lib/types/portal/generate.js +0 -3
  287. package/lib/types/portal/generate.js.map +0 -1
  288. package/lib/types/portal/quickstart.d.ts +0 -17
  289. package/lib/types/portal/quickstart.js +0 -2
  290. package/lib/types/portal/quickstart.js.map +0 -1
  291. package/lib/types/portal/serve.d.ts +0 -12
  292. package/lib/types/portal/serve.js +0 -2
  293. package/lib/types/portal/serve.js.map +0 -1
  294. package/lib/validators/common/directoryValidator.d.ts +0 -5
  295. package/lib/validators/common/directoryValidator.js +0 -22
  296. package/lib/validators/common/directoryValidator.js.map +0 -1
  297. package/lib/validators/portal/serve-validator.d.ts +0 -6
  298. package/lib/validators/portal/serve-validator.js +0 -15
  299. package/lib/validators/portal/serve-validator.js.map +0 -1
@@ -1,14 +1,16 @@
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
1
  import { DirectoryPath } from "../../types/file/directoryPath.js";
7
2
  import { ActionResult } from "../action-result.js";
3
+ import { CommandMetadata } from "../../types/common/command-metadata.js";
8
4
  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, commandName: string, generatePortal: (buildDirectory: DirectoryPath, portalDirectory: DirectoryPath, commandName: string, force: boolean, zipPortal: boolean) => Promise<ActionResult>): Promise<Result<string, string>>;
5
+ private readonly prompts;
6
+ private readonly networkService;
7
+ private readonly launcherService;
8
+ private readonly application;
9
+ private readonly configDir;
10
+ private readonly commandMetadata;
11
+ private readonly authKey;
12
+ private isPortalServed;
13
+ constructor(configDir: DirectoryPath, commandMetadata: CommandMetadata, authKey?: string | null);
14
+ execute(buildDirectory: DirectoryPath, portalDirectory: DirectoryPath, port: number, openInBrowser: boolean, hotReload: boolean, onAfterServe?: () => void): Promise<ActionResult>;
15
+ private clearStandardInput;
14
16
  }
@@ -1,24 +1,119 @@
1
- import { Result } from "../../types/common/result.js";
2
- import { DirectoryPath } from "../../types/file/directoryPath.js";
1
+ import { createServer as createLiveReloadServer } from "livereload";
2
+ import connectLiveReload from "connect-livereload";
3
+ import express from "express";
4
+ import chokidar from "chokidar";
5
+ import crypto from "crypto";
6
+ import { Mutex } from "async-mutex";
7
+ import { PortalServePrompts } from "../../prompts/portal/serve.js";
8
+ import { ActionResult } from "../action-result.js";
9
+ import { GenerateAction } from "./generate.js";
10
+ import { NetworkService } from "../../infrastructure/network-service.js";
11
+ import { UrlPath } from "../../types/file/urlPath.js";
12
+ import { LauncherService } from "../../infrastructure/launcher-service.js";
13
+ import { DebounceService } from "../../infrastructure/debounce-service.js";
3
14
  export class PortalServeAction {
4
- constructor(prompts, serveHandler, docsPortalService) {
5
- this.prompts = prompts;
6
- this.serveHandler = serveHandler;
7
- this.docsPortalService = docsPortalService;
15
+ constructor(configDir, commandMetadata, authKey = null) {
16
+ this.prompts = new PortalServePrompts();
17
+ this.networkService = new NetworkService();
18
+ this.launcherService = new LauncherService();
19
+ this.application = express();
20
+ this.isPortalServed = false;
21
+ this.configDir = configDir;
22
+ this.commandMetadata = commandMetadata;
23
+ this.authKey = authKey;
8
24
  }
9
- async servePortal(flags, paths, commandName, generatePortal) {
10
- const result = await generatePortal(new DirectoryPath(paths.sourceDirectoryPath), new DirectoryPath(paths.destinationDirectoryPath), commandName, 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);
25
+ async execute(buildDirectory, portalDirectory, port, openInBrowser, hotReload, onAfterServe) {
26
+ const generatePortalAction = new GenerateAction(this.configDir, this.commandMetadata, this.authKey);
27
+ const result = await generatePortalAction.execute(buildDirectory, portalDirectory, true, false);
28
+ if (result.isFailed()) {
29
+ return ActionResult.failed();
30
+ }
31
+ const servePort = await this.networkService.getServerPort([port, 3000, 3001, 3002]);
32
+ if (servePort != port && !onAfterServe) {
33
+ this.prompts.usingFallbackPort(port, servePort);
34
+ }
35
+ const liveReloadPort = await this.networkService.getServerPort([35729, 35730, 35731, 35732]);
36
+ const liveReloadServer = createLiveReloadServer({ port: liveReloadPort });
37
+ const server = this.application
38
+ .use(connectLiveReload())
39
+ .use(express.static(portalDirectory.toString(), { extensions: ["html"] }))
40
+ .listen(servePort);
41
+ const portalUrl = new UrlPath(`http://localhost:${servePort}`);
42
+ this.prompts.portalServed(portalUrl);
43
+ if (openInBrowser) {
44
+ await this.launcherService.openUrlInBrowser(portalUrl);
45
+ }
46
+ this.prompts.promptForExit();
47
+ if (!hotReload) {
48
+ if (onAfterServe) {
49
+ onAfterServe();
15
50
  }
16
- const startServerResult = await this.serveHandler.startServer(paths, flags, commandName, generatePortal);
17
- if (startServerResult.isFailed()) {
18
- return Result.failure(startServerResult.error);
51
+ this.clearStandardInput();
52
+ await this.prompts.blockExecution();
53
+ liveReloadServer.close();
54
+ server.close();
55
+ return ActionResult.success();
56
+ }
57
+ this.prompts.hotReloadEnabled(buildDirectory);
58
+ const watcher = chokidar.watch(buildDirectory.toString(), {
59
+ ignored: [/(^|[/\\])\..+/],
60
+ ignoreInitial: true,
61
+ persistent: true,
62
+ awaitWriteFinish: true,
63
+ atomic: true
64
+ });
65
+ const deletedDirectories = new Set();
66
+ // TODO: Verify if we need mutex and eventQueue after refactoring.
67
+ const eventQueue = new Map();
68
+ const mutex = new Mutex();
69
+ const debounceService = new DebounceService();
70
+ watcher
71
+ .on("all", async (event, path) => {
72
+ // triggers folder deletion as a single event
73
+ if (event == "unlinkDir") {
74
+ deletedDirectories.add(path);
19
75
  }
20
- return Result.success(`Portal was successfully served.`);
21
- }, async (message) => Result.failure(message));
76
+ if (event == "unlink") {
77
+ for (const dir of deletedDirectories) {
78
+ if (path.startsWith(dir)) {
79
+ return;
80
+ }
81
+ }
82
+ }
83
+ const eventId = `${Date.now()}-${crypto.randomUUID()}`;
84
+ await mutex.runExclusive(async () => {
85
+ eventQueue.clear();
86
+ eventQueue.set(eventId, path);
87
+ });
88
+ await debounceService.batchSingleRequest(async () => {
89
+ this.prompts.changesDetected();
90
+ // TODO: Verify if this is needed.
91
+ if (!eventQueue.has(eventId)) {
92
+ return;
93
+ }
94
+ await generatePortalAction.execute(buildDirectory, portalDirectory, true, false, false);
95
+ liveReloadServer.refresh(portalDirectory.toString());
96
+ this.clearStandardInput();
97
+ });
98
+ })
99
+ .on("error", async () => {
100
+ this.prompts.watcherError();
101
+ });
102
+ // Wait for SIGINT or SIGTERM
103
+ this.clearStandardInput();
104
+ await this.prompts.blockExecution();
105
+ await watcher.close();
106
+ debounceService.close();
107
+ liveReloadServer.close();
108
+ server.close();
109
+ return ActionResult.success();
110
+ }
111
+ // This clears the standard input to allow interrupts like CTRL+C to work properly.
112
+ clearStandardInput() {
113
+ if (process.platform !== "darwin" && process.stdin.isTTY) {
114
+ process.stdin.setRawMode(false);
115
+ process.stdin.pause();
116
+ }
22
117
  }
23
118
  }
24
119
  //# sourceMappingURL=serve.js.map
@@ -1 +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,WAAmB,EACnB,cAM0B;QAE1B,MAAM,MAAM,GAAG,MAAM,cAAc,CACjC,IAAI,aAAa,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAC5C,IAAI,aAAa,CAAC,KAAK,CAAC,wBAAwB,CAAC,EACjD,WAAW,EACX,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;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,EAAE,CAAC,CAAC;gBACrD,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;aACD,EAAE,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE;YACtB,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEL,6BAA6B;QAC7B,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QAEpC,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACtB,eAAe,CAAC,KAAK,EAAE,CAAC;QAExB,gBAAgB,CAAC,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;IAED,mFAAmF;IAC3E,kBAAkB;QACxB,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACzD,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAChC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;CACF"}
@@ -1,20 +1,21 @@
1
- import { Result } from "../../../types/common/result.js";
1
+ import { TocGroup } from "../../../types/toc/toc.js";
2
2
  import { DirectoryPath } from "../../../types/file/directoryPath.js";
3
+ import { CommandMetadata } from "../../../types/common/command-metadata.js";
4
+ import { ActionResult } from "../../action-result.js";
5
+ export declare class ContentContext {
6
+ private readonly contentDirectory;
7
+ private readonly fileService;
8
+ constructor(contentDirectory: DirectoryPath);
9
+ exists(): Promise<boolean>;
10
+ extractContentGroups(): Promise<TocGroup[]>;
11
+ }
3
12
  export declare class PortalNewTocAction {
13
+ private readonly configDirectory;
14
+ private readonly commandMetadata;
4
15
  private readonly prompts;
5
- private readonly sdlParser;
6
16
  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, commandName: 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;
17
+ private readonly fileService;
18
+ private readonly portalService;
19
+ constructor(configDirectory: DirectoryPath, commandMetadata: CommandMetadata);
20
+ execute(buildDirectory: DirectoryPath, tocDirectory?: DirectoryPath, force?: boolean, expandEndpoints?: boolean, expandModels?: boolean): Promise<ActionResult>;
20
21
  }
@@ -1,133 +1,97 @@
1
- import * as path from "path";
2
- import fsExtra from "fs-extra";
1
+ import { ok } from "neverthrow";
3
2
  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
3
  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";
4
+ import { ActionResult } from "../../action-result.js";
5
+ import { TocContext } from "../../../types/toc-context.js";
6
+ import { FileService } from "../../../infrastructure/file-service.js";
12
7
  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;
8
+ import { getEndpointGroupsAndModels } from "../../../types/sdl/sdl.js";
9
+ import { withDirPath } from "../../../infrastructure/tmp-extensions.js";
10
+ import { TempContext } from "../../../types/temp-context.js";
11
+ import { PortalService } from "../../../infrastructure/services/portal-service.js";
12
+ export class ContentContext {
13
+ constructor(contentDirectory) {
14
+ this.contentDirectory = contentDirectory;
15
+ this.fileService = new FileService();
73
16
  }
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());
17
+ async exists() {
18
+ return this.fileService.directoryExists(this.contentDirectory);
82
19
  }
83
- async getDestinationPath(buildDirectory, providedTocDirectory) {
84
- if (providedTocDirectory === undefined) {
85
- const inferredDestination = await this.getContentFolderPath(buildDirectory);
86
- return inferredDestination;
87
- }
88
- return providedTocDirectory;
20
+ async extractContentGroups() {
21
+ const directory = await this.fileService.getDirectory(this.contentDirectory);
22
+ return await directory.parseContentFolder(this.contentDirectory);
89
23
  }
90
- async checkExistingToc(tocPath, force) {
91
- if ((await fsExtra.pathExists(tocPath.toString())) && !force) {
92
- return await this.prompts.overwriteExistingTocPrompt(tocPath);
93
- }
94
- return true;
24
+ }
25
+ export class PortalNewTocAction {
26
+ constructor(configDirectory, commandMetadata) {
27
+ this.configDirectory = configDirectory;
28
+ this.commandMetadata = commandMetadata;
29
+ this.prompts = new PortalNewTocPrompts();
30
+ this.tocGenerator = new TocStructureGenerator();
31
+ this.fileService = new FileService();
32
+ this.portalService = new PortalService();
95
33
  }
96
- async getContentFolderPath(buildDirectory) {
97
- var _a;
34
+ async execute(buildDirectory, tocDirectory, force = false, expandEndpoints = false, expandModels = false) {
35
+ var _a, _b;
36
+ // Validate build directory
98
37
  const buildContext = new BuildContext(buildDirectory);
99
- const defaultContentFolder = buildDirectory.join("content");
100
38
  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");
39
+ this.prompts.invalidBuildDirectory(buildDirectory);
40
+ return ActionResult.failed();
109
41
  }
110
- catch (_b) {
111
- return defaultContentFolder;
42
+ const buildConfig = await buildContext.getBuildFileContents();
43
+ const contentDirectory = buildDirectory.join((_b = (_a = buildConfig.generatePortal) === null || _a === void 0 ? void 0 : _a.contentFolder) !== null && _b !== void 0 ? _b : "content");
44
+ const tocDir = tocDirectory !== null && tocDirectory !== void 0 ? tocDirectory : contentDirectory;
45
+ const tocContext = new TocContext(tocDir);
46
+ if (!force && (await tocContext.exists()) && !(await this.prompts.overwriteToc(tocContext.tocPath))) {
47
+ this.prompts.tocFileAlreadyExists();
48
+ return ActionResult.cancelled();
112
49
  }
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;
50
+ let sdlComponents = { endpointGroups: new Map(), models: [] };
51
+ if (expandEndpoints || expandModels) {
52
+ const specDirectory = buildDirectory.join("spec");
53
+ if (!(await this.fileService.directoryExists(specDirectory))) {
54
+ this.prompts.fallingBackToDefault();
55
+ }
56
+ else {
57
+ const sdlResult = await withDirPath(async (tempDirectory) => {
58
+ const tempContext = new TempContext(tempDirectory);
59
+ const specZipPath = await tempContext.zip(specDirectory);
60
+ const specFileStream = await this.fileService.getStream(specZipPath);
61
+ try {
62
+ const result = await this.prompts.extractEndpointGroupsAndModels(this.portalService.generateSdl(specFileStream, this.configDirectory, this.commandMetadata));
63
+ if (result.isErr()) {
64
+ this.prompts.fallingBackToDefault();
65
+ return ok({ endpointGroups: new Map(), models: [] });
66
+ }
67
+ return ok(getEndpointGroupsAndModels(result.value));
68
+ }
69
+ finally {
70
+ specFileStream.close();
71
+ }
72
+ });
73
+ if (sdlResult.isErr()) {
74
+ this.prompts.logError(sdlResult.error);
75
+ return ActionResult.failed();
76
+ }
77
+ sdlComponents = sdlResult.value;
125
78
  }
126
- return path.join(buildDirectory.toString(), buildConfig.generatePortal.apiSpecPath);
127
79
  }
128
- catch (_b) {
129
- return defaultSpecFolder;
80
+ const contentContext = new ContentContext(contentDirectory);
81
+ const contentExists = await contentContext.exists();
82
+ let contentGroups;
83
+ if (!contentExists) {
84
+ this.prompts.contentDirectoryNotFound(contentDirectory);
85
+ contentGroups = [];
86
+ }
87
+ else {
88
+ contentGroups = await contentContext.extractContentGroups();
130
89
  }
90
+ const toc = this.tocGenerator.createTocStructure(sdlComponents.endpointGroups, sdlComponents.models, expandEndpoints, expandModels, contentGroups);
91
+ const yamlString = this.tocGenerator.transformToYaml(toc);
92
+ const tocFilePath = await tocContext.save(yamlString);
93
+ this.prompts.tocCreated(tocFilePath);
94
+ return ActionResult.success();
131
95
  }
132
96
  }
133
97
  //# sourceMappingURL=new-toc.js.map
@@ -1 +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,IAAI,CAAC,aAAa,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAC9C,CAAC;IAEM,KAAK,CAA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C9B,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;YACxD,aAAa,GAAG,EAAE,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,aAAa,GAAG,MAAM,cAAc,CAAC,oBAAoB,EAAE,CAAC;QAC9D,CAAC;QAGD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAC9C,aAAa,CAAC,cAAc,EAC5B,aAAa,CAAC,MAAM,EACpB,eAAe,EACf,YAAY,EACZ,aAAa,CACd,CAAC;QAEF,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAC1D,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAGtD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;QAEpC,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;CACF"}
@@ -1,14 +1,13 @@
1
1
  import { DirectoryPath } from "../../types/file/directoryPath.js";
2
2
  import { ActionResult } from "../action-result.js";
3
- import { LanguagePlatform } from "../../types/sdk/generate.js";
3
+ import { CommandMetadata } from "../../types/common/command-metadata.js";
4
+ import { Language } from "../../types/sdk/generate.js";
4
5
  export declare class GenerateAction {
5
6
  private readonly prompts;
6
- private readonly zipArchiver;
7
- private readonly fileService;
8
7
  private readonly portalService;
9
8
  private readonly configDir;
9
+ private readonly commandMetadata;
10
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;
11
+ constructor(configDir: DirectoryPath, commandMetadata: CommandMetadata, authKey?: string | null);
12
+ readonly execute: (specDirectory: DirectoryPath, sdkDirectory: DirectoryPath, language: Language, force: boolean, zipSdk: boolean) => Promise<ActionResult>;
14
13
  }
@@ -1,72 +1,47 @@
1
- import { ZipService } from "../../infrastructure/zip-service.js";
2
- import { FileService } from "../../infrastructure/file-service.js";
3
1
  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
2
  import { ActionResult } from "../action-result.js";
7
3
  import { withDirPath } from "../../infrastructure/tmp-extensions.js";
8
4
  import { SdkContext } from "../../types/sdk-context.js";
9
- import { Platforms } from "@apimatic/sdk";
10
5
  import { SpecContext } from "../../types/spec-context.js";
11
6
  import { SdkGeneratePrompts } from "../../prompts/sdk/generate.js";
12
- import { LanguagePlatform } from "../../types/sdk/generate.js";
7
+ import { TempContext } from "../../types/temp-context.js";
13
8
  export class GenerateAction {
14
- constructor(configDir, authKey = null) {
9
+ constructor(configDir, commandMetadata, authKey = null) {
15
10
  this.prompts = new SdkGeneratePrompts();
16
- this.zipArchiver = new ZipService();
17
- this.fileService = new FileService();
18
11
  this.portalService = new PortalService();
19
- this.execute = async (specDirectory, sdkDirectory, platform, commandName, force, zipSdk) => {
12
+ this.execute = async (specDirectory, sdkDirectory, language, force, zipSdk) => {
20
13
  if (specDirectory.isEqual(sdkDirectory)) {
21
- return ActionResult.error(`The spec directory and sdk directory cannot be the same: "${specDirectory}"`);
14
+ this.prompts.sameSpecAndSdkDir(specDirectory);
15
+ return ActionResult.failed();
22
16
  }
23
17
  const specContext = new SpecContext(specDirectory);
24
18
  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.`);
19
+ this.prompts.invalidSpecDirectory(specDirectory);
20
+ return ActionResult.failed();
26
21
  }
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.");
22
+ const sdkContext = new SdkContext(sdkDirectory, language);
23
+ if (!force && (await sdkContext.exists()) && !(await this.prompts.overwriteSdk(sdkContext.sdkLanguageDirectory))) {
24
+ this.prompts.destinationDirNotEmpty();
25
+ return ActionResult.cancelled();
30
26
  }
31
27
  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);
28
+ const tempContext = new TempContext(tempDirectory);
29
+ const specZipPath = await tempContext.zip(specDirectory);
30
+ const response = await this.prompts.generateSDK(this.portalService.generateSdk(specZipPath, language, this.configDir, this.commandMetadata, this.authKey));
31
+ // TODO: this should be service error
32
+ if (response.isErr()) {
33
+ this.prompts.logGenerationError(response.error);
34
+ return ActionResult.failed();
40
35
  }
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();
36
+ const tempSdkFilePath = await tempContext.save(response.value);
37
+ const sdkLanguageDirectory = await sdkContext.save(tempSdkFilePath, zipSdk);
38
+ this.prompts.sdkGenerated(sdkLanguageDirectory);
45
39
  return ActionResult.success();
46
40
  });
47
41
  };
48
42
  this.configDir = configDir;
43
+ this.commandMetadata = commandMetadata;
49
44
  this.authKey = authKey;
50
45
  }
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
46
  }
72
47
  //# sourceMappingURL=generate.js.map
@@ -1 +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,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,MAAM,OAAO,cAAc;IAQzB,YAAY,SAAwB,EAAE,UAAyB,IAAI;QAPlD,YAAO,GAAuB,IAAI,kBAAkB,EAAE,CAAC;QACvD,gBAAW,GAAe,IAAI,UAAU,EAAE,CAAC;QAC3C,gBAAW,GA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