@apimatic/cli 1.1.0-alpha.13 → 1.1.0-alpha.15

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 (209) hide show
  1. package/README.md +96 -95
  2. package/lib/actions/action-result.d.ts +8 -0
  3. package/lib/actions/action-result.js +25 -0
  4. package/lib/actions/action-result.js.map +1 -0
  5. package/lib/actions/auth/login.d.ts +12 -0
  6. package/lib/actions/auth/login.js +63 -0
  7. package/lib/actions/auth/login.js.map +1 -0
  8. package/lib/actions/portal/copilot.d.ts +11 -0
  9. package/lib/actions/portal/copilot.js +46 -0
  10. package/lib/actions/portal/copilot.js.map +1 -0
  11. package/lib/actions/portal/generate.d.ts +11 -5
  12. package/lib/actions/portal/generate.js +54 -47
  13. package/lib/actions/portal/generate.js.map +1 -1
  14. package/lib/actions/portal/recipe/new-recipe.d.ts +3 -3
  15. package/lib/actions/portal/recipe/new-recipe.js +18 -31
  16. package/lib/actions/portal/recipe/new-recipe.js.map +1 -1
  17. package/lib/actions/portal/serve.d.ts +17 -0
  18. package/lib/actions/portal/serve.js +36 -0
  19. package/lib/actions/portal/serve.js.map +1 -0
  20. package/lib/actions/portal/toc/new-toc.d.ts +4 -1
  21. package/lib/actions/portal/toc/new-toc.js +37 -34
  22. package/lib/actions/portal/toc/new-toc.js.map +1 -1
  23. package/lib/actions/sdk/generate.d.ts +13 -0
  24. package/lib/actions/sdk/generate.js +49 -0
  25. package/lib/actions/sdk/generate.js.map +1 -0
  26. package/lib/application/portal/serve/portal-watcher.d.ts +11 -0
  27. package/lib/application/portal/serve/portal-watcher.js +67 -0
  28. package/lib/application/portal/serve/portal-watcher.js.map +1 -0
  29. package/lib/application/portal/serve/serve-handler.d.ts +16 -0
  30. package/lib/application/portal/serve/serve-handler.js +91 -0
  31. package/lib/application/portal/serve/serve-handler.js.map +1 -0
  32. package/lib/application/portal/serve/watcher-handler.d.ts +10 -0
  33. package/lib/application/portal/serve/watcher-handler.js +51 -0
  34. package/lib/application/portal/serve/watcher-handler.js.map +1 -0
  35. package/lib/application/portal/toc/sdl-parser.d.ts +2 -1
  36. package/lib/application/portal/toc/sdl-parser.js +4 -4
  37. package/lib/application/portal/toc/sdl-parser.js.map +1 -1
  38. package/lib/client-utils/auth-manager.d.ts +7 -2
  39. package/lib/client-utils/auth-manager.js +24 -7
  40. package/lib/client-utils/auth-manager.js.map +1 -1
  41. package/lib/client-utils/sdk-client.d.ts +0 -1
  42. package/lib/client-utils/sdk-client.js +7 -38
  43. package/lib/client-utils/sdk-client.js.map +1 -1
  44. package/lib/commands/api/transform.d.ts +2 -2
  45. package/lib/commands/api/transform.js +10 -19
  46. package/lib/commands/api/transform.js.map +1 -1
  47. package/lib/commands/api/validate.d.ts +1 -1
  48. package/lib/commands/api/validate.js +5 -13
  49. package/lib/commands/api/validate.js.map +1 -1
  50. package/lib/commands/auth/login.d.ts +2 -1
  51. package/lib/commands/auth/login.js +19 -65
  52. package/lib/commands/auth/login.js.map +1 -1
  53. package/lib/commands/auth/logout.js +2 -6
  54. package/lib/commands/auth/logout.js.map +1 -1
  55. package/lib/commands/auth/status.js +3 -6
  56. package/lib/commands/auth/status.js.map +1 -1
  57. package/lib/commands/portal/copilot.d.ts +12 -0
  58. package/lib/commands/portal/copilot.js +35 -0
  59. package/lib/commands/portal/copilot.js.map +1 -0
  60. package/lib/commands/portal/generate.d.ts +7 -10
  61. package/lib/commands/portal/generate.js +18 -83
  62. package/lib/commands/portal/generate.js.map +1 -1
  63. package/lib/commands/portal/quickstart.d.ts +2 -2
  64. package/lib/commands/portal/quickstart.js +58 -29
  65. package/lib/commands/portal/quickstart.js.map +1 -1
  66. package/lib/commands/portal/recipe/new.d.ts +1 -3
  67. package/lib/commands/portal/recipe/new.js +21 -27
  68. package/lib/commands/portal/recipe/new.js.map +1 -1
  69. package/lib/commands/portal/serve.d.ts +7 -6
  70. package/lib/commands/portal/serve.js +62 -112
  71. package/lib/commands/portal/serve.js.map +1 -1
  72. package/lib/commands/portal/toc/new.d.ts +4 -5
  73. package/lib/commands/portal/toc/new.js +26 -37
  74. package/lib/commands/portal/toc/new.js.map +1 -1
  75. package/lib/commands/sdk/generate.d.ts +8 -6
  76. package/lib/commands/sdk/generate.js +53 -124
  77. package/lib/commands/sdk/generate.js.map +1 -1
  78. package/lib/controllers/portal/quickstart.d.ts +0 -2
  79. package/lib/controllers/portal/quickstart.js +2 -60
  80. package/lib/controllers/portal/quickstart.js.map +1 -1
  81. package/lib/infrastructure/api-utils.d.ts +9 -0
  82. package/lib/infrastructure/api-utils.js +33 -0
  83. package/lib/infrastructure/api-utils.js.map +1 -0
  84. package/lib/infrastructure/env-info.d.ts +8 -0
  85. package/lib/infrastructure/env-info.js +37 -0
  86. package/lib/infrastructure/env-info.js.map +1 -0
  87. package/lib/infrastructure/file-service.d.ts +15 -0
  88. package/lib/infrastructure/file-service.js +61 -0
  89. package/lib/infrastructure/file-service.js.map +1 -0
  90. package/lib/infrastructure/services/api-service.d.ts +10 -0
  91. package/lib/infrastructure/services/api-service.js +52 -0
  92. package/lib/infrastructure/services/api-service.js.map +1 -0
  93. package/lib/infrastructure/services/auth-service.d.ts +11 -0
  94. package/lib/infrastructure/services/auth-service.js +33 -0
  95. package/lib/infrastructure/services/auth-service.js.map +1 -0
  96. package/lib/infrastructure/services/portal-service.d.ts +7 -4
  97. package/lib/infrastructure/services/portal-service.js +70 -49
  98. package/lib/infrastructure/services/portal-service.js.map +1 -1
  99. package/lib/infrastructure/services/telemetry-service.d.ts +8 -0
  100. package/lib/infrastructure/services/telemetry-service.js +40 -0
  101. package/lib/infrastructure/services/telemetry-service.js.map +1 -0
  102. package/lib/infrastructure/tmp-extensions.d.ts +2 -0
  103. package/lib/infrastructure/tmp-extensions.js +6 -0
  104. package/lib/infrastructure/tmp-extensions.js.map +1 -0
  105. package/lib/infrastructure/zip-service.d.ts +6 -0
  106. package/lib/infrastructure/zip-service.js +25 -0
  107. package/lib/infrastructure/zip-service.js.map +1 -0
  108. package/lib/prompts/auth/login.d.ts +5 -0
  109. package/lib/prompts/auth/login.js +13 -0
  110. package/lib/prompts/auth/login.js.map +1 -0
  111. package/lib/prompts/portal/common/base-prompts.d.ts +7 -0
  112. package/lib/prompts/portal/common/base-prompts.js +19 -0
  113. package/lib/prompts/portal/common/base-prompts.js.map +1 -0
  114. package/lib/prompts/portal/copilot.d.ts +6 -0
  115. package/lib/prompts/portal/copilot.js +35 -0
  116. package/lib/prompts/portal/copilot.js.map +1 -0
  117. package/lib/prompts/portal/generate.d.ts +3 -2
  118. package/lib/prompts/portal/generate.js +21 -36
  119. package/lib/prompts/portal/generate.js.map +1 -1
  120. package/lib/prompts/portal/quickstart.d.ts +8 -9
  121. package/lib/prompts/portal/quickstart.js +44 -32
  122. package/lib/prompts/portal/quickstart.js.map +1 -1
  123. package/lib/prompts/portal/recipe/new-recipe.d.ts +1 -0
  124. package/lib/prompts/portal/recipe/new-recipe.js +18 -8
  125. package/lib/prompts/portal/recipe/new-recipe.js.map +1 -1
  126. package/lib/prompts/portal/serve.d.ts +4 -6
  127. package/lib/prompts/portal/serve.js +24 -15
  128. package/lib/prompts/portal/serve.js.map +1 -1
  129. package/lib/prompts/portal/toc/new-toc.d.ts +3 -2
  130. package/lib/prompts/portal/toc/new-toc.js +11 -14
  131. package/lib/prompts/portal/toc/new-toc.js.map +1 -1
  132. package/lib/prompts/sdk/generate.d.ts +11 -0
  133. package/lib/prompts/sdk/generate.js +42 -0
  134. package/lib/prompts/sdk/generate.js.map +1 -0
  135. package/lib/types/api/account.d.ts +10 -0
  136. package/lib/types/api/account.js +2 -0
  137. package/lib/types/api/account.js.map +1 -0
  138. package/lib/types/build/build.d.ts +14 -0
  139. package/lib/types/build/build.js +4 -0
  140. package/lib/types/build/build.js.map +1 -0
  141. package/lib/types/build-context.d.ts +13 -0
  142. package/lib/types/build-context.js +30 -0
  143. package/lib/types/build-context.js.map +1 -0
  144. package/lib/types/events/domain-event.d.ts +8 -0
  145. package/lib/types/events/domain-event.js +11 -0
  146. package/lib/types/events/domain-event.js.map +1 -0
  147. package/lib/types/events/recipe-creation-failed.d.ts +5 -0
  148. package/lib/types/events/recipe-creation-failed.js +8 -0
  149. package/lib/types/events/recipe-creation-failed.js.map +1 -0
  150. package/lib/types/events/toc-creation-failed.d.ts +5 -0
  151. package/lib/types/events/toc-creation-failed.js +8 -0
  152. package/lib/types/events/toc-creation-failed.js.map +1 -0
  153. package/lib/types/file/directoryPath.d.ts +7 -0
  154. package/lib/types/file/directoryPath.js +16 -0
  155. package/lib/types/file/directoryPath.js.map +1 -0
  156. package/lib/types/file/fileName.d.ts +5 -0
  157. package/lib/types/file/fileName.js +9 -0
  158. package/lib/types/file/fileName.js.map +1 -0
  159. package/lib/types/file/filePath.d.ts +8 -0
  160. package/lib/types/file/filePath.js +11 -0
  161. package/lib/types/file/filePath.js.map +1 -0
  162. package/lib/types/flags-provider.d.ts +15 -0
  163. package/lib/types/flags-provider.js +34 -0
  164. package/lib/types/flags-provider.js.map +1 -0
  165. package/lib/types/portal/generate.d.ts +0 -13
  166. package/lib/types/portal/quickstart.d.ts +1 -1
  167. package/lib/types/portal/serve.d.ts +13 -0
  168. package/lib/types/portal/serve.js +2 -0
  169. package/lib/types/portal/serve.js.map +1 -0
  170. package/lib/types/portal-context.d.ts +11 -0
  171. package/lib/types/portal-context.js +28 -0
  172. package/lib/types/portal-context.js.map +1 -0
  173. package/lib/types/sdk/generate.d.ts +8 -8
  174. package/lib/types/sdk/generate.js +10 -10
  175. package/lib/types/sdk/generate.js.map +1 -1
  176. package/lib/types/sdk-context.d.ts +13 -0
  177. package/lib/types/sdk-context.js +28 -0
  178. package/lib/types/sdk-context.js.map +1 -0
  179. package/lib/types/spec-context.d.ts +7 -0
  180. package/lib/types/spec-context.js +12 -0
  181. package/lib/types/spec-context.js.map +1 -0
  182. package/lib/utils/utils.d.ts +1 -4
  183. package/lib/utils/utils.js +18 -32
  184. package/lib/utils/utils.js.map +1 -1
  185. package/lib/validators/common/directoryValidator.d.ts +3 -7
  186. package/lib/validators/common/directoryValidator.js +10 -37
  187. package/lib/validators/common/directoryValidator.js.map +1 -1
  188. package/lib/validators/portal/serve-validator.d.ts +6 -0
  189. package/lib/validators/portal/serve-validator.js +15 -0
  190. package/lib/validators/portal/serve-validator.js.map +1 -0
  191. package/package.json +6 -3
  192. package/lib/controllers/portal/generate.d.ts +0 -3
  193. package/lib/controllers/portal/generate.js +0 -106
  194. package/lib/controllers/portal/generate.js.map +0 -1
  195. package/lib/controllers/portal/serve.d.ts +0 -3
  196. package/lib/controllers/portal/serve.js +0 -136
  197. package/lib/controllers/portal/serve.js.map +0 -1
  198. package/lib/controllers/sdk/generate.d.ts +0 -4
  199. package/lib/controllers/sdk/generate.js +0 -61
  200. package/lib/controllers/sdk/generate.js.map +0 -1
  201. package/lib/services/portal/server.d.ts +0 -14
  202. package/lib/services/portal/server.js +0 -97
  203. package/lib/services/portal/server.js.map +0 -1
  204. package/lib/validators/common/portValidator.d.ts +0 -5
  205. package/lib/validators/common/portValidator.js +0 -16
  206. package/lib/validators/common/portValidator.js.map +0 -1
  207. package/lib/validators/portal/serveValidator.d.ts +0 -6
  208. package/lib/validators/portal/serveValidator.js +0 -17
  209. package/lib/validators/portal/serveValidator.js.map +0 -1
@@ -1,9 +1,17 @@
1
+ import getPort from "get-port";
1
2
  import { Command } from "@oclif/core";
2
3
  import { ApiValidationExternalApisController } from "@apimatic/sdk";
3
4
  import { SDKClient } from "../../client-utils/sdk-client.js";
4
5
  import { PortalQuickstartPrompts } from "../../prompts/portal/quickstart.js";
5
6
  import { PortalQuickstartController } from "../../controllers/portal/quickstart.js";
6
7
  import { getMessageInRedColor } from "../../utils/utils.js";
8
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
9
+ import { PortalServeAction } from "../../actions/portal/serve.js";
10
+ import { ServeHandler } from "../../application/portal/serve/serve-handler.js";
11
+ import { PortalService } from "../../infrastructure/services/portal-service.js";
12
+ import { PortalServePrompts } from "../../prompts/portal/serve.js";
13
+ import { GenerateAction } from "../../actions/portal/generate.js";
14
+ import { LoginAction } from "../../actions/auth/login.js";
7
15
  class PortalQuickstart extends Command {
8
16
  async getSpecFile(prompts, controller) {
9
17
  const specPath = await prompts.specPrompt();
@@ -22,36 +30,27 @@ class PortalQuickstart extends Command {
22
30
  }
23
31
  return apiValidationSummary;
24
32
  }
25
- async getBuildDirectory(prompts, controller, specFile, apiValidationSummary, languages) {
26
- const buildDirectoryPath = await prompts.buildDirectoryPrompt();
33
+ async getWorkingDirectory(prompts, controller, specFile, apiValidationSummary, languages) {
34
+ const workingDirectory = await prompts.workingDirectoryPrompt();
27
35
  prompts.displayBuildDirectoryGenerationMessage();
28
- await controller.setupBuildDirectory(prompts, buildDirectoryPath, specFile, apiValidationSummary, languages);
29
- prompts.displayBuildDirectoryGenerationSuccessMessage(buildDirectoryPath);
30
- prompts.displayBuildDirectoryAsTree(buildDirectoryPath);
31
- return buildDirectoryPath;
32
- }
33
- async getGeneratedPortalPath(prompts, controller, directory) {
34
- prompts.displayPortalGenerationMessage();
35
- const generatedPortalPath = await controller.generatePortalArtifacts(directory, this.config.configDir);
36
- prompts.displayPortalGenerationSuccessMessage();
37
- return generatedPortalPath;
36
+ const buildDirectory = new DirectoryPath(workingDirectory, "src").toString();
37
+ await controller.setupBuildDirectory(prompts, buildDirectory, specFile, apiValidationSummary, languages);
38
+ prompts.displayBuildDirectoryGenerationSuccessMessage(buildDirectory);
39
+ prompts.displayBuildDirectoryAsTree(buildDirectory);
40
+ return workingDirectory;
38
41
  }
39
42
  async run() {
40
43
  const prompts = new PortalQuickstartPrompts();
41
44
  const controller = new PortalQuickstartController();
42
45
  prompts.displayWelcomeMessage();
43
46
  let loggedIn = await controller.isUserAuthenticated(this.config.configDir);
44
- while (!loggedIn) {
45
- const credentials = await prompts.loginPrompt();
46
- prompts.displayLoggingInMessage();
47
- try {
48
- await controller.userLogin(credentials, SDKClient.getInstance(), this.config.configDir);
49
- loggedIn = true;
50
- prompts.displayLoggedInMessage();
51
- }
52
- catch (error) {
53
- prompts.displayLoggingInErrorMessage();
54
- }
47
+ if (!loggedIn) {
48
+ prompts.getLoggedInFirst();
49
+ const loginAction = new LoginAction(new DirectoryPath(this.config.configDir));
50
+ const loginResult = await loginAction.execute();
51
+ loginResult.match(e => prompts.displayLoggedInMessage(e), error => prompts.logError(error));
52
+ if (loginResult.isErr())
53
+ return;
55
54
  }
56
55
  const client = await SDKClient.getInstance().getClient(null, this.config.configDir);
57
56
  const apiValidationController = new ApiValidationExternalApisController(client);
@@ -59,19 +58,49 @@ class PortalQuickstart extends Command {
59
58
  const specFile = await this.getSpecFile(prompts, controller);
60
59
  const apiValidationSummary = await this.getSpecValidationSummary(prompts, controller, specFile, apiValidationController);
61
60
  const languages = await prompts.sdkLanguagesPrompt();
62
- const directory = await this.getBuildDirectory(prompts, controller, specFile, apiValidationSummary, languages);
63
- const generatedPortalPath = await this.getGeneratedPortalPath(prompts, controller, directory);
64
- const serverStarted = await controller.servePortal(generatedPortalPath, directory, this.config.configDir);
65
- if (serverStarted) {
66
- prompts.displayOutroMessage(directory);
61
+ const workingDirectory = await this.getWorkingDirectory(prompts, controller, specFile, apiValidationSummary, languages);
62
+ const portalServePrompts = new PortalServePrompts();
63
+ const portalServeAction = new PortalServeAction(portalServePrompts, new ServeHandler(), new PortalService());
64
+ //TODO: This needs to be moved within the action. Port should not be initialized again here.
65
+ const port = await this.getServerPort(3000);
66
+ const buildDirectory = new DirectoryPath(workingDirectory, "src");
67
+ const portalDirectory = new DirectoryPath(workingDirectory, "portal");
68
+ const generatePortalAction = new GenerateAction(new DirectoryPath(this.config.configDir), null);
69
+ const serveFlags = {
70
+ folder: buildDirectory.toString(),
71
+ destination: portalDirectory.toString(),
72
+ port: port,
73
+ open: true,
74
+ "no-reload": false,
75
+ ignore: "",
76
+ "auth-key": undefined
77
+ };
78
+ const serverPaths = {
79
+ sourceDirectoryPath: buildDirectory.toString(),
80
+ destinationDirectoryPath: portalDirectory.toString()
81
+ };
82
+ const servePortalResult = await portalServeAction.servePortal(serveFlags, serverPaths, generatePortalAction.execute);
83
+ if (servePortalResult.isFailed()) {
84
+ portalServePrompts.logError(getMessageInRedColor(servePortalResult.error));
85
+ return;
67
86
  }
87
+ if (servePortalResult.isCancelled()) {
88
+ portalServePrompts.logError(getMessageInRedColor(servePortalResult.value));
89
+ return;
90
+ }
91
+ prompts.displayOutroMessage(buildDirectory.toString());
68
92
  }
69
93
  catch (error) {
70
94
  this.error(getMessageInRedColor(error instanceof Error ? error.message : String(error)));
71
95
  }
72
96
  }
97
+ async getServerPort(port) {
98
+ const defaultPorts = [3000, 3001, 3002];
99
+ const preferredPorts = typeof port === "number" ? [port, ...defaultPorts.filter((p) => p !== port)] : defaultPorts;
100
+ return await getPort({ port: preferredPorts });
101
+ }
73
102
  }
74
103
  PortalQuickstart.description = "Create your first API Portal using APIMatic's Docs as Code offering.";
75
- PortalQuickstart.examples = ["$ apimatic portal:quickstart"];
104
+ PortalQuickstart.examples = ["apimatic portal:quickstart"];
76
105
  export default PortalQuickstart;
77
106
  //# sourceMappingURL=quickstart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"quickstart.js","sourceRoot":"","sources":["../../../src/commands/portal/quickstart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,mCAAmC,EAAgC,MAAM,eAAe,CAAC;AAClG,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AAEpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAqB,gBAAiB,SAAQ,OAAO;IAK3C,KAAK,CAAC,WAAW,CACvB,OAAgC,EAChC,UAAsC;QAEtC,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,UAAU,EAAE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C,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;QAEnH,OAAO,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;IACjD,CAAC;;AA9JM,4BAAW,GAAG,sEAAsE,CAAC;AAErF,yBAAQ,GAAG,CAAC,4BAA4B,CAAC,CAAC;eAH9B,gBAAgB"}
@@ -1,12 +1,10 @@
1
1
  import { Command } from "@oclif/core";
2
- export default class PortalNewRecipe extends Command {
2
+ export default class PortalRecipeNew extends Command {
3
3
  static summary: string;
4
4
  static description: string;
5
5
  static examples: string[];
6
6
  static flags: {
7
7
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
- folder: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
9
- "build-config": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
8
  };
11
9
  run(): Promise<void>;
12
10
  }
@@ -1,17 +1,25 @@
1
- var _a;
2
- import * as path from "path";
3
1
  import { Command, Flags } from "@oclif/core";
4
2
  import { PortalRecipeAction } from "../../../actions/portal/recipe/new-recipe.js";
5
3
  import { PortalRecipePrompts } from "../../../prompts/portal/recipe/new-recipe.js";
6
4
  import { getMessageInRedColor } from "../../../utils/utils.js";
7
- const DEFAULT_FOLDER = process.cwd();
8
- class PortalNewRecipe extends Command {
5
+ import { TelemetryService } from "../../../infrastructure/services/telemetry-service.js";
6
+ import { RecipeCreationFailedEvent } from "../../../types/events/recipe-creation-failed.js";
7
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
8
+ import { FlagsProvider } from "../../../types/flags-provider.js";
9
+ const DEFAULT_WORKING_DIRECTORY = "./";
10
+ class PortalRecipeNew extends Command {
9
11
  async run() {
10
- const { flags } = await this.parse(_a);
12
+ var _a;
13
+ const { flags } = await this.parse(PortalRecipeNew);
14
+ const telemetryService = new TelemetryService(this.config.configDir);
11
15
  const portalRecipeAction = new PortalRecipeAction();
12
16
  const portalRecipePrompts = new PortalRecipePrompts();
13
- const createRecipeResult = await portalRecipeAction.createRecipe(flags.folder, this.config.configDir, flags["build-config"], flags.name);
17
+ const workingDirectory = new DirectoryPath((_a = flags.input) !== null && _a !== void 0 ? _a : DEFAULT_WORKING_DIRECTORY);
18
+ const buildDirectory = flags.input ? new DirectoryPath(flags.input, "src") : workingDirectory.join("src");
19
+ const createRecipeResult = await portalRecipeAction.createRecipe(buildDirectory, this.config.configDir, flags.name);
20
+ //TODO: Add a mapper for automatically mapping events to logger and telemetry service.
14
21
  if (createRecipeResult.isFailed()) {
22
+ telemetryService.trackEvent(new RecipeCreationFailedEvent(createRecipeResult.error, PortalRecipeNew.id, flags));
15
23
  portalRecipePrompts.logError(getMessageInRedColor(createRecipeResult.error));
16
24
  }
17
25
  if (createRecipeResult.isCancelled()) {
@@ -19,26 +27,12 @@ class PortalNewRecipe extends Command {
19
27
  }
20
28
  }
21
29
  }
22
- _a = PortalNewRecipe;
23
- PortalNewRecipe.summary = "Generate an API Recipe for a static API Documentation portal.";
24
- PortalNewRecipe.description = "To learn more about API Recipes, visit: https://docs.apimatic.io/platform-api/#/http/guides/generating-on-prem-api-portal/api-recipes";
25
- PortalNewRecipe.examples = [
26
- `$ apimatic portal:recipe:new --name="My API Recipe" --folder="./build-folder" --build-config-file="./build-folder/APIMATIC-BUILD.json"
27
- Generated recipe has been added to build directory at: C:/build-folder/`,
28
- `$ apimatic portal:recipe:new
29
- Generated recipe has been added to build directory at: C:/`
30
+ PortalRecipeNew.summary = "Generate an API Recipe for a static API Documentation portal.";
31
+ PortalRecipeNew.description = "To learn more about API Recipes, visit: https://docs.apimatic.io/platform-api/#/http/guides/generating-on-prem-api-portal/api-recipes";
32
+ PortalRecipeNew.examples = [
33
+ `apimatic portal:recipe:new`,
34
+ `apimatic portal:recipe:new --name="My API Recipe" --input="./"`
30
35
  ];
31
- PortalNewRecipe.flags = {
32
- name: Flags.string({ description: "name for the recipe" }),
33
- folder: Flags.string({
34
- parse: async (input) => path.resolve(input),
35
- description: "path to the build directory containing the specs folder, content folder, and the build config file. Defaults to the current working directory if not provided.",
36
- default: DEFAULT_FOLDER
37
- }),
38
- "build-config": Flags.string({
39
- parse: async (input) => path.resolve(input),
40
- description: "path to the APIMATIC-BUILD.json file. Defaults to the APIMATIC-BUILD.json file in the build directory if not provided."
41
- })
42
- };
43
- export default PortalNewRecipe;
36
+ PortalRecipeNew.flags = Object.assign({ name: Flags.string({ description: "name for the recipe" }) }, FlagsProvider.input);
37
+ export default PortalRecipeNew;
44
38
  //# sourceMappingURL=new.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"new.js","sourceRoot":"","sources":["../../../../src/commands/portal/recipe/new.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AACrC,MAAqB,eAAgB,SAAQ,OAAO;IA0B3C,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,EAAe,CAAC,CAAC;QACpD,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAC;QACpD,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,EAAE,CAAC;QAEtD,MAAM,kBAAkB,GAAG,MAAM,kBAAkB,CAAC,YAAY,CAC9D,KAAK,CAAC,MAAM,EACZ,IAAI,CAAC,MAAM,CAAC,SAAS,EACrB,KAAK,CAAC,cAAc,CAAC,EACrB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KAAK,CAAC,CAAC,CAAC;YACjH,mBAAmB,CAAC,QAAQ,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,KAAM,CAAC,CAAC,CAAC;QAChF,CAAC;QACD,IAAI,kBAAkB,CAAC,WAAW,EAAE,EAAE,CAAC;YACrC,mBAAmB,CAAC,QAAQ,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,KAAM,CAAC,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;;AAjCe,uBAAO,GAAG,+DAA+D,CAAC;AAE1E,2BAAW,GACzB,uIAAuI,CAAC;AAE1H,wBAAQ,GAAG;IACzB,4BAA4B;IAC5B,gEAAgE;CACjE,CAAC;AACc,qBAAK,mBACnB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC,IACvD,aAAa,CAAC,KAAK,EACtB;eAbiB,eAAe"}
@@ -1,16 +1,17 @@
1
- import { Command } from "@oclif/core";
1
+ import { Command, Config } from "@oclif/core";
2
2
  export default class PortalServe extends Command {
3
3
  static description: string;
4
4
  static flags: {
5
- port: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
6
- destination: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
7
- source: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
5
+ "auth-key": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
6
  open: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
7
  "no-reload": import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
8
  ignore: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
- "auth-key": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ destination: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ port: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
11
  };
12
+ private readonly prompts;
13
+ constructor(argv: string[], config: Config);
13
14
  static examples: string[];
14
15
  run(): Promise<void>;
15
- private handleError;
16
+ private getServerPort;
16
17
  }
@@ -1,135 +1,85 @@
1
- var _a;
2
- import * as path from "path";
3
- import axios from "axios";
1
+ import getPort from "get-port";
4
2
  import { Command, Flags } from "@oclif/core";
5
- import { generatePortal } from "../../controllers/portal/serve.js";
6
- import { PortalServerService } from "../../services/portal/server.js";
7
3
  import { PortalServePrompts } from "../../prompts/portal/serve.js";
8
- import { cleanUpGeneratedPortalFiles, getGeneratedFilesPaths, getMessageInRedColor } from "../../utils/utils.js";
9
- import { PortalServeValidator } from "../../validators/portal/serveValidator.js";
4
+ import { PortalServeAction } from "../../actions/portal/serve.js";
5
+ import { getMessageInRedColor } from "../../utils/utils.js";
6
+ import { ServeHandler } from "../../application/portal/serve/serve-handler.js";
7
+ import { PortalService } from "../../infrastructure/services/portal-service.js";
8
+ import { GenerateAction } from "../../actions/portal/generate.js";
9
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
10
+ import { FlagsProvider } from "../../types/flags-provider.js";
11
+ const DEFAULT_WORKING_DIRECTORY = "./";
10
12
  class PortalServe extends Command {
13
+ constructor(argv, config) {
14
+ super(argv, config);
15
+ this.prompts = new PortalServePrompts();
16
+ }
11
17
  async run() {
12
- var _b;
13
- const { flags } = await this.parse(_a);
14
- const ignoredPaths = flags.ignore.split(",").map((path) => path.trim());
15
- const portalDir = path.resolve(flags.destination);
16
- const sourceDir = path.resolve(flags.source);
17
- const port = flags.port;
18
- const overrideAuthKey = (_b = flags["auth-key"]) !== null && _b !== void 0 ? _b : null;
19
- const serverService = new PortalServerService();
20
- const prompts = new PortalServePrompts();
21
- const validator = new PortalServeValidator(this.error);
22
- const allIgnoredPaths = [...ignoredPaths, ...getGeneratedFilesPaths(sourceDir, portalDir)];
23
- await validator.validate(port, flags.destination, sourceDir, portalDir);
24
- try {
25
- prompts.displayGeneratingPortalMessage();
26
- await generatePortal(sourceDir, portalDir, this.config.configDir, allIgnoredPaths, overrideAuthKey);
27
- prompts.displayGeneratedPortalMessage(portalDir);
28
- await cleanUpGeneratedPortalFiles(sourceDir);
29
- }
30
- catch (error) {
31
- prompts.displayGeneratingPortalErrorMessage();
32
- await cleanUpGeneratedPortalFiles(sourceDir);
33
- this.handleError(error);
18
+ var _a;
19
+ const { flags } = await this.parse(PortalServe);
20
+ const portalServePrompts = new PortalServePrompts();
21
+ const portalServeAction = new PortalServeAction(portalServePrompts, new ServeHandler(), new PortalService());
22
+ //TODO: This needs to be moved within the action. Port should not be initialized again here.
23
+ const port = await this.getServerPort(flags.port);
24
+ const workingDirectory = new DirectoryPath((_a = flags.input) !== null && _a !== void 0 ? _a : DEFAULT_WORKING_DIRECTORY);
25
+ const buildDirectory = flags.input ? new DirectoryPath(flags.input, "src") : workingDirectory.join("src");
26
+ const portalDirectory = flags.destination ? new DirectoryPath(flags.destination) : workingDirectory.join("portal");
27
+ const generatePortalAction = new GenerateAction(new DirectoryPath(this.config.configDir), flags["auth-key"]);
28
+ const serveFlags = {
29
+ folder: buildDirectory.toString(),
30
+ destination: portalDirectory.toString(),
31
+ "auth-key": flags["auth-key"],
32
+ port: port,
33
+ open: flags.open,
34
+ "no-reload": flags["no-reload"],
35
+ ignore: flags.ignore
36
+ };
37
+ const servePaths = {
38
+ sourceDirectoryPath: buildDirectory.toString(),
39
+ destinationDirectoryPath: portalDirectory.toString()
40
+ };
41
+ const servePortalResult = await portalServeAction.servePortal(serveFlags, servePaths, generatePortalAction.execute);
42
+ //TODO: Convert below statements to result.mapAll after changing servePortalResult to ActionResult.
43
+ if (servePortalResult.isFailed()) {
44
+ portalServePrompts.logError(getMessageInRedColor(servePortalResult.error));
34
45
  }
35
- serverService.setupServer(portalDir);
36
- serverService.startServer({
37
- generatedPortalPath: portalDir,
38
- targetFolder: sourceDir,
39
- configDir: this.config.configDir,
40
- authKey: overrideAuthKey,
41
- ignoredPaths: allIgnoredPaths,
42
- port,
43
- openInBrowser: flags.open
44
- }, flags["no-reload"]);
45
- prompts.displayOutroMessage(port);
46
- }
47
- handleError(error) {
48
- if (axios.isAxiosError(error)) {
49
- const axiosError = error;
50
- if (axiosError.response) {
51
- if (axiosError.response.status === 400) {
52
- this.error(getMessageInRedColor(`Failed to generate the portal. Please ensure that the provided build directory follows the correct structure and contains valid API definition and build files.`));
53
- }
54
- else if (axiosError.response.status === 401) {
55
- this.error(getMessageInRedColor(`Failed to generate the portal. Please ensure that you are logged in or have provided a valid Auth key.`));
56
- }
57
- else if (axiosError.response.status === 403) {
58
- this.error(getMessageInRedColor(`Access denied. It looks like you don't have access to APIMatic's Docs as Code offering. Check your subscription details and contact our team at support@apimatic.io if you believe this is a mistake.`));
59
- }
60
- else if (axiosError.response.status === 422) {
61
- this.error(getMessageInRedColor(`Failed to generate the portal. Please ensure that the provided build directory follows the correct structure and contains valid API definition and build files.`));
62
- }
63
- else if (axiosError.response.status === 500) {
64
- this.error(getMessageInRedColor(`Failed to generate the portal. Please ensure that the provided build directory follows the correct structure and contains valid API definition and build files. If the issue persists, reach out to our team at support@apimatic.io`));
65
- }
66
- else {
67
- this.error(getMessageInRedColor(`Failed to generate the portal. Please ensure that the provided build directory follows the correct structure and contains valid API definition and build files. If the issue persists, reach out to our team at support@apimatic.io`));
68
- }
69
- }
70
- else if (axiosError.request) {
71
- if (axiosError.code === "ECONNABORTED") {
72
- this.error(getMessageInRedColor(`Your request timed out. Please try again or reach out to our team at support@apimatic.io for help if your problem persists.`));
73
- }
74
- else if (error.code === "ENOTFOUND" || error.code === "ERR_NETWORK") {
75
- this.error(getMessageInRedColor(`Network error. Please check your internet connection and try again.`));
76
- }
77
- else {
78
- this.error(getMessageInRedColor(`No response received from the server. Please try again later.`));
79
- }
80
- }
81
- else {
82
- this.error(getMessageInRedColor(`Failed to generate the portal: ${axiosError.message}`));
83
- }
46
+ if (servePortalResult.isCancelled()) {
47
+ portalServePrompts.logError(getMessageInRedColor(servePortalResult.value));
84
48
  }
85
- else if (error instanceof Error) {
86
- this.error(getMessageInRedColor(`Failed to generate the portal: ${error.message}`));
49
+ if (servePortalResult.isSuccess()) {
50
+ this.prompts.displayOutroMessage(buildDirectory.toString(), portalDirectory.toString(), port, flags["no-reload"]);
87
51
  }
88
- else {
89
- this.error(getMessageInRedColor(`Something went wrong while generating the portal, please try again later. If the issue persists, contact our team at support@apimatic.io`));
52
+ }
53
+ async getServerPort(port) {
54
+ const defaultPorts = [3000, 3001, 3002];
55
+ const preferredPorts = typeof port === "number" ? [port, ...defaultPorts.filter((p) => p !== port)] : defaultPorts;
56
+ const availablePort = await getPort({ port: preferredPorts });
57
+ // Show warning only if user provided --port and it is not available
58
+ if (typeof port === "number" && availablePort !== port) {
59
+ this.prompts.displayInfo(`⚠️ Port ${port} is already in use. Available port ${availablePort} will be used.`);
90
60
  }
61
+ return availablePort;
91
62
  }
92
63
  }
93
- _a = PortalServe;
94
64
  PortalServe.description = "Generate and deploy a Docs as Code portal with hot reload.";
95
- PortalServe.flags = {
96
- port: Flags.integer({
65
+ PortalServe.flags = Object.assign(Object.assign(Object.assign(Object.assign({ port: Flags.integer({
97
66
  char: "p",
98
- description: "Port to serve the portal.",
99
- default: 3000
100
- }),
101
- destination: Flags.string({
102
- char: "d",
103
- description: "Directory to store and serve the generated portal.",
104
- default: "./generated_portal",
105
- parse: async (input) => path.resolve(input)
106
- }),
107
- source: Flags.string({
108
- char: "s",
109
- description: "Source directory containing specs, content, and build file. By default, the current directory is used.",
110
- default: "./",
111
- parse: async (input) => path.resolve(input)
112
- }),
113
- open: Flags.boolean({
67
+ description: "[default: 3000] port to serve the portal."
68
+ }) }, FlagsProvider.input), FlagsProvider.destination("portal", "portal")), { open: Flags.boolean({
114
69
  char: "o",
115
70
  description: "Open the portal in the default browser.",
116
71
  default: false
117
- }),
118
- "no-reload": Flags.boolean({
72
+ }), "no-reload": Flags.boolean({
119
73
  description: "Disable hot reload.",
120
74
  default: false
121
- }),
122
- ignore: Flags.string({
75
+ }), ignore: Flags.string({
123
76
  char: "i",
124
- description: "Comma-separated list of files/directories to ignore.",
77
+ description: "Comma-separated list of file and directory paths to exclude from portal generation and hot reload.",
125
78
  default: ""
126
- }),
127
- "auth-key": Flags.string({
128
- description: "Override current authentication state with an authentication key."
129
- })
130
- };
79
+ }) }), FlagsProvider.authKey);
131
80
  PortalServe.examples = [
132
- '$ apimatic portal:serve --source="./" --destination="./generated_portal" --port=3000 --open --no-reload'
81
+ "apimatic portal:serve",
82
+ 'apimatic portal:serve --input="./" --destination="./portal" --port=3000 --open --no-reload'
133
83
  ];
134
84
  export default PortalServe;
135
85
  //# sourceMappingURL=serve.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serve.js","sourceRoot":"","sources":["../../../src/commands/portal/serve.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,MAAqB,WAAY,SAAQ,OAAO;IA6C9C,KAAK,CAAC,GAAG;;QACP,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,EAAW,CAAC,CAAC;QAChD,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,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ACT,WAAW,EAAE,oGAAoG;QACjH,OAAO,EAAE,EAAE;KACZ,CAAC,KACC,aAAa,CAAC,OAAO,EACxB;AASK,oBAAQ,GAAG;IAChB,uBAAuB;IACvB,4FAA4F;CAC7F,CAAC;eArCiB,WAAW"}
@@ -1,15 +1,14 @@
1
- import { Command } from "@oclif/core";
1
+ import { Command, Config } from "@oclif/core";
2
2
  export default class PortalTocNew extends Command {
3
3
  static summary: string;
4
4
  static description: string;
5
5
  static flags: {
6
- destination: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
- folder: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
8
- force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
6
  "expand-endpoints": import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
7
  "expand-models": import("@oclif/core/interfaces").BooleanFlag<boolean>;
8
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
+ destination: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
10
  };
12
11
  static examples: string[];
13
- constructor(argv: string[], config: any);
12
+ constructor(argv: string[], config: Config);
14
13
  run(): Promise<void>;
15
14
  }
@@ -1,23 +1,34 @@
1
- var _a;
2
- import * as path from "path";
3
1
  import { Command, Flags } from "@oclif/core";
4
2
  import { PortalNewTocAction } from "../../../actions/portal/toc/new-toc.js";
5
- const DEFAULT_FOLDER = process.cwd();
3
+ import { TelemetryService } from "../../../infrastructure/services/telemetry-service.js";
4
+ import { TocCreationFailedEvent } from "../../../types/events/toc-creation-failed.js";
5
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
6
+ import { FlagsProvider } from "../../../types/flags-provider.js";
7
+ const DEFAULT_WORKING_DIRECTORY = "./";
6
8
  class PortalTocNew extends Command {
7
9
  constructor(argv, config) {
8
10
  super(argv, config);
9
11
  }
10
12
  async run() {
11
- const { flags } = await this.parse(_a);
13
+ var _a;
14
+ const { flags } = await this.parse(PortalTocNew);
15
+ const telemetryService = new TelemetryService(this.config.configDir);
12
16
  const portalNewTocAction = new PortalNewTocAction();
13
- const result = await portalNewTocAction.createToc(flags.folder, this.config.configDir, flags.destination, flags.force, flags["expand-endpoints"], flags["expand-models"]);
17
+ const workingDirectory = new DirectoryPath((_a = flags.input) !== null && _a !== void 0 ? _a : DEFAULT_WORKING_DIRECTORY);
18
+ const buildDirectory = flags.input ? new DirectoryPath(flags.input, "src") : workingDirectory.join("src");
19
+ let tocDirectory;
20
+ if (flags.destination) {
21
+ tocDirectory = new DirectoryPath(flags.destination);
22
+ }
23
+ const result = await portalNewTocAction.createToc(buildDirectory, this.config.configDir, tocDirectory, flags.force, flags["expand-endpoints"], flags["expand-models"]);
24
+ //TODO: Add a mapper for automatically mapping events to logger and telemetry service.
14
25
  if (result.isFailed()) {
26
+ telemetryService.trackEvent(new TocCreationFailedEvent(result.error, PortalTocNew.id, flags));
15
27
  this.error(result.error);
16
28
  }
17
29
  }
18
30
  }
19
- _a = PortalTocNew;
20
- PortalTocNew.summary = 'Generates a TOC file based on the content directory and spec folder provided in your working directory';
31
+ PortalTocNew.summary = "Generates a TOC file based on the content directory and spec folder provided in your working directory";
21
32
  PortalTocNew.description = `This command generates a new Table of Contents (TOC) file used in the
22
33
  generation of your API documentation portal.
23
34
 
@@ -25,39 +36,17 @@ The output is a YAML file with the .yml extension.
25
36
 
26
37
  To learn more about the TOC file and APIMatic build directory structure, visit:
27
38
  https://docs.apimatic.io/platform-api/#/http/guides/generating-on-prem-api-portal/overview-generating-api-portal`;
28
- PortalTocNew.flags = {
29
- destination: Flags.string({
30
- parse: async (input) => path.resolve(input),
31
- description: "optional path where the generated TOC file will be saved. Defaults to the current working directory if not provided.",
32
- }),
33
- folder: Flags.string({
34
- parse: async (input) => path.resolve(input),
35
- description: "path to the working directory containing the API project files. Defaults to the current working directory if not specified.",
36
- default: DEFAULT_FOLDER
37
- }),
38
- force: Flags.boolean({
39
- default: false,
40
- description: "overwrite the TOC file if one already exists at the destination.",
41
- }),
42
- "expand-endpoints": Flags.boolean({
39
+ PortalTocNew.flags = Object.assign(Object.assign(Object.assign(Object.assign({}, FlagsProvider.destination("src/content", `'toc.yml'`)), FlagsProvider.input), FlagsProvider.force), { "expand-endpoints": Flags.boolean({
43
40
  default: false,
44
- description: "include individual entries for each endpoint in the generated TOC. Requires a valid API specification in the working directory."
45
- }),
46
- "expand-models": Flags.boolean({
41
+ description: "include individual entries for each endpoint in the generated 'toc.yml'. Requires a valid API specification in the working directory."
42
+ }), "expand-models": Flags.boolean({
47
43
  default: false,
48
- description: "include individual entries for each model in the generated TOC. Requires a valid API specification in the working directory."
49
- })
50
- };
44
+ description: "include individual entries for each model in the generated 'toc.yml'. Requires a valid API specification in the working directory."
45
+ }) });
51
46
  PortalTocNew.examples = [
52
- `$ apimatic portal:toc:new --destination="./portal/content/"
53
- A new toc file has been created at ./portal/content/toc.yml
54
- `,
55
- `$ apimatic portal:toc:new --folder="./my-project"
56
- A new toc file has been created at ./my-project/content/toc.yml
57
- `,
58
- `$ apimatic portal:toc:new --folder="./my-project" --destination="./portal/content/"
59
- A new toc file has been created at ./portal/content/toc.yml
60
- `
47
+ `apimatic portal:toc:new --destination="./src/content/"`,
48
+ `apimatic portal:toc:new --input="./"`,
49
+ `apimatic portal:toc:new --input="./" --destination="./src/content/"`
61
50
  ];
62
51
  export default PortalTocNew;
63
52
  //# sourceMappingURL=new.js.map