@apimatic/cli 1.1.0-alpha.2 → 1.1.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +249 -99
- package/bin/run.js +5 -0
- 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 +49 -0
- package/lib/actions/portal/copilot.js.map +1 -0
- package/lib/actions/portal/generate.d.ts +13 -0
- package/lib/actions/portal/generate.js +61 -0
- package/lib/actions/portal/generate.js.map +1 -0
- package/lib/actions/portal/recipe/new-recipe.d.ts +24 -0
- package/lib/actions/portal/recipe/new-recipe.js +250 -0
- package/lib/actions/portal/recipe/new-recipe.js.map +1 -0
- package/lib/actions/portal/serve.d.ts +14 -0
- package/lib/actions/portal/serve.js +24 -0
- package/lib/actions/portal/serve.js.map +1 -0
- package/lib/actions/portal/toc/new-toc.d.ts +20 -0
- package/lib/actions/portal/toc/new-toc.js +133 -0
- package/lib/actions/portal/toc/new-toc.js.map +1 -0
- package/lib/actions/sdk/generate.d.ts +14 -0
- package/lib/actions/sdk/generate.js +72 -0
- package/lib/actions/sdk/generate.js.map +1 -0
- package/lib/application/portal/recipe/portal-recipe.d.ts +8 -0
- package/lib/application/portal/recipe/portal-recipe.js +33 -0
- package/lib/application/portal/recipe/portal-recipe.js.map +1 -0
- package/lib/application/portal/recipe/recipe-generator.d.ts +16 -0
- package/lib/application/portal/recipe/recipe-generator.js +147 -0
- package/lib/application/portal/recipe/recipe-generator.js.map +1 -0
- package/lib/application/portal/serve/portal-watcher.d.ts +11 -0
- package/lib/application/portal/serve/portal-watcher.js +64 -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 +19 -0
- package/lib/application/portal/toc/sdl-parser.js +90 -0
- package/lib/application/portal/toc/sdl-parser.js.map +1 -0
- package/lib/application/portal/toc/toc-content-parser.d.ts +5 -0
- package/lib/application/portal/toc/toc-content-parser.js +44 -0
- package/lib/application/portal/toc/toc-content-parser.js.map +1 -0
- package/lib/application/portal/toc/toc-structure-generator.d.ts +6 -0
- package/lib/application/portal/toc/toc-structure-generator.js +84 -0
- package/lib/application/portal/toc/toc-structure-generator.js.map +1 -0
- package/lib/client-utils/auth-manager.d.ts +8 -3
- package/lib/client-utils/auth-manager.js +23 -10
- package/lib/client-utils/auth-manager.js.map +1 -0
- package/lib/client-utils/sdk-client.d.ts +0 -1
- package/lib/client-utils/sdk-client.js +25 -55
- package/lib/client-utils/sdk-client.js.map +1 -0
- package/lib/commands/api/transform.d.ts +7 -7
- package/lib/commands/api/transform.js +43 -51
- package/lib/commands/api/transform.js.map +1 -0
- package/lib/commands/api/validate.d.ts +4 -4
- package/lib/commands/api/validate.js +26 -33
- package/lib/commands/api/validate.js.map +1 -0
- package/lib/commands/auth/login.d.ts +3 -2
- package/lib/commands/auth/login.js +22 -53
- package/lib/commands/auth/login.js.map +1 -0
- package/lib/commands/auth/logout.d.ts +1 -1
- package/lib/commands/auth/logout.js +8 -13
- package/lib/commands/auth/logout.js.map +1 -0
- package/lib/commands/auth/status.d.ts +1 -1
- package/lib/commands/auth/status.js +9 -13
- package/lib/commands/auth/status.js.map +1 -0
- package/lib/commands/portal/copilot.d.ts +12 -0
- package/lib/commands/portal/copilot.js +32 -0
- package/lib/commands/portal/copilot.js.map +1 -0
- package/lib/commands/portal/generate.d.ts +10 -8
- package/lib/commands/portal/generate.js +28 -107
- package/lib/commands/portal/generate.js.map +1 -0
- package/lib/commands/portal/quickstart.d.ts +10 -0
- package/lib/commands/portal/quickstart.js +105 -0
- package/lib/commands/portal/quickstart.js.map +1 -0
- package/lib/commands/portal/recipe/new.d.ts +10 -0
- package/lib/commands/portal/recipe/new.js +38 -0
- package/lib/commands/portal/recipe/new.js.map +1 -0
- package/lib/commands/portal/serve.d.ts +16 -0
- package/lib/commands/portal/serve.js +80 -0
- package/lib/commands/portal/serve.js.map +1 -0
- package/lib/commands/portal/toc/new.d.ts +14 -0
- package/lib/commands/portal/toc/new.js +52 -0
- package/lib/commands/portal/toc/new.js.map +1 -0
- package/lib/commands/sdk/generate.d.ts +9 -8
- package/lib/commands/sdk/generate.js +39 -128
- package/lib/commands/sdk/generate.js.map +1 -0
- package/lib/config/axios-config.d.ts +2 -0
- package/lib/config/axios-config.js +10 -0
- package/lib/config/axios-config.js.map +1 -0
- package/lib/config/env.d.ts +26 -1
- package/lib/config/env.js +27 -4
- package/lib/config/env.js.map +1 -0
- package/lib/controllers/api/transform.d.ts +1 -1
- package/lib/controllers/api/transform.js +23 -22
- package/lib/controllers/api/transform.js.map +1 -0
- package/lib/controllers/api/validate.d.ts +3 -3
- package/lib/controllers/api/validate.js +19 -12
- package/lib/controllers/api/validate.js.map +1 -0
- package/lib/controllers/portal/quickstart.d.ts +15 -0
- package/lib/controllers/portal/quickstart.js +217 -0
- package/lib/controllers/portal/quickstart.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -4
- package/lib/index.js.map +1 -0
- 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 +18 -0
- package/lib/infrastructure/file-service.js +76 -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 +54 -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 +20 -0
- package/lib/infrastructure/services/portal-service.js +163 -0
- package/lib/infrastructure/services/portal-service.js.map +1 -0
- 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 +39 -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 +8 -0
- package/lib/prompts/portal/copilot.js +54 -0
- package/lib/prompts/portal/copilot.js.map +1 -0
- package/lib/prompts/portal/generate.d.ts +11 -0
- package/lib/prompts/portal/generate.js +42 -0
- package/lib/prompts/portal/generate.js.map +1 -0
- package/lib/prompts/portal/quickstart.d.ts +30 -0
- package/lib/prompts/portal/quickstart.js +240 -0
- package/lib/prompts/portal/quickstart.js.map +1 -0
- package/lib/prompts/portal/recipe/new-recipe.d.ts +24 -0
- package/lib/prompts/portal/recipe/new-recipe.js +203 -0
- package/lib/prompts/portal/recipe/new-recipe.js.map +1 -0
- package/lib/prompts/portal/serve.d.ts +4 -0
- package/lib/prompts/portal/serve.js +14 -0
- package/lib/prompts/portal/serve.js.map +1 -0
- package/lib/prompts/portal/toc/new-toc.d.ts +11 -0
- package/lib/prompts/portal/toc/new-toc.js +39 -0
- package/lib/prompts/portal/toc/new-toc.js.map +1 -0
- 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/api/transform.d.ts +19 -4
- package/lib/types/api/transform.js +19 -4
- package/lib/types/api/transform.js.map +1 -0
- package/lib/types/api/validate.d.ts +3 -3
- package/lib/types/api/validate.js +2 -2
- package/lib/types/api/validate.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/common/result.d.ts +17 -0
- package/lib/types/common/result.js +32 -0
- package/lib/types/common/result.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 +13 -9
- package/lib/types/portal/generate.js +3 -2
- package/lib/types/portal/generate.js.map +1 -0
- package/lib/types/portal/quickstart.d.ts +17 -0
- package/lib/types/portal/quickstart.js +2 -0
- package/lib/types/portal/quickstart.js.map +1 -0
- package/lib/types/portal/serve.d.ts +12 -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/recipe/recipe.d.ts +37 -0
- package/lib/types/recipe/recipe.js +6 -0
- package/lib/types/recipe/recipe.js.map +1 -0
- package/lib/types/sdk/generate.d.ts +11 -10
- package/lib/types/sdk/generate.js +11 -12
- package/lib/types/sdk/generate.js.map +1 -0
- 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/sdl/sdl.d.ts +12 -0
- package/lib/types/sdl/sdl.js +2 -0
- package/lib/types/sdl/sdl.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/types/toc/toc.d.ts +31 -0
- package/lib/types/toc/toc.js +9 -0
- package/lib/types/toc/toc.js.map +1 -0
- package/lib/types/utils.d.ts +3 -3
- package/lib/types/utils.js +2 -2
- package/lib/types/utils.js.map +1 -0
- package/lib/utils/utils.d.ts +16 -7
- package/lib/utils/utils.js +142 -86
- package/lib/utils/utils.js.map +1 -0
- package/lib/validators/common/directoryValidator.d.ts +5 -0
- package/lib/validators/common/directoryValidator.js +22 -0
- package/lib/validators/common/directoryValidator.js.map +1 -0
- 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 +96 -40
- package/bin/run +0 -5
- package/lib/controllers/portal/generate.d.ts +0 -2
- package/lib/controllers/portal/generate.js +0 -49
- package/lib/controllers/sdk/generate.d.ts +0 -4
- package/lib/controllers/sdk/generate.js +0 -64
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { select, cancel, isCancel, outro, confirm, log, text, } from "@clack/prompts";
|
|
2
|
+
import { getMessageInCyanColor } from "../../utils/utils.js";
|
|
3
|
+
export class PortalCopilotPrompts {
|
|
4
|
+
async selectCopilotKey(keys) {
|
|
5
|
+
const selectedKey = await select({
|
|
6
|
+
message: "Select the ID for the API Copilot you would like to add to this API Portal:",
|
|
7
|
+
maxItems: 10,
|
|
8
|
+
options: keys.map((key) => ({
|
|
9
|
+
value: key,
|
|
10
|
+
label: key
|
|
11
|
+
}))
|
|
12
|
+
});
|
|
13
|
+
if (isCancel(selectedKey)) {
|
|
14
|
+
cancel("Operation cancelled.");
|
|
15
|
+
return process.exit(0);
|
|
16
|
+
}
|
|
17
|
+
return selectedKey;
|
|
18
|
+
}
|
|
19
|
+
copilotConfigured(apiCopilotConfig) {
|
|
20
|
+
outro(`API Copilot configured successfully!
|
|
21
|
+
|
|
22
|
+
Copilot ID: ${getMessageInCyanColor(apiCopilotConfig.key)}
|
|
23
|
+
Welcome Message: ${getMessageInCyanColor(apiCopilotConfig.welcomeMessage)}
|
|
24
|
+
Status: ${getMessageInCyanColor(apiCopilotConfig.isEnabled ? "Enabled" : "Disabled")}
|
|
25
|
+
|
|
26
|
+
Configuration saved to: APIMATIC-BUILD.json
|
|
27
|
+
|
|
28
|
+
Run 'apimatic portal:serve' to preview your API Portal and try out the API Copilot.`);
|
|
29
|
+
}
|
|
30
|
+
async confirmOverwrite() {
|
|
31
|
+
const shouldOverwrite = await confirm({
|
|
32
|
+
message: "API Copilot configuration already exists. Do you want to overwrite?",
|
|
33
|
+
initialValue: false
|
|
34
|
+
});
|
|
35
|
+
if (isCancel(shouldOverwrite)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return shouldOverwrite;
|
|
39
|
+
}
|
|
40
|
+
logError(error) {
|
|
41
|
+
log.error(error);
|
|
42
|
+
}
|
|
43
|
+
async getWelcomeMessage() {
|
|
44
|
+
const welcomeMessage = await text({
|
|
45
|
+
message: "Enter a welcome message for your API Copilot:",
|
|
46
|
+
placeholder: "Enter your welcome message here..."
|
|
47
|
+
});
|
|
48
|
+
if (isCancel(welcomeMessage)) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return welcomeMessage;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=copilot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot.js","sourceRoot":"","sources":["../../../src/prompts/portal/copilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,GAAI,MAAM,gBAAgB,CAAC;AAEvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,OAAO,oBAAoB;IACxB,KAAK,CAAC,gBAAgB,CAAC,IAAc;QAC1C,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC;YAC/B,OAAO,EAAE,6EAA6E;YACtF,QAAQ,EAAE,EAAE;YACZ,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;gBAC1B,KAAK,EAAE,GAAG;gBACV,KAAK,EAAE,GAAG;aACX,CAAC,CAAC;SACJ,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1B,MAAM,CAAC,sBAAsB,CAAC,CAAC;YAC/B,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAEM,iBAAiB,CAAC,gBAA+B;QACtD,KAAK,CACH;;kBAEY,qBAAqB,CAAC,gBAAgB,CAAC,GAAG,CAAC;uBACtC,qBAAqB,CAAC,gBAAgB,CAAC,cAAc,CAAC;cAC/D,qBAAqB,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;;;;oFAIJ,CAC/E,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,gBAAgB;QAC3B,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC;YACpC,OAAO,EAAE,qEAAqE;YAC9E,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,iBAAiB;QACrB,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC;YAChC,OAAO,EAAE,+CAA+C;YACxD,WAAW,EAAE,oCAAoC;SAClD,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YAC7B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DirectoryPath } from "../../types/file/directoryPath.js";
|
|
2
|
+
export declare class PortalGeneratePrompts {
|
|
3
|
+
private readonly spin;
|
|
4
|
+
overwritePortal(directory: DirectoryPath): Promise<boolean>;
|
|
5
|
+
displayPortalGenerationMessage(): void;
|
|
6
|
+
displayPortalGenerationSuccessMessage(): void;
|
|
7
|
+
displayPortalGenerationErrorMessage(): void;
|
|
8
|
+
displayOutroMessage(generatedPortalPath: string): void;
|
|
9
|
+
logError(error: string): void;
|
|
10
|
+
private cleanUpStandardInput;
|
|
11
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { outro, spinner, isCancel, confirm, log } from "@clack/prompts";
|
|
2
|
+
import { getMessageInRedColor, getMessageInMagentaColor, getMessageInCyanColor } from "../../utils/utils.js";
|
|
3
|
+
export class PortalGeneratePrompts {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.spin = spinner();
|
|
6
|
+
}
|
|
7
|
+
async overwritePortal(directory) {
|
|
8
|
+
const overwrite = await confirm({
|
|
9
|
+
message: `The destination '${directory}' is not empty, do you want to overwrite?`,
|
|
10
|
+
initialValue: false
|
|
11
|
+
});
|
|
12
|
+
if (isCancel(overwrite)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return overwrite;
|
|
16
|
+
}
|
|
17
|
+
displayPortalGenerationMessage() {
|
|
18
|
+
this.spin.start(getMessageInMagentaColor("Generating portal"));
|
|
19
|
+
}
|
|
20
|
+
displayPortalGenerationSuccessMessage() {
|
|
21
|
+
this.spin.stop(getMessageInCyanColor("Portal generated successfully."));
|
|
22
|
+
this.cleanUpStandardInput();
|
|
23
|
+
}
|
|
24
|
+
displayPortalGenerationErrorMessage() {
|
|
25
|
+
this.spin.stop(getMessageInRedColor(`Portal Generation failed.`), 1);
|
|
26
|
+
this.cleanUpStandardInput();
|
|
27
|
+
}
|
|
28
|
+
displayOutroMessage(generatedPortalPath) {
|
|
29
|
+
outro(`The generated portal can be found at ${generatedPortalPath}`);
|
|
30
|
+
}
|
|
31
|
+
logError(error) {
|
|
32
|
+
log.error(error);
|
|
33
|
+
}
|
|
34
|
+
//This clears the standard input to allow interrupts like CTRL+C to work properly.
|
|
35
|
+
cleanUpStandardInput() {
|
|
36
|
+
if (process.stdin.isTTY) {
|
|
37
|
+
process.stdin.setRawMode(false);
|
|
38
|
+
process.stdin.pause();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/prompts/portal/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAG7G,MAAM,OAAO,qBAAqB;IAAlC;QACmB,SAAI,GAAG,OAAO,EAAE,CAAC;IA4CpC,CAAC;IA1CQ,KAAK,CAAC,eAAe,CAAC,SAAwB;QACnD,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC;YAC9B,OAAO,EAAE,oBAAoB,SAAS,2CAA2C;YACjF,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,8BAA8B;QAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,mBAAmB,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,qCAAqC;QACnC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,gCAAgC,CAAC,CAAC,CAAC;QACxE,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC9B,CAAC;IAED,mCAAmC;QACjC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,2BAA2B,CAAC,EAAE,CAAC,CAAC,CAAC;QACrE,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC9B,CAAC;IAED,mBAAmB,CAAC,mBAA2B;QAC7C,KAAK,CAAC,wCAAwC,mBAAmB,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED,kFAAkF;IAC1E,oBAAoB;QAC1B,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAChC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BasePrompts } from "./common/base-prompts.js";
|
|
2
|
+
export declare class PortalQuickstartPrompts extends BasePrompts {
|
|
3
|
+
private readonly vscodeExtensionUrl;
|
|
4
|
+
private readonly serverUrl;
|
|
5
|
+
private readonly referenceDocumentationUrl;
|
|
6
|
+
private readonly customizeTheSdksUrl;
|
|
7
|
+
private readonly defaultPortalDirectoryPath;
|
|
8
|
+
displayWelcomeMessage(): void;
|
|
9
|
+
loginPrompt(): Promise<{
|
|
10
|
+
email: string;
|
|
11
|
+
password: string;
|
|
12
|
+
}>;
|
|
13
|
+
removeQuotes(str: string): string;
|
|
14
|
+
specPrompt(): Promise<string>;
|
|
15
|
+
displaySpecValidationMessage(): void;
|
|
16
|
+
displaySpecValidationSuccessMessage(): void;
|
|
17
|
+
displaySpecValidationErrorMessage(): void;
|
|
18
|
+
displaySpecValidationFailureMessage(): void;
|
|
19
|
+
specValidationFailurePrompt(): Promise<void>;
|
|
20
|
+
sdkLanguagesPrompt(): Promise<string[]>;
|
|
21
|
+
workingDirectoryPrompt(): Promise<string>;
|
|
22
|
+
displayBuildDirectoryGenerationMessage(): void;
|
|
23
|
+
displayBuildDirectoryGenerationErrorMessage(): void;
|
|
24
|
+
displayBuildDirectoryGenerationSuccessMessage(targetFolder: string): void;
|
|
25
|
+
displayBuildDirectoryAsTree(targetFolder: string): void;
|
|
26
|
+
displayOutroMessage(buildDirectory: string): void;
|
|
27
|
+
getLoggedInFirst(): void;
|
|
28
|
+
displayLoggedInMessage(email: string): void;
|
|
29
|
+
logError(error: string): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import treeify from "treeify";
|
|
4
|
+
import { intro, outro, text, select, multiselect, log, isCancel, cancel, password } from "@clack/prompts";
|
|
5
|
+
import { getMessageInCyanColor, getMessageInGreenColor, getMessageInOrangeColor, getMessageInMagentaColor, getMessageInRedColor, isValidUrl, directoryToJson } from "../../utils/utils.js";
|
|
6
|
+
import { BasePrompts } from "./common/base-prompts.js";
|
|
7
|
+
import axios from "axios";
|
|
8
|
+
export class PortalQuickstartPrompts extends BasePrompts {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.vscodeExtensionUrl = "\u001b[4mhttps://marketplace.visualstudio.com/items?itemName=apimatic-developers.apimatic-for-vscode\u001b[0m";
|
|
12
|
+
this.serverUrl = "\u001b[4mhttp://localhost:3000\u001b[0m";
|
|
13
|
+
this.referenceDocumentationUrl = "\u001b[4mhttps://docs.apimatic.io/cli-getting-started/advanced-portal-setup\u001b[0m";
|
|
14
|
+
this.customizeTheSdksUrl = "\u001b[4mhttps://docs.apimatic.io/generate-sdks/codegen-settings/codegen-settings-overview\u001b[0m";
|
|
15
|
+
this.defaultPortalDirectoryPath = process.cwd();
|
|
16
|
+
}
|
|
17
|
+
displayWelcomeMessage() {
|
|
18
|
+
intro(`Hello there 👋`);
|
|
19
|
+
log.message(`This wizard will help you set up an API Portal via APIMatic's Docs as Code workflow in 4 simple steps.`);
|
|
20
|
+
log.message(`Let's get started! 🚀`);
|
|
21
|
+
}
|
|
22
|
+
async loginPrompt() {
|
|
23
|
+
log.message(`Please log in to continue.`);
|
|
24
|
+
const email = await text({
|
|
25
|
+
message: "Enter your registered email:",
|
|
26
|
+
validate: (input) => {
|
|
27
|
+
if (!input) {
|
|
28
|
+
return getMessageInRedColor("Email is required.");
|
|
29
|
+
}
|
|
30
|
+
const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
31
|
+
if (!emailRegex.test(input)) {
|
|
32
|
+
return getMessageInRedColor("Please enter a valid email address.");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (isCancel(email)) {
|
|
37
|
+
cancel("Operation cancelled.");
|
|
38
|
+
return process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
const pass = await password({
|
|
41
|
+
message: "Enter your password:",
|
|
42
|
+
validate: (input) => {
|
|
43
|
+
if (!input) {
|
|
44
|
+
return getMessageInRedColor("Password is required.");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (isCancel(pass)) {
|
|
49
|
+
cancel("Operation cancelled.");
|
|
50
|
+
return process.exit(0);
|
|
51
|
+
}
|
|
52
|
+
return { email: String(email).trim(), password: String(pass).trim() };
|
|
53
|
+
}
|
|
54
|
+
removeQuotes(str) {
|
|
55
|
+
const quotes = ['"', "'"];
|
|
56
|
+
for (const quote of quotes) {
|
|
57
|
+
if (str.startsWith(quote) && str.endsWith(quote) && str.length > 1) {
|
|
58
|
+
return this.removeQuotes(str.slice(1, -1)); // Recursive call
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return str;
|
|
62
|
+
}
|
|
63
|
+
async specPrompt() {
|
|
64
|
+
log.step(getMessageInOrangeColor(`Step 1 of 4: Import your OpenAPI Definition`));
|
|
65
|
+
while (true) {
|
|
66
|
+
const spec = await text({
|
|
67
|
+
message: `Provide a local path or a public URL for your OpenAPI definition file:`,
|
|
68
|
+
placeholder: "Provide absolute URL/local path or press Enter to use a sample OpenAPI file from APIMatic.",
|
|
69
|
+
defaultValue: "https://raw.githubusercontent.com/apimatic/static-portal-workflow/refs/heads/master/spec/openapi.json",
|
|
70
|
+
validate: (input) => {
|
|
71
|
+
var _a;
|
|
72
|
+
if (!input)
|
|
73
|
+
return;
|
|
74
|
+
const cleanedPath = this.removeQuotes((_a = input.trim()) !== null && _a !== void 0 ? _a : "");
|
|
75
|
+
if (!isValidUrl(cleanedPath)) {
|
|
76
|
+
const dirPath = path.resolve(cleanedPath);
|
|
77
|
+
if (!fs.existsSync(dirPath)) {
|
|
78
|
+
return getMessageInRedColor("Error: The specified file does not exist. Please enter a valid file path.");
|
|
79
|
+
}
|
|
80
|
+
if (!fs.statSync(dirPath).isFile()) {
|
|
81
|
+
return getMessageInRedColor("Error: The specified path does not point to a valid API Definition file or a zip archive containing API definition files. Please try again.");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return; // pass sync validation
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
if (isCancel(spec)) {
|
|
88
|
+
cancel("Operation cancelled.");
|
|
89
|
+
process.exit(0);
|
|
90
|
+
}
|
|
91
|
+
const cleanedPath = this.removeQuotes(String(spec).trim());
|
|
92
|
+
// Async validation for URLs
|
|
93
|
+
if (isValidUrl(cleanedPath)) {
|
|
94
|
+
try {
|
|
95
|
+
const response = await axios.head(cleanedPath);
|
|
96
|
+
const contentType = response.headers["content-type"];
|
|
97
|
+
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/html")) {
|
|
98
|
+
log.error(getMessageInRedColor(`Invalid URL. Please check the URL and ensure it points to a valid OpenAPI definition.`));
|
|
99
|
+
continue; // re-prompt
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
log.error(getMessageInRedColor(`Failed to reach the URL. Please check your internet connection or the URL.`));
|
|
104
|
+
continue; // re-prompt
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return cleanedPath; // valid local file or valid URL
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
displaySpecValidationMessage() {
|
|
111
|
+
log.step(getMessageInOrangeColor(`Step 2 of 4: Validate and Lint your OpenAPI file`));
|
|
112
|
+
this.spin.start(getMessageInMagentaColor(`Running your API Definition through APIMatic's 1200+ CodeGen Specific validation and linting rules 🔍 `));
|
|
113
|
+
}
|
|
114
|
+
displaySpecValidationSuccessMessage() {
|
|
115
|
+
this.spin.stop(getMessageInCyanColor(`Validation Successful.`));
|
|
116
|
+
}
|
|
117
|
+
displaySpecValidationErrorMessage() {
|
|
118
|
+
this.spin.stop(getMessageInRedColor(`Something went wrong while validating your spec.`), 1);
|
|
119
|
+
}
|
|
120
|
+
displaySpecValidationFailureMessage() {
|
|
121
|
+
this.spin.stop(getMessageInRedColor(`❗ Oops, it looks like there are some errors in your API Definition.`), 1);
|
|
122
|
+
}
|
|
123
|
+
async specValidationFailurePrompt() {
|
|
124
|
+
const useSampleSpec = await select({
|
|
125
|
+
message: `How would you like to proceed?`,
|
|
126
|
+
options: [
|
|
127
|
+
{
|
|
128
|
+
value: "exit",
|
|
129
|
+
label: `1. Fix the issues using APIMatic's interactive VS Code Extension: ${this.vscodeExtensionUrl}`
|
|
130
|
+
},
|
|
131
|
+
{ value: "continue", label: `2. Use an example API spec instead (recommended)` }
|
|
132
|
+
]
|
|
133
|
+
});
|
|
134
|
+
if (isCancel(useSampleSpec)) {
|
|
135
|
+
cancel("Operation cancelled.");
|
|
136
|
+
return process.exit(0);
|
|
137
|
+
}
|
|
138
|
+
if (useSampleSpec === "exit") {
|
|
139
|
+
outro(getMessageInCyanColor("Good luck fixing your API definition! 🛠️ Feel free to run this command again once you're done."));
|
|
140
|
+
return process.exit(0);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async sdkLanguagesPrompt() {
|
|
144
|
+
log.step(getMessageInOrangeColor(`Step 3 of 4: Select programming languages`));
|
|
145
|
+
const languages = (await multiselect({
|
|
146
|
+
message: "💻 Your API Portal will contain SDKs and SDK Documentation in the following Languages. Press enter to continue with all languages, or use the arrow keys and spacebar to customize your selection:",
|
|
147
|
+
options: [
|
|
148
|
+
{ label: "HTTP", value: "http" },
|
|
149
|
+
{ label: "Typescript", value: "typescript" },
|
|
150
|
+
{ label: "Ruby", value: "ruby" },
|
|
151
|
+
{ label: "Python", value: "python" },
|
|
152
|
+
{ label: "Java", value: "java" },
|
|
153
|
+
{ label: "C#", value: "csharp" },
|
|
154
|
+
{ label: "PHP", value: "php" },
|
|
155
|
+
{ label: "Go", value: "go" }
|
|
156
|
+
],
|
|
157
|
+
initialValues: ["http", "typescript", "ruby", "python", "java", "csharp", "php", "go"]
|
|
158
|
+
}));
|
|
159
|
+
if (isCancel(languages)) {
|
|
160
|
+
cancel("Operation cancelled.");
|
|
161
|
+
return process.exit(0);
|
|
162
|
+
}
|
|
163
|
+
return languages;
|
|
164
|
+
}
|
|
165
|
+
async workingDirectoryPrompt() {
|
|
166
|
+
log.step(getMessageInOrangeColor(`Step 4 of 4: Generate source files for Docs as Code`));
|
|
167
|
+
const directory = await text({
|
|
168
|
+
message: "Enter the directory path where you would like to setup the API Portal (Requires an empty directory):",
|
|
169
|
+
placeholder: "Provide absolute path to the directory or press Enter to use the current directory.",
|
|
170
|
+
defaultValue: "./",
|
|
171
|
+
validate: (input) => {
|
|
172
|
+
var _a;
|
|
173
|
+
const cleanedPath = this.removeQuotes((_a = input === null || input === void 0 ? void 0 : input.trim()) !== null && _a !== void 0 ? _a : "");
|
|
174
|
+
const dirPath = path.resolve(cleanedPath);
|
|
175
|
+
if (!fs.existsSync(dirPath) && dirPath != this.defaultPortalDirectoryPath) {
|
|
176
|
+
return getMessageInRedColor("Error: The specified directory path does not exist. Please try again.");
|
|
177
|
+
}
|
|
178
|
+
if (dirPath !== this.defaultPortalDirectoryPath) {
|
|
179
|
+
const files = fs.readdirSync(dirPath).filter((item) => !item.startsWith("."));
|
|
180
|
+
if (files.length > 0) {
|
|
181
|
+
return getMessageInRedColor("Error: The target directory is not empty. Please provide a path to an empty directory or clear its contents.");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else if (fs.existsSync(dirPath)) {
|
|
185
|
+
// For ignoring hidden files and folders in the current directory in MacOS.
|
|
186
|
+
const files = fs.readdirSync(dirPath).filter((item) => !item.startsWith("."));
|
|
187
|
+
if (files.length > 0) {
|
|
188
|
+
return getMessageInRedColor("Error: The target directory is not empty. Please provide a path to an empty directory or clear its contents.");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
if (isCancel(directory)) {
|
|
194
|
+
cancel("Operation cancelled.");
|
|
195
|
+
return process.exit(0);
|
|
196
|
+
}
|
|
197
|
+
if (directory === "./") {
|
|
198
|
+
return this.defaultPortalDirectoryPath;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
return this.removeQuotes(String(directory).trim());
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
displayBuildDirectoryGenerationMessage() {
|
|
205
|
+
this.spin.start(getMessageInMagentaColor("Generating build directory ⚙️"));
|
|
206
|
+
}
|
|
207
|
+
displayBuildDirectoryGenerationErrorMessage() {
|
|
208
|
+
this.spin.stop(getMessageInRedColor(`Something went wrong while setting up your build directory.`), 1);
|
|
209
|
+
}
|
|
210
|
+
displayBuildDirectoryGenerationSuccessMessage(targetFolder) {
|
|
211
|
+
this.spin.stop(getMessageInCyanColor(`📁 Directory created at ${targetFolder}`));
|
|
212
|
+
}
|
|
213
|
+
displayBuildDirectoryAsTree(targetFolder) {
|
|
214
|
+
const buildDirectory = directoryToJson(targetFolder);
|
|
215
|
+
const tree = treeify.asTree(buildDirectory, true, true);
|
|
216
|
+
const coloredLogString = tree
|
|
217
|
+
.split("\n")
|
|
218
|
+
.map((line) => line.replace(/#.*/, (match) => getMessageInGreenColor(match)))
|
|
219
|
+
.join("\n");
|
|
220
|
+
log.step(coloredLogString);
|
|
221
|
+
}
|
|
222
|
+
displayOutroMessage(buildDirectory) {
|
|
223
|
+
log.step(getMessageInCyanColor(`📢 Your API Portal is live at: ${this.serverUrl}\n`) +
|
|
224
|
+
getMessageInCyanColor(`Hot reload enabled! Edit files in ${buildDirectory} to see changes instantly reflected in your API Portal.\n`) +
|
|
225
|
+
getMessageInCyanColor(`Press CTRL+C to stop the server.`));
|
|
226
|
+
outro(getMessageInCyanColor(`What's next?\n`) +
|
|
227
|
+
getMessageInCyanColor(`- Use the API Playground or an SDK to call your API.\n`) +
|
|
228
|
+
getMessageInCyanColor(`- Customize the Portal theme, add API recipes and enable AI features: ${this.referenceDocumentationUrl}`));
|
|
229
|
+
}
|
|
230
|
+
getLoggedInFirst() {
|
|
231
|
+
log.step("You need to be logged in to continue.");
|
|
232
|
+
}
|
|
233
|
+
displayLoggedInMessage(email) {
|
|
234
|
+
log.success(`Successfully logged in as ${email}`);
|
|
235
|
+
}
|
|
236
|
+
logError(error) {
|
|
237
|
+
log.error(error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=quickstart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickstart.js","sourceRoot":"","sources":["../../../src/prompts/portal/quickstart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1G,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,UAAU,EACV,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IAAxD;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AsB;QACxC,GAAG,CAAC,IAAI,CACN,qBAAqB,CAAC,mCAAmC,IAAI,CAAC,SAAS,IAAI,CAAC;YAC5E,qBAAqB,CACnB,qCAAqC,cAAc,2DAA2D,CAC/G;YACD,qBAAqB,CAAC,kCAAkC,CAAC,CAC1D,CAAC;QACF,KAAK,CACH,qBAAqB,CAAC,gBAAgB,CAAC;YACvC,qBAAqB,CAAC,wDAAwD,CAAC;YAC/E,qBAAqB,CACnB,yEAAyE,IAAI,CAAC,yBAAyB,EAAE,CAC1G,CACF,CAAC;IACJ,CAAC;IAED,gBAAgB;QACd,GAAG,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAA;IACnD,CAAC;IAED,sBAAsB,CAAC,KAAa;QAClC,GAAG,CAAC,OAAO,CAAC,6BAA6B,KAAK,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import treeify from "treeify";
|
|
2
|
+
import { SdlEndpoint } from "../../../types/sdl/sdl.js";
|
|
3
|
+
export declare class PortalRecipePrompts {
|
|
4
|
+
private readonly spin;
|
|
5
|
+
displayWelcomeMessage(): void;
|
|
6
|
+
recipeNamePrompt(): Promise<string>;
|
|
7
|
+
removeQuotes(str: string): string;
|
|
8
|
+
buildConfigFilePathPrompt(buildDirectoryPath: string): Promise<string>;
|
|
9
|
+
stepNamePrompt(defaultStepName: string): Promise<string>;
|
|
10
|
+
displayStepsInformation(): void;
|
|
11
|
+
stepTypeSelectionPrompt(): Promise<string>;
|
|
12
|
+
displayContentStepInfo(): void;
|
|
13
|
+
endpointGroupNamePrompt(endpointGroups: Map<string, SdlEndpoint[]>): Promise<string>;
|
|
14
|
+
endpointNamePrompt(endpointGroups: Map<string, SdlEndpoint[]>, endpointGroupName: string): Promise<string>;
|
|
15
|
+
endpointDescriptionPrompt(endpointGroups: Map<string, SdlEndpoint[]>, endpointGroupName: string, endpointName: string): Promise<string>;
|
|
16
|
+
addAnotherStepSelectionPrompt(): Promise<boolean>;
|
|
17
|
+
overwriteApiRecipeInTocPrompt(): Promise<boolean>;
|
|
18
|
+
displayStepAddedSuccessfullyMessage(): void;
|
|
19
|
+
displayRecipeGenerationSuccessMessage(buildDirectoryPath: string): void;
|
|
20
|
+
startProgressIndicatorWithMessage(message: string): void;
|
|
21
|
+
stopProgressIndicatorWithMessage(message: string): void;
|
|
22
|
+
displayBuildDirectoryStructureAsTree(buildDirectoryTreeObject: treeify.TreeObject): void;
|
|
23
|
+
logError(error: string): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import treeify from "treeify";
|
|
4
|
+
import { intro, spinner, select, text, cancel, isCancel, outro, log, autocomplete } from "@clack/prompts";
|
|
5
|
+
import { getMessageInGreenColor } from "../../../utils/utils.js";
|
|
6
|
+
export class PortalRecipePrompts {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.spin = spinner();
|
|
9
|
+
}
|
|
10
|
+
displayWelcomeMessage() {
|
|
11
|
+
intro(`Welcome to the API Recipe Generation Wizard. 🪄`);
|
|
12
|
+
log.step(`This wizard will guide you through the process of creating an API Recipe.`);
|
|
13
|
+
log.message(`An API Recipe is a collection of steps that allows you to define a single use case for your API Documentation portal.`);
|
|
14
|
+
log.message(`ℹ️ Learn more: https://docs.apimatic.io/platform-api/#/http/guides/generating-on-prem-api-portal/api-recipes`);
|
|
15
|
+
log.message(`Let's get started! 🚀`);
|
|
16
|
+
}
|
|
17
|
+
async recipeNamePrompt() {
|
|
18
|
+
const recipeName = await text({
|
|
19
|
+
message: `📘 Enter a name for your API Recipe:`,
|
|
20
|
+
placeholder: "This name will be displayed in your API Documentation portal sidebar.",
|
|
21
|
+
validate: (name) => {
|
|
22
|
+
if (!name) {
|
|
23
|
+
return "Recipe name cannot be empty. Please provide a name for your API Recipe.";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
if (isCancel(recipeName)) {
|
|
28
|
+
cancel("Operation cancelled.");
|
|
29
|
+
return process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
return recipeName.trim();
|
|
32
|
+
}
|
|
33
|
+
//Todo: Find a better place for this function
|
|
34
|
+
removeQuotes(str) {
|
|
35
|
+
const quotes = ['"', "'"];
|
|
36
|
+
for (const quote of quotes) {
|
|
37
|
+
if (str.startsWith(quote) && str.endsWith(quote) && str.length > 1) {
|
|
38
|
+
return this.removeQuotes(str.slice(1, -1)); // Recursive call
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return str;
|
|
42
|
+
}
|
|
43
|
+
async buildConfigFilePathPrompt(buildDirectoryPath) {
|
|
44
|
+
const buildConfigFilePath = await text({
|
|
45
|
+
message: `⚠️ APIMATIC-BUILD.json is required and was not found in "${buildDirectoryPath}".\nPlease enter the path to your build config file (relative to this directory):`,
|
|
46
|
+
validate: (filePath) => {
|
|
47
|
+
if (!filePath) {
|
|
48
|
+
return "Build config file path cannot be empty. Please provide a valid file path.";
|
|
49
|
+
}
|
|
50
|
+
const cleanedPath = this.removeQuotes(filePath.trim());
|
|
51
|
+
const resolvedPath = path.resolve(buildDirectoryPath, cleanedPath);
|
|
52
|
+
if (!resolvedPath.endsWith(".json")) {
|
|
53
|
+
return "The content file must be a JSON (.json) file. Please provide a valid file path.";
|
|
54
|
+
}
|
|
55
|
+
if (fs.existsSync(resolvedPath) && fs.statSync(resolvedPath).isFile()) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
return "The specified path is either not a valid relative file path or it doesn't exist. Please provide a valid relative file path.";
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (isCancel(buildConfigFilePath)) {
|
|
62
|
+
cancel("Operation cancelled.");
|
|
63
|
+
return process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
return path.resolve(buildDirectoryPath, this.removeQuotes(buildConfigFilePath.trim()));
|
|
66
|
+
}
|
|
67
|
+
async stepNamePrompt(defaultStepName) {
|
|
68
|
+
const stepName = await text({
|
|
69
|
+
message: `Enter a name for the step:`,
|
|
70
|
+
defaultValue: defaultStepName,
|
|
71
|
+
placeholder: `Press enter to use the default, i.e. ${defaultStepName}`
|
|
72
|
+
});
|
|
73
|
+
if (isCancel(stepName)) {
|
|
74
|
+
cancel("Operation cancelled.");
|
|
75
|
+
return process.exit(0);
|
|
76
|
+
}
|
|
77
|
+
return stepName.trim();
|
|
78
|
+
}
|
|
79
|
+
displayStepsInformation() {
|
|
80
|
+
log.step(`🔧 Add Steps to your API Recipe:`);
|
|
81
|
+
log.message(`You can add:`);
|
|
82
|
+
log.message(`1. 📄 Content Step: Display custom content, such as instructions or information related to your API.`);
|
|
83
|
+
log.message(`2. 🔗 Endpoint Step: Display an API endpoint, its playground and other relevant details.`);
|
|
84
|
+
log.message(`💡 Steps appear in the order you add them.`);
|
|
85
|
+
log.message(`📝 Let's proceed to adding steps to your API Recipe. `);
|
|
86
|
+
}
|
|
87
|
+
async stepTypeSelectionPrompt() {
|
|
88
|
+
const stepType = await select({
|
|
89
|
+
message: `➕ Select the type of step you want to add:`,
|
|
90
|
+
options: [
|
|
91
|
+
{ value: "content", label: "Content Step", hint: "For displaying custom content" },
|
|
92
|
+
{ value: "endpoint", label: "Endpoint Step", hint: "For displaying an API endpoint with its details" }
|
|
93
|
+
]
|
|
94
|
+
});
|
|
95
|
+
if (isCancel(stepType)) {
|
|
96
|
+
cancel("Operation cancelled.");
|
|
97
|
+
return process.exit(0);
|
|
98
|
+
}
|
|
99
|
+
return stepType;
|
|
100
|
+
}
|
|
101
|
+
displayContentStepInfo() {
|
|
102
|
+
log.step("📝 Opening markdown editor for you to add content in...");
|
|
103
|
+
}
|
|
104
|
+
async endpointGroupNamePrompt(endpointGroups) {
|
|
105
|
+
const groupNames = Array.from(endpointGroups.keys()).map((name) => ({
|
|
106
|
+
value: name,
|
|
107
|
+
label: name
|
|
108
|
+
}));
|
|
109
|
+
const endpointGroupName = await autocomplete({
|
|
110
|
+
message: `Select the endpoint group name:`,
|
|
111
|
+
maxItems: 10,
|
|
112
|
+
options: groupNames
|
|
113
|
+
});
|
|
114
|
+
if (isCancel(endpointGroupName)) {
|
|
115
|
+
cancel("Operation cancelled.");
|
|
116
|
+
return process.exit(0);
|
|
117
|
+
}
|
|
118
|
+
return endpointGroupName.trim();
|
|
119
|
+
}
|
|
120
|
+
async endpointNamePrompt(endpointGroups, endpointGroupName) {
|
|
121
|
+
const endpoints = endpointGroups.get(endpointGroupName);
|
|
122
|
+
const endpointName = await autocomplete({
|
|
123
|
+
message: `Select the name of the endpoint:`,
|
|
124
|
+
maxItems: 10,
|
|
125
|
+
options: endpoints.map((endpoint) => ({
|
|
126
|
+
value: endpoint.Name,
|
|
127
|
+
label: endpoint.Name
|
|
128
|
+
}))
|
|
129
|
+
});
|
|
130
|
+
if (isCancel(endpointName)) {
|
|
131
|
+
cancel("Operation cancelled.");
|
|
132
|
+
return process.exit(0);
|
|
133
|
+
}
|
|
134
|
+
return endpointName.trim();
|
|
135
|
+
}
|
|
136
|
+
async endpointDescriptionPrompt(endpointGroups, endpointGroupName, endpointName) {
|
|
137
|
+
const defaultDescription = endpointGroups.get(endpointGroupName).find((e) => e.Name === endpointName).Description;
|
|
138
|
+
const endpointDescription = await text({
|
|
139
|
+
message: `Enter a description for the endpoint:`,
|
|
140
|
+
placeholder: `Optional. Leave this empty to use the endpoint description defined in the API Specification`,
|
|
141
|
+
defaultValue: defaultDescription
|
|
142
|
+
});
|
|
143
|
+
if (isCancel(endpointDescription)) {
|
|
144
|
+
cancel("Operation cancelled.");
|
|
145
|
+
return process.exit(0);
|
|
146
|
+
}
|
|
147
|
+
return endpointDescription.trim();
|
|
148
|
+
}
|
|
149
|
+
async addAnotherStepSelectionPrompt() {
|
|
150
|
+
const addAnotherStep = await select({
|
|
151
|
+
message: `Do you want to add another step?`,
|
|
152
|
+
options: [
|
|
153
|
+
{ value: "yes", label: "Yes" },
|
|
154
|
+
{ value: "no", label: "No" }
|
|
155
|
+
],
|
|
156
|
+
initialValue: "yes"
|
|
157
|
+
});
|
|
158
|
+
if (isCancel(addAnotherStep)) {
|
|
159
|
+
cancel("Operation cancelled.");
|
|
160
|
+
return process.exit(0);
|
|
161
|
+
}
|
|
162
|
+
return addAnotherStep === "yes";
|
|
163
|
+
}
|
|
164
|
+
async overwriteApiRecipeInTocPrompt() {
|
|
165
|
+
const overwriteApiRecipeInToc = await select({
|
|
166
|
+
message: `⚠️ An API Recipe with this name already exists. Do you want to overwrite it?`,
|
|
167
|
+
options: [
|
|
168
|
+
{ value: "yes", label: "Yes" },
|
|
169
|
+
{ value: "no", label: "No" }
|
|
170
|
+
]
|
|
171
|
+
});
|
|
172
|
+
if (isCancel(overwriteApiRecipeInToc)) {
|
|
173
|
+
cancel("Operation cancelled.");
|
|
174
|
+
return process.exit(0);
|
|
175
|
+
}
|
|
176
|
+
return overwriteApiRecipeInToc === "yes";
|
|
177
|
+
}
|
|
178
|
+
displayStepAddedSuccessfullyMessage() {
|
|
179
|
+
log.step(`Step has been added successfully.`);
|
|
180
|
+
}
|
|
181
|
+
displayRecipeGenerationSuccessMessage(buildDirectoryPath) {
|
|
182
|
+
log.message(`🎉 Your new API Recipe has been added to the source directory at: ${buildDirectoryPath}`);
|
|
183
|
+
outro(`▶ Run the command 'apimatic portal:serve' to preview your documentation portal.`);
|
|
184
|
+
}
|
|
185
|
+
startProgressIndicatorWithMessage(message) {
|
|
186
|
+
this.spin.start(message);
|
|
187
|
+
}
|
|
188
|
+
stopProgressIndicatorWithMessage(message) {
|
|
189
|
+
this.spin.stop(message);
|
|
190
|
+
}
|
|
191
|
+
displayBuildDirectoryStructureAsTree(buildDirectoryTreeObject) {
|
|
192
|
+
const tree = treeify.asTree(buildDirectoryTreeObject, true, true);
|
|
193
|
+
const coloredLogString = tree
|
|
194
|
+
.split("\n")
|
|
195
|
+
.map((line) => line.replace(/#.*/, (match) => getMessageInGreenColor(match)))
|
|
196
|
+
.join("\n");
|
|
197
|
+
log.step(`🛠️ You can edit the following files to customize your API Recipe :\n\n` + coloredLogString);
|
|
198
|
+
}
|
|
199
|
+
logError(error) {
|
|
200
|
+
outro(error);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=new-recipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-recipe.js","sourceRoot":"","sources":["../../../../src/prompts/portal/recipe/new-recipe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1G,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,MAAM,OAAO,mBAAmB;IAAhC;QACmB,SAAI,GAAG,OAAO,EAAE,CAAC;IAmPpC,CAAC;IAjPQ,qBAAqB;QAC1B,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACzD,GAAG,CAAC,IAAI,CAAC,2EAA2E,CAAC,CAAC;QACtF,GAAG,CAAC,OAAO,CACT,uHAAuH,CACxH,CAAC;QACF,GAAG,CAAC,OAAO,CACT,+GAA+G,CAChH,CAAC;QACF,GAAG,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACvC,CAAC;IAEM,KAAK,CAAC,gBAAgB;QAC3B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC;YAC5B,OAAO,EAAE,sCAAsC;YAC/C,WAAW,EAAE,uEAAuE;YACpF,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE;gBACjB,IAAI,CA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