@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.
- package/README.md +96 -95
- package/lib/actions/action-result.d.ts +8 -0
- package/lib/actions/action-result.js +25 -0
- package/lib/actions/action-result.js.map +1 -0
- package/lib/actions/auth/login.d.ts +12 -0
- package/lib/actions/auth/login.js +63 -0
- package/lib/actions/auth/login.js.map +1 -0
- package/lib/actions/portal/copilot.d.ts +11 -0
- package/lib/actions/portal/copilot.js +46 -0
- package/lib/actions/portal/copilot.js.map +1 -0
- package/lib/actions/portal/generate.d.ts +11 -5
- package/lib/actions/portal/generate.js +54 -47
- package/lib/actions/portal/generate.js.map +1 -1
- package/lib/actions/portal/recipe/new-recipe.d.ts +3 -3
- package/lib/actions/portal/recipe/new-recipe.js +18 -31
- package/lib/actions/portal/recipe/new-recipe.js.map +1 -1
- package/lib/actions/portal/serve.d.ts +17 -0
- package/lib/actions/portal/serve.js +36 -0
- package/lib/actions/portal/serve.js.map +1 -0
- package/lib/actions/portal/toc/new-toc.d.ts +4 -1
- package/lib/actions/portal/toc/new-toc.js +37 -34
- package/lib/actions/portal/toc/new-toc.js.map +1 -1
- package/lib/actions/sdk/generate.d.ts +13 -0
- package/lib/actions/sdk/generate.js +49 -0
- package/lib/actions/sdk/generate.js.map +1 -0
- package/lib/application/portal/serve/portal-watcher.d.ts +11 -0
- package/lib/application/portal/serve/portal-watcher.js +67 -0
- package/lib/application/portal/serve/portal-watcher.js.map +1 -0
- package/lib/application/portal/serve/serve-handler.d.ts +16 -0
- package/lib/application/portal/serve/serve-handler.js +91 -0
- package/lib/application/portal/serve/serve-handler.js.map +1 -0
- package/lib/application/portal/serve/watcher-handler.d.ts +10 -0
- package/lib/application/portal/serve/watcher-handler.js +51 -0
- package/lib/application/portal/serve/watcher-handler.js.map +1 -0
- package/lib/application/portal/toc/sdl-parser.d.ts +2 -1
- package/lib/application/portal/toc/sdl-parser.js +4 -4
- package/lib/application/portal/toc/sdl-parser.js.map +1 -1
- package/lib/client-utils/auth-manager.d.ts +7 -2
- package/lib/client-utils/auth-manager.js +24 -7
- package/lib/client-utils/auth-manager.js.map +1 -1
- package/lib/client-utils/sdk-client.d.ts +0 -1
- package/lib/client-utils/sdk-client.js +7 -38
- package/lib/client-utils/sdk-client.js.map +1 -1
- package/lib/commands/api/transform.d.ts +2 -2
- package/lib/commands/api/transform.js +10 -19
- package/lib/commands/api/transform.js.map +1 -1
- package/lib/commands/api/validate.d.ts +1 -1
- package/lib/commands/api/validate.js +5 -13
- package/lib/commands/api/validate.js.map +1 -1
- package/lib/commands/auth/login.d.ts +2 -1
- package/lib/commands/auth/login.js +19 -65
- package/lib/commands/auth/login.js.map +1 -1
- package/lib/commands/auth/logout.js +2 -6
- package/lib/commands/auth/logout.js.map +1 -1
- package/lib/commands/auth/status.js +3 -6
- package/lib/commands/auth/status.js.map +1 -1
- package/lib/commands/portal/copilot.d.ts +12 -0
- package/lib/commands/portal/copilot.js +35 -0
- package/lib/commands/portal/copilot.js.map +1 -0
- package/lib/commands/portal/generate.d.ts +7 -10
- package/lib/commands/portal/generate.js +18 -83
- package/lib/commands/portal/generate.js.map +1 -1
- package/lib/commands/portal/quickstart.d.ts +2 -2
- package/lib/commands/portal/quickstart.js +58 -29
- package/lib/commands/portal/quickstart.js.map +1 -1
- package/lib/commands/portal/recipe/new.d.ts +1 -3
- package/lib/commands/portal/recipe/new.js +21 -27
- package/lib/commands/portal/recipe/new.js.map +1 -1
- package/lib/commands/portal/serve.d.ts +7 -6
- package/lib/commands/portal/serve.js +62 -112
- package/lib/commands/portal/serve.js.map +1 -1
- package/lib/commands/portal/toc/new.d.ts +4 -5
- package/lib/commands/portal/toc/new.js +26 -37
- package/lib/commands/portal/toc/new.js.map +1 -1
- package/lib/commands/sdk/generate.d.ts +8 -6
- package/lib/commands/sdk/generate.js +53 -124
- package/lib/commands/sdk/generate.js.map +1 -1
- package/lib/controllers/portal/quickstart.d.ts +0 -2
- package/lib/controllers/portal/quickstart.js +2 -60
- package/lib/controllers/portal/quickstart.js.map +1 -1
- package/lib/infrastructure/api-utils.d.ts +9 -0
- package/lib/infrastructure/api-utils.js +33 -0
- package/lib/infrastructure/api-utils.js.map +1 -0
- package/lib/infrastructure/env-info.d.ts +8 -0
- package/lib/infrastructure/env-info.js +37 -0
- package/lib/infrastructure/env-info.js.map +1 -0
- package/lib/infrastructure/file-service.d.ts +15 -0
- package/lib/infrastructure/file-service.js +61 -0
- package/lib/infrastructure/file-service.js.map +1 -0
- package/lib/infrastructure/services/api-service.d.ts +10 -0
- package/lib/infrastructure/services/api-service.js +52 -0
- package/lib/infrastructure/services/api-service.js.map +1 -0
- package/lib/infrastructure/services/auth-service.d.ts +11 -0
- package/lib/infrastructure/services/auth-service.js +33 -0
- package/lib/infrastructure/services/auth-service.js.map +1 -0
- package/lib/infrastructure/services/portal-service.d.ts +7 -4
- package/lib/infrastructure/services/portal-service.js +70 -49
- package/lib/infrastructure/services/portal-service.js.map +1 -1
- package/lib/infrastructure/services/telemetry-service.d.ts +8 -0
- package/lib/infrastructure/services/telemetry-service.js +40 -0
- package/lib/infrastructure/services/telemetry-service.js.map +1 -0
- package/lib/infrastructure/tmp-extensions.d.ts +2 -0
- package/lib/infrastructure/tmp-extensions.js +6 -0
- package/lib/infrastructure/tmp-extensions.js.map +1 -0
- package/lib/infrastructure/zip-service.d.ts +6 -0
- package/lib/infrastructure/zip-service.js +25 -0
- package/lib/infrastructure/zip-service.js.map +1 -0
- package/lib/prompts/auth/login.d.ts +5 -0
- package/lib/prompts/auth/login.js +13 -0
- package/lib/prompts/auth/login.js.map +1 -0
- package/lib/prompts/portal/common/base-prompts.d.ts +7 -0
- package/lib/prompts/portal/common/base-prompts.js +19 -0
- package/lib/prompts/portal/common/base-prompts.js.map +1 -0
- package/lib/prompts/portal/copilot.d.ts +6 -0
- package/lib/prompts/portal/copilot.js +35 -0
- package/lib/prompts/portal/copilot.js.map +1 -0
- package/lib/prompts/portal/generate.d.ts +3 -2
- package/lib/prompts/portal/generate.js +21 -36
- package/lib/prompts/portal/generate.js.map +1 -1
- package/lib/prompts/portal/quickstart.d.ts +8 -9
- package/lib/prompts/portal/quickstart.js +44 -32
- package/lib/prompts/portal/quickstart.js.map +1 -1
- package/lib/prompts/portal/recipe/new-recipe.d.ts +1 -0
- package/lib/prompts/portal/recipe/new-recipe.js +18 -8
- package/lib/prompts/portal/recipe/new-recipe.js.map +1 -1
- package/lib/prompts/portal/serve.d.ts +4 -6
- package/lib/prompts/portal/serve.js +24 -15
- package/lib/prompts/portal/serve.js.map +1 -1
- package/lib/prompts/portal/toc/new-toc.d.ts +3 -2
- package/lib/prompts/portal/toc/new-toc.js +11 -14
- package/lib/prompts/portal/toc/new-toc.js.map +1 -1
- package/lib/prompts/sdk/generate.d.ts +11 -0
- package/lib/prompts/sdk/generate.js +42 -0
- package/lib/prompts/sdk/generate.js.map +1 -0
- package/lib/types/api/account.d.ts +10 -0
- package/lib/types/api/account.js +2 -0
- package/lib/types/api/account.js.map +1 -0
- package/lib/types/build/build.d.ts +14 -0
- package/lib/types/build/build.js +4 -0
- package/lib/types/build/build.js.map +1 -0
- package/lib/types/build-context.d.ts +13 -0
- package/lib/types/build-context.js +30 -0
- package/lib/types/build-context.js.map +1 -0
- package/lib/types/events/domain-event.d.ts +8 -0
- package/lib/types/events/domain-event.js +11 -0
- package/lib/types/events/domain-event.js.map +1 -0
- package/lib/types/events/recipe-creation-failed.d.ts +5 -0
- package/lib/types/events/recipe-creation-failed.js +8 -0
- package/lib/types/events/recipe-creation-failed.js.map +1 -0
- package/lib/types/events/toc-creation-failed.d.ts +5 -0
- package/lib/types/events/toc-creation-failed.js +8 -0
- package/lib/types/events/toc-creation-failed.js.map +1 -0
- package/lib/types/file/directoryPath.d.ts +7 -0
- package/lib/types/file/directoryPath.js +16 -0
- package/lib/types/file/directoryPath.js.map +1 -0
- package/lib/types/file/fileName.d.ts +5 -0
- package/lib/types/file/fileName.js +9 -0
- package/lib/types/file/fileName.js.map +1 -0
- package/lib/types/file/filePath.d.ts +8 -0
- package/lib/types/file/filePath.js +11 -0
- package/lib/types/file/filePath.js.map +1 -0
- package/lib/types/flags-provider.d.ts +15 -0
- package/lib/types/flags-provider.js +34 -0
- package/lib/types/flags-provider.js.map +1 -0
- package/lib/types/portal/generate.d.ts +0 -13
- package/lib/types/portal/quickstart.d.ts +1 -1
- package/lib/types/portal/serve.d.ts +13 -0
- package/lib/types/portal/serve.js +2 -0
- package/lib/types/portal/serve.js.map +1 -0
- package/lib/types/portal-context.d.ts +11 -0
- package/lib/types/portal-context.js +28 -0
- package/lib/types/portal-context.js.map +1 -0
- package/lib/types/sdk/generate.d.ts +8 -8
- package/lib/types/sdk/generate.js +10 -10
- package/lib/types/sdk/generate.js.map +1 -1
- package/lib/types/sdk-context.d.ts +13 -0
- package/lib/types/sdk-context.js +28 -0
- package/lib/types/sdk-context.js.map +1 -0
- package/lib/types/spec-context.d.ts +7 -0
- package/lib/types/spec-context.js +12 -0
- package/lib/types/spec-context.js.map +1 -0
- package/lib/utils/utils.d.ts +1 -4
- package/lib/utils/utils.js +18 -32
- package/lib/utils/utils.js.map +1 -1
- package/lib/validators/common/directoryValidator.d.ts +3 -7
- package/lib/validators/common/directoryValidator.js +10 -37
- package/lib/validators/common/directoryValidator.js.map +1 -1
- package/lib/validators/portal/serve-validator.d.ts +6 -0
- package/lib/validators/portal/serve-validator.js +15 -0
- package/lib/validators/portal/serve-validator.js.map +1 -0
- package/package.json +6 -3
- package/lib/controllers/portal/generate.d.ts +0 -3
- package/lib/controllers/portal/generate.js +0 -106
- package/lib/controllers/portal/generate.js.map +0 -1
- package/lib/controllers/portal/serve.d.ts +0 -3
- package/lib/controllers/portal/serve.js +0 -136
- package/lib/controllers/portal/serve.js.map +0 -1
- package/lib/controllers/sdk/generate.d.ts +0 -4
- package/lib/controllers/sdk/generate.js +0 -61
- package/lib/controllers/sdk/generate.js.map +0 -1
- package/lib/services/portal/server.d.ts +0 -14
- package/lib/services/portal/server.js +0 -97
- package/lib/services/portal/server.js.map +0 -1
- package/lib/validators/common/portValidator.d.ts +0 -5
- package/lib/validators/common/portValidator.js +0 -16
- package/lib/validators/common/portValidator.js.map +0 -1
- package/lib/validators/portal/serveValidator.d.ts +0 -6
- package/lib/validators/portal/serveValidator.js +0 -17
- 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
|
|
26
|
-
const
|
|
33
|
+
async getWorkingDirectory(prompts, controller, specFile, apiValidationSummary, languages) {
|
|
34
|
+
const workingDirectory = await prompts.workingDirectoryPrompt();
|
|
27
35
|
prompts.displayBuildDirectoryGenerationMessage();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
prompts.
|
|
31
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
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 = ["
|
|
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;
|
|
1
|
+
{"version":3,"file":"quickstart.js","sourceRoot":"","sources":["../../../src/commands/portal/quickstart.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,mCAAmC,EAAgC,MAAM,eAAe,CAAC;AAClG,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AA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,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,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
|
|
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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"new.js","sourceRoot":"","sources":["../../../../src/commands/portal/recipe/new.ts"],"names":[],"mappings":"AAAA,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;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uDAAuD,CAAC;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,aAAa,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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
|
-
|
|
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
|
-
|
|
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
|
|
16
|
+
private getServerPort;
|
|
16
17
|
}
|
|
@@ -1,135 +1,85 @@
|
|
|
1
|
-
|
|
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 {
|
|
9
|
-
import {
|
|
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
|
|
13
|
-
const { flags } = await this.parse(
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const port = flags.port;
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
86
|
-
this.
|
|
49
|
+
if (servePortalResult.isSuccess()) {
|
|
50
|
+
this.prompts.displayOutroMessage(buildDirectory.toString(), portalDirectory.toString(), port, flags["no-reload"]);
|
|
87
51
|
}
|
|
88
|
-
|
|
89
|
-
|
|
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: "
|
|
99
|
-
|
|
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
|
|
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
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../../src/commands/portal/serve.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAC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AE,yCAAyC;QACtD,OAAO,EAAE,KAAK;KACf,CAAC,EACF,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC;QACzB,WAAW,EAAE,qBAAqB;QAClC,OAAO,EAAE,KAAK;KACf,CAAC,EACF,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,GAAG;QACT,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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
53
|
-
|
|
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
|