@apimatic/cli 1.1.0-alpha.8 → 1.1.0-beta.1
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 +436 -374
- package/bin/run.js +5 -0
- package/lib/actions/action-result.d.ts +13 -0
- package/lib/actions/action-result.js +44 -0
- package/lib/actions/action-result.js.map +1 -0
- package/lib/actions/api/transform.d.ts +15 -0
- package/lib/actions/api/transform.js +48 -0
- package/lib/actions/api/transform.js.map +1 -0
- package/lib/actions/api/validate.d.ts +12 -0
- package/lib/actions/api/validate.js +41 -0
- package/lib/actions/api/validate.js.map +1 -0
- package/lib/actions/auth/login.d.ts +13 -0
- package/lib/actions/auth/login.js +55 -0
- package/lib/actions/auth/login.js.map +1 -0
- package/lib/actions/auth/logout.d.ts +8 -0
- package/lib/actions/auth/logout.js +15 -0
- package/lib/actions/auth/logout.js.map +1 -0
- package/lib/actions/auth/status.d.ts +11 -0
- package/lib/actions/auth/status.js +26 -0
- package/lib/actions/auth/status.js.map +1 -0
- package/lib/actions/portal/copilot.d.ts +16 -0
- package/lib/actions/portal/copilot.js +89 -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 +60 -55
- package/lib/actions/portal/generate.js.map +1 -0
- package/lib/actions/portal/quickstart.d.ts +16 -0
- package/lib/actions/portal/quickstart.js +146 -0
- package/lib/actions/portal/quickstart.js.map +1 -0
- package/lib/actions/portal/recipe/new-recipe.d.ts +15 -0
- package/lib/actions/portal/recipe/new-recipe.js +177 -0
- package/lib/actions/portal/recipe/new-recipe.js.map +1 -0
- package/lib/actions/portal/serve.d.ts +15 -0
- package/lib/actions/portal/serve.js +118 -0
- package/lib/actions/portal/serve.js.map +1 -0
- package/lib/actions/portal/toc/new-toc.d.ts +21 -0
- package/lib/actions/portal/toc/new-toc.js +97 -0
- package/lib/actions/portal/toc/new-toc.js.map +1 -0
- package/lib/actions/quickstart.d.ts +10 -0
- package/lib/actions/quickstart.js +30 -0
- package/lib/actions/quickstart.js.map +1 -0
- package/lib/actions/sdk/generate.d.ts +13 -0
- package/lib/actions/sdk/generate.js +47 -0
- package/lib/actions/sdk/generate.js.map +1 -0
- package/lib/actions/sdk/quickstart.d.ts +14 -0
- package/lib/actions/sdk/quickstart.js +149 -0
- package/lib/actions/sdk/quickstart.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 +21 -0
- package/lib/application/portal/recipe/recipe-generator.js +145 -0
- package/lib/application/portal/recipe/recipe-generator.js.map +1 -0
- package/lib/application/portal/{new/toc → toc}/toc-content-parser.d.ts +1 -1
- 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/{new/toc → toc}/toc-structure-generator.d.ts +1 -1
- 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 +7 -2
- package/lib/client-utils/auth-manager.js +26 -14
- package/lib/client-utils/auth-manager.js.map +1 -0
- package/lib/commands/api/transform.d.ts +10 -7
- package/lib/commands/api/transform.js +51 -111
- package/lib/commands/api/transform.js.map +1 -0
- package/lib/commands/api/validate.d.ts +7 -4
- package/lib/commands/api/validate.js +31 -74
- package/lib/commands/api/validate.js.map +1 -0
- package/lib/commands/auth/login.d.ts +3 -1
- package/lib/commands/auth/login.js +26 -68
- package/lib/commands/auth/login.js.map +1 -0
- package/lib/commands/auth/logout.d.ts +3 -1
- package/lib/commands/auth/logout.js +14 -21
- package/lib/commands/auth/logout.js.map +1 -0
- package/lib/commands/auth/status.d.ts +1 -0
- package/lib/commands/auth/status.js +18 -21
- package/lib/commands/auth/status.js.map +1 -0
- package/lib/commands/portal/copilot.d.ts +13 -0
- package/lib/commands/portal/copilot.js +34 -0
- package/lib/commands/portal/copilot.js.map +1 -0
- package/lib/commands/portal/generate.d.ts +7 -11
- package/lib/commands/portal/generate.js +26 -89
- package/lib/commands/portal/generate.js.map +1 -0
- package/lib/commands/portal/recipe/new.d.ts +12 -0
- package/lib/commands/portal/recipe/new.js +45 -0
- package/lib/commands/portal/recipe/new.js.map +1 -0
- package/lib/commands/portal/serve.d.ts +8 -8
- package/lib/commands/portal/serve.js +41 -125
- 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 +60 -0
- package/lib/commands/portal/toc/new.js.map +1 -0
- package/lib/commands/quickstart.d.ts +9 -0
- package/lib/commands/quickstart.js +37 -0
- package/lib/commands/quickstart.js.map +1 -0
- package/lib/commands/sdk/generate.d.ts +10 -8
- package/lib/commands/sdk/generate.js +46 -131
- package/lib/commands/sdk/generate.js.map +1 -0
- package/lib/config/axios-config.js +4 -6
- package/lib/config/axios-config.js.map +1 -0
- package/lib/hooks/not-found.d.ts +3 -0
- package/lib/hooks/not-found.js +52 -0
- package/lib/hooks/not-found.js.map +1 -0
- package/lib/hooks/utils.d.ts +5 -0
- package/lib/hooks/utils.js +51 -0
- package/lib/hooks/utils.js.map +1 -0
- package/lib/index.js +2 -5
- package/lib/index.js.map +1 -0
- package/lib/infrastructure/debounce-service.d.ts +10 -0
- package/lib/infrastructure/debounce-service.js +52 -0
- package/lib/infrastructure/debounce-service.js.map +1 -0
- package/lib/infrastructure/env-info.d.ts +12 -0
- package/lib/infrastructure/env-info.js +58 -0
- package/lib/infrastructure/env-info.js.map +1 -0
- package/lib/infrastructure/file-service.d.ts +24 -0
- package/lib/infrastructure/file-service.js +120 -0
- package/lib/infrastructure/file-service.js.map +1 -0
- package/lib/infrastructure/launcher-service.d.ts +9 -0
- package/lib/infrastructure/launcher-service.js +72 -0
- package/lib/infrastructure/launcher-service.js.map +1 -0
- package/lib/infrastructure/network-service.d.ts +3 -0
- package/lib/infrastructure/network-service.js +7 -0
- package/lib/infrastructure/network-service.js.map +1 -0
- package/lib/infrastructure/service-error.d.ts +16 -0
- package/lib/infrastructure/service-error.js +49 -0
- package/lib/infrastructure/service-error.js.map +1 -0
- package/lib/infrastructure/services/api-client-factory.d.ts +6 -0
- package/lib/infrastructure/services/api-client-factory.js +20 -0
- package/lib/infrastructure/services/api-client-factory.js.map +1 -0
- package/lib/infrastructure/services/api-service.d.ts +12 -0
- package/lib/infrastructure/services/api-service.js +79 -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 +37 -0
- package/lib/infrastructure/services/auth-service.js.map +1 -0
- package/lib/infrastructure/services/file-download-service.d.ts +15 -0
- package/lib/infrastructure/services/file-download-service.js +104 -0
- package/lib/infrastructure/services/file-download-service.js.map +1 -0
- package/lib/infrastructure/services/portal-service.d.ts +17 -12
- package/lib/infrastructure/services/portal-service.js +134 -99
- package/lib/infrastructure/services/portal-service.js.map +1 -0
- package/lib/infrastructure/services/telemetry-service.d.ts +9 -0
- package/lib/infrastructure/services/telemetry-service.js +38 -0
- package/lib/infrastructure/services/telemetry-service.js.map +1 -0
- package/lib/infrastructure/services/transformation-service.d.ts +23 -0
- package/lib/infrastructure/services/transformation-service.js +56 -0
- package/lib/infrastructure/services/transformation-service.js.map +1 -0
- package/lib/infrastructure/services/validation-service.d.ts +17 -0
- package/lib/infrastructure/services/validation-service.js +49 -0
- package/lib/infrastructure/services/validation-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/api/transform.d.ts +11 -0
- package/lib/prompts/api/transform.js +29 -0
- package/lib/prompts/api/transform.js.map +1 -0
- package/lib/prompts/api/validate.d.ts +12 -0
- package/lib/prompts/api/validate.js +40 -0
- package/lib/prompts/api/validate.js.map +1 -0
- package/lib/prompts/auth/login.d.ts +10 -0
- package/lib/prompts/auth/login.js +22 -0
- package/lib/prompts/auth/login.js.map +1 -0
- package/lib/prompts/auth/logout.d.ts +3 -0
- package/lib/prompts/auth/logout.js +7 -0
- package/lib/prompts/auth/logout.js.map +1 -0
- package/lib/prompts/auth/status.d.ts +8 -0
- package/lib/prompts/auth/status.js +22 -0
- package/lib/prompts/auth/status.js.map +1 -0
- package/lib/prompts/format.d.ts +31 -0
- package/lib/prompts/format.js +89 -0
- package/lib/prompts/format.js.map +1 -0
- package/lib/prompts/portal/copilot.d.ts +18 -0
- package/lib/prompts/portal/copilot.js +82 -0
- package/lib/prompts/portal/copilot.js.map +1 -0
- package/lib/prompts/portal/generate.d.ts +13 -8
- package/lib/prompts/portal/generate.js +36 -53
- package/lib/prompts/portal/generate.js.map +1 -0
- package/lib/prompts/portal/quickstart.d.ts +28 -29
- package/lib/prompts/portal/quickstart.js +102 -185
- package/lib/prompts/portal/quickstart.js.map +1 -0
- package/lib/prompts/portal/recipe/new-recipe.d.ts +29 -0
- package/lib/prompts/portal/recipe/new-recipe.js +165 -0
- package/lib/prompts/portal/recipe/new-recipe.js.map +1 -0
- package/lib/prompts/portal/serve.d.ts +9 -5
- package/lib/prompts/portal/serve.js +29 -19
- package/lib/prompts/portal/serve.js.map +1 -0
- package/lib/prompts/portal/toc/new-toc.d.ts +15 -0
- package/lib/prompts/portal/toc/new-toc.js +38 -0
- package/lib/prompts/portal/toc/new-toc.js.map +1 -0
- package/lib/prompts/prompt.d.ts +3 -0
- package/lib/prompts/prompt.js +37 -0
- package/lib/prompts/prompt.js.map +1 -0
- package/lib/prompts/quickstart.d.ts +6 -0
- package/lib/prompts/quickstart.js +25 -0
- package/lib/prompts/quickstart.js.map +1 -0
- package/lib/prompts/sdk/generate.d.ts +11 -0
- package/lib/prompts/sdk/generate.js +37 -0
- package/lib/prompts/sdk/generate.js.map +1 -0
- package/lib/prompts/sdk/quickstart.d.ts +32 -0
- package/lib/prompts/sdk/quickstart.js +140 -0
- package/lib/prompts/sdk/quickstart.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 +14 -25
- package/lib/types/api/transform.js +20 -23
- package/lib/types/api/transform.js.map +1 -0
- package/lib/types/build/build.d.ts +22 -0
- package/lib/types/build/build.js +7 -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 +33 -0
- package/lib/types/build-context.js.map +1 -0
- package/lib/types/common/command-metadata.d.ts +4 -0
- package/lib/types/common/command-metadata.js +2 -0
- package/lib/types/common/command-metadata.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/quickstart-completed.d.ts +7 -0
- package/lib/types/events/quickstart-completed.js +10 -0
- package/lib/types/events/quickstart-completed.js.map +1 -0
- package/lib/types/events/quickstart-initiated.d.ts +7 -0
- package/lib/types/events/quickstart-initiated.js +10 -0
- package/lib/types/events/quickstart-initiated.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/directory.d.ts +17 -0
- package/lib/types/file/directory.js +87 -0
- package/lib/types/file/directory.js.map +1 -0
- package/lib/types/file/directoryPath.d.ts +10 -0
- package/lib/types/file/directoryPath.js +26 -0
- package/lib/types/file/directoryPath.js.map +1 -0
- package/lib/types/file/fileName.d.ts +7 -0
- package/lib/types/file/fileName.js +21 -0
- package/lib/types/file/fileName.js.map +1 -0
- package/lib/types/file/filePath.d.ts +10 -0
- package/lib/types/file/filePath.js +32 -0
- package/lib/types/file/filePath.js.map +1 -0
- package/lib/types/file/resource-input.d.ts +5 -0
- package/lib/types/file/resource-input.js +42 -0
- package/lib/types/file/resource-input.js.map +1 -0
- package/lib/types/file/urlPath.d.ts +6 -0
- package/lib/types/file/urlPath.js +22 -0
- package/lib/types/file/urlPath.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-context.d.ts +13 -0
- package/lib/types/portal-context.js +38 -0
- package/lib/types/portal-context.js.map +1 -0
- package/lib/types/recipe/recipe.d.ts +22 -0
- package/lib/types/recipe/recipe.js +6 -0
- package/lib/types/recipe/recipe.js.map +1 -0
- package/lib/types/recipe-context.d.ts +9 -0
- package/lib/types/recipe-context.js +26 -0
- package/lib/types/recipe-context.js.map +1 -0
- package/lib/types/resource-context.d.ts +12 -0
- package/lib/types/resource-context.js +30 -0
- package/lib/types/resource-context.js.map +1 -0
- package/lib/types/sdk/generate.d.ts +9 -22
- package/lib/types/sdk/generate.js +25 -14
- package/lib/types/sdk/generate.js.map +1 -0
- package/lib/types/sdk-context.d.ts +14 -0
- package/lib/types/sdk-context.js +32 -0
- package/lib/types/sdk-context.js.map +1 -0
- package/lib/types/sdl/sdl.d.ts +10 -0
- package/lib/types/sdl/sdl.js +47 -3
- package/lib/types/sdl/sdl.js.map +1 -0
- package/lib/types/spec-context.d.ts +12 -0
- package/lib/types/spec-context.js +29 -0
- package/lib/types/spec-context.js.map +1 -0
- package/lib/types/temp-context.d.ts +11 -0
- package/lib/types/temp-context.js +27 -0
- package/lib/types/temp-context.js.map +1 -0
- package/lib/types/toc/toc.js +2 -10
- package/lib/types/toc/toc.js.map +1 -0
- package/lib/types/toc-context.d.ts +12 -0
- package/lib/types/toc-context.js +26 -0
- package/lib/types/toc-context.js.map +1 -0
- package/lib/types/transform-context.d.ts +13 -0
- package/lib/types/transform-context.js +30 -0
- package/lib/types/transform-context.js.map +1 -0
- package/lib/types/utils.d.ts +0 -9
- package/lib/types/utils.js +2 -3
- package/lib/types/utils.js.map +1 -0
- package/lib/utils/string-utils.d.ts +2 -0
- package/lib/utils/string-utils.js +37 -0
- package/lib/utils/string-utils.js.map +1 -0
- package/lib/utils/utils.d.ts +2 -44
- package/lib/utils/utils.js +14 -366
- package/lib/utils/utils.js.map +1 -0
- package/package.json +50 -31
- package/bin/run +0 -9
- package/lib/actions/portal/new/toc.d.ts +0 -17
- package/lib/actions/portal/new/toc.js +0 -134
- package/lib/application/portal/new/toc/sdl-parser.d.ts +0 -13
- package/lib/application/portal/new/toc/sdl-parser.js +0 -53
- package/lib/application/portal/new/toc/toc-content-parser.js +0 -46
- package/lib/application/portal/new/toc/toc-structure-generator.js +0 -88
- package/lib/client-utils/sdk-client.d.ts +0 -23
- package/lib/client-utils/sdk-client.js +0 -124
- package/lib/commands/portal/new/toc.d.ts +0 -15
- package/lib/commands/portal/new/toc.js +0 -65
- package/lib/commands/portal/quickstart.d.ts +0 -10
- package/lib/commands/portal/quickstart.js +0 -79
- package/lib/config/env.d.ts +0 -27
- package/lib/config/env.js +0 -31
- package/lib/controllers/api/transform.d.ts +0 -5
- package/lib/controllers/api/transform.js +0 -56
- package/lib/controllers/api/validate.d.ts +0 -3
- package/lib/controllers/api/validate.js +0 -33
- package/lib/controllers/portal/generate.d.ts +0 -3
- package/lib/controllers/portal/generate.js +0 -110
- package/lib/controllers/portal/quickstart.d.ts +0 -14
- package/lib/controllers/portal/quickstart.js +0 -258
- package/lib/controllers/portal/serve.d.ts +0 -3
- package/lib/controllers/portal/serve.js +0 -138
- package/lib/controllers/sdk/generate.d.ts +0 -4
- package/lib/controllers/sdk/generate.js +0 -66
- package/lib/prompts/portal/new/toc.d.ts +0 -10
- package/lib/prompts/portal/new/toc.js +0 -46
- package/lib/services/portal/server.d.ts +0 -14
- package/lib/services/portal/server.js +0 -101
- package/lib/types/api/validate.d.ts +0 -12
- package/lib/types/api/validate.js +0 -3
- package/lib/types/common/result.d.ts +0 -17
- package/lib/types/common/result.js +0 -36
- package/lib/types/portal/generate.d.ts +0 -26
- package/lib/types/portal/generate.js +0 -4
- package/lib/types/portal/quickstart.d.ts +0 -17
- package/lib/types/portal/quickstart.js +0 -3
- package/lib/validators/common/directoryValidator.d.ts +0 -9
- package/lib/validators/common/directoryValidator.js +0 -53
- package/lib/validators/common/portValidator.d.ts +0 -5
- package/lib/validators/common/portValidator.js +0 -20
- package/lib/validators/portal/serveValidator.d.ts +0 -6
- package/lib/validators/portal/serveValidator.js +0 -21
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// This code was originally forked from https://github.com/oclif/plugin-not-found/blob/main/src/index.ts
|
|
2
|
+
import { toConfiguredId } from "@oclif/core";
|
|
3
|
+
import { cyan, yellow } from "ansis";
|
|
4
|
+
import utils from "./utils.js";
|
|
5
|
+
const hook = async function (opts) {
|
|
6
|
+
var _a;
|
|
7
|
+
const hiddenCommandIds = new Set(opts.config.commands.filter((c) => c.hidden).map((c) => c.id));
|
|
8
|
+
const commandIDs = [...opts.config.commandIDs, ...opts.config.commands.flatMap((c) => c.aliases)].filter((c) => !hiddenCommandIds.has(c));
|
|
9
|
+
if (commandIDs.length === 0)
|
|
10
|
+
return;
|
|
11
|
+
let binHelp = `${opts.config.bin} help`;
|
|
12
|
+
const idSplit = opts.id.split(":");
|
|
13
|
+
if (opts.config.findTopic(idSplit[0])) {
|
|
14
|
+
binHelp = `${binHelp} ${idSplit[0]}`;
|
|
15
|
+
}
|
|
16
|
+
let suggestion;
|
|
17
|
+
if (/:?help:?/.test(opts.id)) {
|
|
18
|
+
suggestion = ["help", ...opts.id.split(":").filter((cmd) => cmd !== "help")].join(":");
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
suggestion = utils.closest(opts.id, commandIDs);
|
|
22
|
+
}
|
|
23
|
+
const readableSuggestion = suggestion ? toConfiguredId(suggestion, this.config) : null;
|
|
24
|
+
const originalCmd = toConfiguredId(opts.id, this.config);
|
|
25
|
+
this.warn(`${yellow(originalCmd)} is not a ${opts.config.bin} command.`);
|
|
26
|
+
if (!process.stdin.isTTY || !suggestion) {
|
|
27
|
+
this.error(`Run ${cyan.bold(binHelp)} for a list of available commands.`, {
|
|
28
|
+
exit: 127
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
let response;
|
|
32
|
+
try {
|
|
33
|
+
response = await utils.getConfirmation(readableSuggestion);
|
|
34
|
+
}
|
|
35
|
+
catch (_b) {
|
|
36
|
+
response = false;
|
|
37
|
+
}
|
|
38
|
+
if (response) {
|
|
39
|
+
const confirmedSuggestion = suggestion;
|
|
40
|
+
let argv = ((_a = opts.argv) === null || _a === void 0 ? void 0 : _a.length) ? opts.argv : opts.id.split(":").slice(confirmedSuggestion.split(":").length);
|
|
41
|
+
if (confirmedSuggestion.startsWith("help:")) {
|
|
42
|
+
argv = confirmedSuggestion.split(":").slice(1);
|
|
43
|
+
suggestion = "help";
|
|
44
|
+
}
|
|
45
|
+
return this.config.runCommand(confirmedSuggestion, argv);
|
|
46
|
+
}
|
|
47
|
+
this.error(`Run ${cyan.bold(binHelp)} for a list of available commands.`, {
|
|
48
|
+
exit: 127
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
export default hook;
|
|
52
|
+
//# sourceMappingURL=not-found.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-found.js","sourceRoot":"","sources":["../../src/hooks/not-found.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,OAAO,EAAQ,cAAc,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,MAAM,IAAI,GAAyB,KAAK,WAAW,I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GAAG,mBAAmB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC/C,UAAU,GAAG,MAAM,CAAC;QACtB,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oCAAoC,EAAE;QACxE,IAAI,EAAE,GAAG;KACV,CAAC,CAAC;AAEL,CAAC,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// This code was originally forked from https://github.com/oclif/plugin-not-found/blob/main/src/utils.ts
|
|
2
|
+
import readline from 'node:readline';
|
|
3
|
+
import { blueBright, reset } from 'ansis';
|
|
4
|
+
import levenshtein from 'fast-levenshtein';
|
|
5
|
+
const getConfirmation = async (suggestion) => {
|
|
6
|
+
if (!process.stdin.isTTY)
|
|
7
|
+
return false;
|
|
8
|
+
const question = `${reset('Did you mean ' + blueBright(suggestion) + '?')} (Y/n) `;
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
const rl = readline.createInterface({
|
|
11
|
+
input: process.stdin,
|
|
12
|
+
output: process.stdout,
|
|
13
|
+
});
|
|
14
|
+
let settled = false;
|
|
15
|
+
const cleanup = () => {
|
|
16
|
+
rl.close();
|
|
17
|
+
clearTimeout(timeout);
|
|
18
|
+
};
|
|
19
|
+
const finish = (result) => {
|
|
20
|
+
if (!settled) {
|
|
21
|
+
settled = true;
|
|
22
|
+
cleanup();
|
|
23
|
+
resolve(result);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const timeout = setTimeout(() => {
|
|
27
|
+
finish(false);
|
|
28
|
+
}, 10000);
|
|
29
|
+
rl.question(question, (answer) => {
|
|
30
|
+
const a = (answer !== null && answer !== void 0 ? answer : '').trim().toLowerCase();
|
|
31
|
+
finish(a === '' || a === 'y' || a === 'yes');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const closest = (target, possibilities) => {
|
|
36
|
+
let best = null;
|
|
37
|
+
let bestDistance = Infinity;
|
|
38
|
+
for (const id of possibilities) {
|
|
39
|
+
const distance = levenshtein.get(target, id, { useCollator: true });
|
|
40
|
+
if (distance < bestDistance) {
|
|
41
|
+
bestDistance = distance;
|
|
42
|
+
best = id;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return best;
|
|
46
|
+
};
|
|
47
|
+
export default {
|
|
48
|
+
closest,
|
|
49
|
+
getConfirmation,
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/hooks/utils.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAE3C,MAAM,eAAe,GAAG,KAAK,EAAE,UAAkB,EAAoB,EAAE;IACrE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IAEvC,MAAM,QAAQ,GAAG,GAAG,KAAK,CAAC,eAAe,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC;IAEnF,OAAO,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,EAAE;QACtC,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;YAClC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;QAEH,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,EAAE,CAAC,KAAK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,OAAO;IACP,eAAe;CAChB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var core_1 = require("@oclif/core");
|
|
4
|
-
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
|
|
5
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxvQ0FBa0M7QUFBekIsMkZBQUEsR0FBRyxPQUFBIn0=
|
|
1
|
+
export { run } from "@oclif/core";
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class DebounceService {
|
|
2
|
+
private isProcessing;
|
|
3
|
+
private latestHandler;
|
|
4
|
+
private debounceTimer;
|
|
5
|
+
private readonly debounceMs;
|
|
6
|
+
constructor(debounceMs?: number);
|
|
7
|
+
batchSingleRequest(handler: () => Promise<void>): Promise<void>;
|
|
8
|
+
private scheduleExecution;
|
|
9
|
+
close(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { clearTimeout, setTimeout } from "timers";
|
|
2
|
+
export class DebounceService {
|
|
3
|
+
constructor(debounceMs = 500) {
|
|
4
|
+
this.isProcessing = false;
|
|
5
|
+
this.latestHandler = null;
|
|
6
|
+
this.debounceTimer = null;
|
|
7
|
+
this.debounceMs = debounceMs;
|
|
8
|
+
}
|
|
9
|
+
async batchSingleRequest(handler) {
|
|
10
|
+
// Always store the latest handler
|
|
11
|
+
this.latestHandler = handler;
|
|
12
|
+
// If already processing, don't start a new timer. Just update the latest handler
|
|
13
|
+
if (this.isProcessing) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
// Clear any existing timer
|
|
17
|
+
if (this.debounceTimer) {
|
|
18
|
+
clearTimeout(this.debounceTimer);
|
|
19
|
+
}
|
|
20
|
+
// Set up debounced execution
|
|
21
|
+
this.scheduleExecution();
|
|
22
|
+
}
|
|
23
|
+
scheduleExecution() {
|
|
24
|
+
this.debounceTimer = setTimeout(async () => {
|
|
25
|
+
if (this.isProcessing) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.isProcessing = true;
|
|
29
|
+
this.debounceTimer = null;
|
|
30
|
+
try {
|
|
31
|
+
// Execute the latest handler if it exists
|
|
32
|
+
if (this.latestHandler) {
|
|
33
|
+
const currentHandler = this.latestHandler;
|
|
34
|
+
this.latestHandler = null;
|
|
35
|
+
await currentHandler();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
this.isProcessing = false;
|
|
40
|
+
}
|
|
41
|
+
}, this.debounceMs);
|
|
42
|
+
}
|
|
43
|
+
// Method to clear any pending execution.
|
|
44
|
+
close() {
|
|
45
|
+
if (this.debounceTimer) {
|
|
46
|
+
clearTimeout(this.debounceTimer);
|
|
47
|
+
this.debounceTimer = null;
|
|
48
|
+
}
|
|
49
|
+
this.latestHandler = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=debounce-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce-service.js","sourceRoot":"","sources":["../../src/infrastructure/debounce-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAElD,MAAM,OAAO,eAAe;IAM1B,YAAY,aAAqB,GAAG;QAL5B,iBAAY,GAAG,KAAK,CAAC;QACrB,kBAAa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C,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare class EnvInfo {
|
|
2
|
+
private static cachedCliVersion;
|
|
3
|
+
private static cachedUserAgent;
|
|
4
|
+
private static cachedBaseUrl;
|
|
5
|
+
private static cachedAuthBaseUrl;
|
|
6
|
+
getUserAgent(shell: string): string;
|
|
7
|
+
getCLIVersion(): string;
|
|
8
|
+
getBaseUrl(): string | undefined;
|
|
9
|
+
getAuthBaseUrl(): string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare const envInfo: EnvInfo;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { dirname, join } from "path";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
class EnvInfo {
|
|
6
|
+
getUserAgent(shell) {
|
|
7
|
+
if (!EnvInfo.cachedUserAgent) {
|
|
8
|
+
const osInfo = `${os.platform()} ${os.release()}`;
|
|
9
|
+
const engine = "Node.js";
|
|
10
|
+
const engineVersion = process.version;
|
|
11
|
+
EnvInfo.cachedUserAgent = `APIMATIC CLI/${this.getCLIVersion()} - (OS: ${osInfo}, Engine: ${engine}/${engineVersion}, Shell: ${shell})`;
|
|
12
|
+
}
|
|
13
|
+
return EnvInfo.cachedUserAgent;
|
|
14
|
+
}
|
|
15
|
+
getCLIVersion() {
|
|
16
|
+
if (EnvInfo.cachedCliVersion) {
|
|
17
|
+
return EnvInfo.cachedCliVersion;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
const __dirname = dirname(__filename);
|
|
22
|
+
const pkgPath = join(__dirname, "../../package.json");
|
|
23
|
+
const pkgJson = fs.readFileSync(pkgPath, "utf-8");
|
|
24
|
+
const pkg = JSON.parse(pkgJson);
|
|
25
|
+
const version = pkg.version || "unknown";
|
|
26
|
+
EnvInfo.cachedCliVersion = version;
|
|
27
|
+
return version;
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
return "unknown";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
getBaseUrl() {
|
|
34
|
+
if (EnvInfo.cachedBaseUrl) {
|
|
35
|
+
return EnvInfo.cachedBaseUrl;
|
|
36
|
+
}
|
|
37
|
+
const envBaseUrls = process.env.APIMATIC_BASE_URL;
|
|
38
|
+
if (envBaseUrls) {
|
|
39
|
+
EnvInfo.cachedBaseUrl = envBaseUrls.split(";")[0];
|
|
40
|
+
}
|
|
41
|
+
return EnvInfo.cachedBaseUrl;
|
|
42
|
+
}
|
|
43
|
+
getAuthBaseUrl() {
|
|
44
|
+
if (EnvInfo.cachedAuthBaseUrl) {
|
|
45
|
+
return EnvInfo.cachedAuthBaseUrl;
|
|
46
|
+
}
|
|
47
|
+
const envBaseUrls = process.env.APIMATIC_BASE_URL;
|
|
48
|
+
if (envBaseUrls) {
|
|
49
|
+
const baseUrls = envBaseUrls.split(";");
|
|
50
|
+
EnvInfo.cachedAuthBaseUrl = baseUrls.length === 2 ? baseUrls[1] : undefined;
|
|
51
|
+
}
|
|
52
|
+
return EnvInfo.cachedAuthBaseUrl;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
EnvInfo.cachedCliVersion = null;
|
|
56
|
+
EnvInfo.cachedUserAgent = null;
|
|
57
|
+
export const envInfo = new EnvInfo();
|
|
58
|
+
//# sourceMappingURL=env-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-info.js","sourceRoot":"","sources":["../../src/infrastructure/env-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,MAAM,UAAU,CAAC;AAE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;QACD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAClD,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,CAAC,aAAa,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,OAAO,CAAC,aAAa,CAAC;IAC/B,CAAC;IAEM,cAAc;QACnB,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAC9B,OAAO,OAAO,CAAC,iBAAiB,CAAC;QACnC,CAAC;QACD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAClD,IAAI,WAAW,EAAE,CAAC;YAChB,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACxC,OAAO,CAAC,iBAAiB,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9E,CAAC;QACD,OAAO,OAAO,CAAC,iBAAiB,CAAC;IACnC,CAAC;;AAvDc,wBAAgB,GAAkB,IAAI,CAAC;AACvC,uBAAe,GAAkB,IAAI,CAAC;AAwDvD,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { FilePath } from "../types/file/filePath.js";
|
|
3
|
+
import { DirectoryPath } from "../types/file/directoryPath.js";
|
|
4
|
+
import { Directory } from "../types/file/directory.js";
|
|
5
|
+
export declare class FileService {
|
|
6
|
+
fileExists(file: FilePath): Promise<boolean>;
|
|
7
|
+
directoryExists(dir: DirectoryPath): Promise<boolean>;
|
|
8
|
+
directoryEmpty(dir: DirectoryPath): Promise<boolean>;
|
|
9
|
+
cleanDirectory(dir: DirectoryPath): Promise<void>;
|
|
10
|
+
createDirectoryIfNotExists(dir: DirectoryPath): Promise<void>;
|
|
11
|
+
getDirectory(directoryPath: DirectoryPath): Promise<Directory>;
|
|
12
|
+
copyDirectoryContents(source: DirectoryPath, destination: DirectoryPath): Promise<void>;
|
|
13
|
+
deleteFile(filePath: FilePath): Promise<void>;
|
|
14
|
+
deleteDirectory(dirPath: DirectoryPath): Promise<void>;
|
|
15
|
+
getRelativePath(filePath: FilePath, basePath: DirectoryPath): string;
|
|
16
|
+
getStream(filePath: FilePath): Promise<fs.ReadStream>;
|
|
17
|
+
getContents(filePath: FilePath): Promise<string>;
|
|
18
|
+
writeFile(filePath: FilePath, stream: NodeJS.ReadableStream): Promise<void>;
|
|
19
|
+
ensurePathExists(filePath: FilePath): Promise<void>;
|
|
20
|
+
writeContents(filePath: FilePath, contents: string): Promise<void>;
|
|
21
|
+
copy(source: FilePath, destination: FilePath): Promise<void>;
|
|
22
|
+
copyToDir(source: FilePath, destination: DirectoryPath): Promise<void>;
|
|
23
|
+
isZipFile(filePath: FilePath): Promise<boolean>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import fsExtra from "fs-extra";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { pipeline } from "stream";
|
|
5
|
+
import { promisify } from "util";
|
|
6
|
+
import { DirectoryPath } from "../types/file/directoryPath.js";
|
|
7
|
+
import { Directory } from "../types/file/directory.js";
|
|
8
|
+
import { FileName } from "../types/file/fileName.js";
|
|
9
|
+
export class FileService {
|
|
10
|
+
async fileExists(file) {
|
|
11
|
+
try {
|
|
12
|
+
const stat = await fsExtra.stat(file.toString());
|
|
13
|
+
return stat.isFile();
|
|
14
|
+
}
|
|
15
|
+
catch (_a) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async directoryExists(dir) {
|
|
20
|
+
try {
|
|
21
|
+
const stat = await fsExtra.stat(dir.toString());
|
|
22
|
+
return stat.isDirectory();
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async directoryEmpty(dir) {
|
|
29
|
+
try {
|
|
30
|
+
const files = await fsExtra.readdir(dir.toString());
|
|
31
|
+
return files.filter((file) => !file.startsWith(".")).length === 0;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async cleanDirectory(dir) {
|
|
38
|
+
await fsExtra.ensureDir(dir.toString());
|
|
39
|
+
await fsExtra.emptyDir(dir.toString()); // removes everything inside, keeps the dir
|
|
40
|
+
}
|
|
41
|
+
async createDirectoryIfNotExists(dir) {
|
|
42
|
+
await fsExtra.ensureDir(dir.toString());
|
|
43
|
+
}
|
|
44
|
+
async getDirectory(directoryPath) {
|
|
45
|
+
const entries = await fsExtra.readdir(directoryPath.toString());
|
|
46
|
+
const results = await Promise.all(entries.map(async (entry) => {
|
|
47
|
+
const fullPath = path.join(directoryPath.toString(), entry);
|
|
48
|
+
const stat = await fsExtra.stat(fullPath);
|
|
49
|
+
return stat.isDirectory() ? await this.getDirectory(new DirectoryPath(fullPath)) : new FileName(entry);
|
|
50
|
+
}));
|
|
51
|
+
return new Directory(directoryPath, results);
|
|
52
|
+
}
|
|
53
|
+
async copyDirectoryContents(source, destination) {
|
|
54
|
+
const entries = await fsExtra.readdir(source.toString());
|
|
55
|
+
await Promise.all(entries.map(async (entry) => {
|
|
56
|
+
const srcEntry = path.join(source.toString(), entry);
|
|
57
|
+
const destEntry = path.join(destination.toString(), entry);
|
|
58
|
+
await fsExtra.copy(srcEntry, destEntry);
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
async deleteFile(filePath) {
|
|
62
|
+
const exists = await this.fileExists(filePath);
|
|
63
|
+
if (exists) {
|
|
64
|
+
await fsExtra.remove(filePath.toString());
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async deleteDirectory(dirPath) {
|
|
68
|
+
const exists = await this.directoryExists(dirPath);
|
|
69
|
+
if (exists) {
|
|
70
|
+
await fsExtra.remove(dirPath.toString());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
getRelativePath(filePath, basePath) {
|
|
74
|
+
const filePathStr = filePath.toString();
|
|
75
|
+
const basePathStr = basePath.toString();
|
|
76
|
+
if (filePathStr.startsWith(basePathStr)) {
|
|
77
|
+
const relativePath = filePathStr.substring(basePathStr.length).replace(/^[/\\]/, "");
|
|
78
|
+
return relativePath.replace(/\\/g, "/");
|
|
79
|
+
}
|
|
80
|
+
// Normalize the full path if it doesn't start with basePath
|
|
81
|
+
return filePathStr.replace(/\\/g, "/");
|
|
82
|
+
}
|
|
83
|
+
async getStream(filePath) {
|
|
84
|
+
return fs.createReadStream(filePath.toString());
|
|
85
|
+
}
|
|
86
|
+
async getContents(filePath) {
|
|
87
|
+
return await fsExtra.readFile(filePath.toString(), "utf-8");
|
|
88
|
+
}
|
|
89
|
+
async writeFile(filePath, stream) {
|
|
90
|
+
const writeStream = fs.createWriteStream(filePath.toString());
|
|
91
|
+
await streamPipeline(stream, writeStream);
|
|
92
|
+
}
|
|
93
|
+
async ensurePathExists(filePath) {
|
|
94
|
+
await fsExtra.ensureFile(filePath.toString());
|
|
95
|
+
}
|
|
96
|
+
async writeContents(filePath, contents) {
|
|
97
|
+
await fsExtra.writeFile(filePath.toString(), contents, "utf-8");
|
|
98
|
+
}
|
|
99
|
+
async copy(source, destination) {
|
|
100
|
+
await fsExtra.copyFile(source.toString(), destination.toString());
|
|
101
|
+
}
|
|
102
|
+
async copyToDir(source, destination) {
|
|
103
|
+
await fsExtra.copyFile(source.toString(), source.replaceDirectory(destination).toString());
|
|
104
|
+
}
|
|
105
|
+
async isZipFile(filePath) {
|
|
106
|
+
try {
|
|
107
|
+
const buffer = await fsExtra.readFile(filePath.toString());
|
|
108
|
+
return (buffer.length >= 4 &&
|
|
109
|
+
buffer[0] === 0x50 && // P
|
|
110
|
+
buffer[1] === 0x4b && // K
|
|
111
|
+
buffer[2] === 0x03 && // \x03
|
|
112
|
+
buffer[3] === 0x04); // \x04
|
|
113
|
+
}
|
|
114
|
+
catch (_a) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const streamPipeline = promisify(pipeline);
|
|
120
|
+
//# sourceMappingURL=file-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-service.js","sourceRoot":"","sources":["../../src/infrastructure/file-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,MAAM,OAAO,WAAW;IACf,KAAK,CAAC,UAAU,CAAC,IAAc;QACpC,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YACjD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,GAAkB;QAC7C,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;QA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ryPath.js";
|
|
4
|
+
export declare class LauncherService {
|
|
5
|
+
openFolderInIde(directoryPath: DirectoryPath, fileToOpen: FilePath): Promise<boolean>;
|
|
6
|
+
openInEditor(filePath: FilePath): Promise<void>;
|
|
7
|
+
openFile(filePath: FilePath): Promise<void>;
|
|
8
|
+
openUrlInBrowser(url: UrlPath): Promise<import("child_process").ChildProcess> | undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { execa } from "execa";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import { spawn } from "child_process";
|
|
4
|
+
import open from "open";
|
|
5
|
+
import isInCi from "is-in-ci";
|
|
6
|
+
export class LauncherService {
|
|
7
|
+
async openFolderInIde(directoryPath, fileToOpen) {
|
|
8
|
+
if (isInCi)
|
|
9
|
+
return false;
|
|
10
|
+
try {
|
|
11
|
+
await execa("code", [directoryPath.toString(), fileToOpen.toString()]);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
catch (_a) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async openInEditor(filePath) {
|
|
19
|
+
if (isInCi)
|
|
20
|
+
return;
|
|
21
|
+
try {
|
|
22
|
+
await execa("code", ["--wait", filePath.toString()]);
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
// TODO: check for fallback (start)
|
|
26
|
+
if (process.platform === "win32") {
|
|
27
|
+
await execa("cmd", ["/c", "start", "/wait", "notepad", filePath.toString()], { stdio: "ignore" });
|
|
28
|
+
}
|
|
29
|
+
else if (process.platform === "darwin") {
|
|
30
|
+
await execa("vim", [filePath.toString()], { stdio: "inherit" });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async openFile(filePath) {
|
|
35
|
+
const targetPath = filePath.toString();
|
|
36
|
+
// Determine the command and args without using the shell
|
|
37
|
+
let command;
|
|
38
|
+
let args;
|
|
39
|
+
switch (os.platform()) {
|
|
40
|
+
case "win32":
|
|
41
|
+
command = "cmd";
|
|
42
|
+
args = ["/c", "start", "", targetPath];
|
|
43
|
+
break;
|
|
44
|
+
case "darwin":
|
|
45
|
+
command = "open";
|
|
46
|
+
args = [targetPath];
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
command = "xdg-open";
|
|
50
|
+
args = [targetPath];
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const child = spawn(command, args, { stdio: "ignore", detached: true });
|
|
55
|
+
child.unref(); // Let it run without blocking
|
|
56
|
+
}
|
|
57
|
+
catch (_a) {
|
|
58
|
+
// Silently ignore errors
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
openUrlInBrowser(url) {
|
|
62
|
+
if (isInCi)
|
|
63
|
+
return;
|
|
64
|
+
try {
|
|
65
|
+
return open(url.toString());
|
|
66
|
+
}
|
|
67
|
+
catch (_a) {
|
|
68
|
+
// Silently ignore errors
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=launcher-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launcher-service.js","sourceRoot":"","sources":["../../src/infrastructure/launcher-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,MAAM,MAAM,UAAU,CAAC;AAG9B,MAAM,OAAO,eAAe;IACnB,KAAK,CAAC,eAAe,CAAC,aAA4B,EAAE,UAAoB;QAC7E,IAAI,MAAM;YAAE,OAAO,KAAK,CAAC;QACzB,IAAI,CAAC;YACH,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,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AAC;gBACpB,MAAM;YACR;gBACE,OAAO,GAAG,UAAU,CAAC;gBACrB,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;gBACpB,MAAM;QACV,CAAC;QAED,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YACxE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,8BAA8B;QAC/C,CAAC;QAAC,WAAM,CAAC;YACP,yBAAyB;QAC3B,CAAC;IACH,CAAC;IAEM,gBAAgB,CAAC,GAAY;QAClC,IAAI,MAAM;YAAE,OAAO;QACnB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC9B,CAAC;QAAC,WAAM,CAAC;YACP,yBAAyB;QAC3B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-service.js","sourceRoot":"","sources":["../../src/infrastructure/network-service.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAC;AAE/B,MAAM,OAAO,cAAc;IAClB,KAAK,CAAC,aAAa,CAAC,cAAwB;QACjD,OAAO,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class ServiceError {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
private readonly defaultMessage;
|
|
4
|
+
private static defaultErrorMessage;
|
|
5
|
+
static readonly NotFound: ServiceError;
|
|
6
|
+
static readonly ServerError: ServiceError;
|
|
7
|
+
static readonly NetworkError: ServiceError;
|
|
8
|
+
static readonly InvalidResponse: ServiceError;
|
|
9
|
+
static readonly UnAuthorized: ServiceError;
|
|
10
|
+
static badRequest(customMessage: string): ServiceError;
|
|
11
|
+
static forbidden(customMessage: string): ServiceError;
|
|
12
|
+
static readonly values: ServiceError[];
|
|
13
|
+
private constructor();
|
|
14
|
+
get errorMessage(): string;
|
|
15
|
+
}
|
|
16
|
+
export declare function handleServiceError(error: unknown): ServiceError;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { format as f } from "../prompts/format.js";
|
|
4
|
+
export class ServiceError {
|
|
5
|
+
static badRequest(customMessage) {
|
|
6
|
+
return new _a("BAD_REQUEST", customMessage);
|
|
7
|
+
}
|
|
8
|
+
static forbidden(customMessage) {
|
|
9
|
+
return new _a("FORBIDDEN", customMessage);
|
|
10
|
+
}
|
|
11
|
+
constructor(code, defaultMessage) {
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.defaultMessage = defaultMessage;
|
|
14
|
+
}
|
|
15
|
+
get errorMessage() {
|
|
16
|
+
return this.defaultMessage;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
_a = ServiceError;
|
|
20
|
+
ServiceError.defaultErrorMessage = `An unexpected error occurred, please try again later. If the problem persists, please reach out to our team at ${f.var("support@apimatic.io")}`;
|
|
21
|
+
ServiceError.NotFound = new _a("NOT_FOUND", "Resource not found.");
|
|
22
|
+
ServiceError.ServerError = new _a("SERVER_ERROR", _a.defaultErrorMessage);
|
|
23
|
+
ServiceError.NetworkError = new _a("NETWORK_ERROR", "Unable to connect to the server.");
|
|
24
|
+
ServiceError.InvalidResponse = new _a("INVALID_RESPONSE", _a.defaultErrorMessage);
|
|
25
|
+
ServiceError.UnAuthorized = new _a("UNAUTHORIZED", "Unauthorized access.");
|
|
26
|
+
ServiceError.values = [
|
|
27
|
+
_a.NotFound,
|
|
28
|
+
_a.ServerError,
|
|
29
|
+
_a.NetworkError,
|
|
30
|
+
_a.InvalidResponse,
|
|
31
|
+
_a.UnAuthorized
|
|
32
|
+
];
|
|
33
|
+
export function handleServiceError(error) {
|
|
34
|
+
var _b;
|
|
35
|
+
if (axios.isAxiosError(error)) {
|
|
36
|
+
const status = (_b = error.response) === null || _b === void 0 ? void 0 : _b.status;
|
|
37
|
+
if (status === 401)
|
|
38
|
+
return ServiceError.UnAuthorized;
|
|
39
|
+
if (status === 404)
|
|
40
|
+
return ServiceError.NotFound;
|
|
41
|
+
if (status === 500)
|
|
42
|
+
return ServiceError.ServerError;
|
|
43
|
+
if (error.code === "ECONNABORTED" || error.code === "ECONNREFUSED" || error.code === "ENOTFOUND") {
|
|
44
|
+
return ServiceError.NetworkError;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return ServiceError.ServerError;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=service-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-error.js","sourceRoot":"","sources":["../../src/infrastructure/service-error.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,OAAO,YAAY;IAUvB,MAAM,CAAC,UAAU,CAAC,aAAqB;QACrC,OAAO,IAAI,EAAY,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,CAAC,SAAS,CAAC,aAAqB;QACpC,OAAO,IAAI,EAAY,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IACtD,CAAC;IAUD,YAAoC,IAAY,EAAmB,cAAsB;QAArD,SAAI,GAAJ,IAAI,CAAQ;QAAmB,mBAAc,GAAd,cAAc,CAAQ;IAAG,CAAC;IAE7F,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;;;AA5Bc,gCAAmB,GAAG,kHAAkH,CAAC,CAAC,GAAG,CAC1J,qBAAqB,CACtB,EAAE,AAF+B,CAE9B;AAEY,qBAAQ,GAAG,IAAI,EAAY,CAAC,WAAW,EAAE,qBAAqB,CAAC,AAAvD,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