@asyncapi-actions-test/trusted-publishing-test_asyncapi-cli 4.1.3
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/LICENSE +201 -0
- package/README.md +117 -0
- package/assets/create-template/templates/default/asyncapi.yaml +34 -0
- package/assets/create-template/templates/default/package-lock.json +4062 -0
- package/assets/create-template/templates/default/package.json +10 -0
- package/assets/create-template/templates/default/readme.md +4 -0
- package/assets/create-template/templates/default/template/index.js +11 -0
- package/assets/examples/adeo-kafka-request-reply-asyncapi.yml +298 -0
- package/assets/examples/anyof-asyncapi.yml +36 -0
- package/assets/examples/application-headers-asyncapi.yml +86 -0
- package/assets/examples/correlation-id-asyncapi.yml +180 -0
- package/assets/examples/default-example.json +51 -0
- package/assets/examples/default-example.yaml +31 -0
- package/assets/examples/examples.json +82 -0
- package/assets/examples/gitter-streaming-asyncapi.yml +178 -0
- package/assets/examples/kraken-websocket-request-reply-message-filter-in-reply-asyncapi.yml +388 -0
- package/assets/examples/kraken-websocket-request-reply-multiple-channels-asyncapi.yml +394 -0
- package/assets/examples/mercure-asyncapi.yml +58 -0
- package/assets/examples/not-asyncapi.yml +29 -0
- package/assets/examples/oneof-asyncapi.yml +57 -0
- package/assets/examples/operation-security-asyncapi.yml +117 -0
- package/assets/examples/rpc-client-asyncapi.yml +72 -0
- package/assets/examples/rpc-server-asyncapi.yml +69 -0
- package/assets/examples/simple-asyncapi.yml +31 -0
- package/assets/examples/slack-rtm-asyncapi.yml +982 -0
- package/assets/examples/streetlights-kafka-asyncapi.yml +199 -0
- package/assets/examples/streetlights-mqtt-asyncapi.yml +253 -0
- package/assets/examples/streetlights-operation-security-asyncapi.yml +240 -0
- package/assets/examples/tutorial.yml +41 -0
- package/assets/examples/websocket-gemini-asyncapi.yml +301 -0
- package/assets/logo.png +0 -0
- package/assets/server-api.png +0 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +12 -0
- package/bin/run.cmd +3 -0
- package/bin/run_bin +13 -0
- package/bin/run_bin.cmd +3 -0
- package/lib/apps/api/app.d.ts +15 -0
- package/lib/apps/api/app.js +91 -0
- package/lib/apps/api/configs/development.json +16 -0
- package/lib/apps/api/configs/production.json +16 -0
- package/lib/apps/api/configs/test.json +16 -0
- package/lib/apps/api/constants.d.ts +1 -0
- package/lib/apps/api/constants.js +4 -0
- package/lib/apps/api/controllers/bundle.controller.d.ts +7 -0
- package/lib/apps/api/controllers/bundle.controller.js +44 -0
- package/lib/apps/api/controllers/convert.controller.d.ts +11 -0
- package/lib/apps/api/controllers/convert.controller.js +69 -0
- package/lib/apps/api/controllers/diff.controller.d.ts +7 -0
- package/lib/apps/api/controllers/diff.controller.js +42 -0
- package/lib/apps/api/controllers/docs.controller.d.ts +6 -0
- package/lib/apps/api/controllers/docs.controller.js +24 -0
- package/lib/apps/api/controllers/generate.controller.d.ts +22 -0
- package/lib/apps/api/controllers/generate.controller.js +174 -0
- package/lib/apps/api/controllers/help.controller.d.ts +6 -0
- package/lib/apps/api/controllers/help.controller.js +101 -0
- package/lib/apps/api/controllers/parse.controller.d.ts +10 -0
- package/lib/apps/api/controllers/parse.controller.js +35 -0
- package/lib/apps/api/controllers/validate.controller.d.ts +10 -0
- package/lib/apps/api/controllers/validate.controller.js +50 -0
- package/lib/apps/api/controllers/version.controller.d.ts +8 -0
- package/lib/apps/api/controllers/version.controller.js +69 -0
- package/lib/apps/api/exceptions/problem.exception.d.ts +14 -0
- package/lib/apps/api/exceptions/problem.exception.js +10 -0
- package/lib/apps/api/index.d.ts +10 -0
- package/lib/apps/api/index.js +23 -0
- package/lib/apps/api/middlewares/logger.middleware.d.ts +2 -0
- package/lib/apps/api/middlewares/logger.middleware.js +12 -0
- package/lib/apps/api/middlewares/problem.middleware.d.ts +6 -0
- package/lib/apps/api/middlewares/problem.middleware.js +27 -0
- package/lib/apps/api/middlewares/validation.middleware.d.ts +12 -0
- package/lib/apps/api/middlewares/validation.middleware.js +245 -0
- package/lib/apps/api/server.d.ts +3 -0
- package/lib/apps/api/server.js +19 -0
- package/lib/apps/cli/commands/bundle.d.ts +15 -0
- package/lib/apps/cli/commands/bundle.js +75 -0
- package/lib/apps/cli/commands/config/analytics.d.ts +11 -0
- package/lib/apps/cli/commands/config/analytics.js +61 -0
- package/lib/apps/cli/commands/config/auth/add.d.ts +13 -0
- package/lib/apps/cli/commands/config/auth/add.js +68 -0
- package/lib/apps/cli/commands/config/context/add.d.ts +13 -0
- package/lib/apps/cli/commands/config/context/add.js +46 -0
- package/lib/apps/cli/commands/config/context/current.d.ts +8 -0
- package/lib/apps/cli/commands/config/context/current.js +37 -0
- package/lib/apps/cli/commands/config/context/edit.d.ts +12 -0
- package/lib/apps/cli/commands/config/context/edit.js +44 -0
- package/lib/apps/cli/commands/config/context/index.d.ts +5 -0
- package/lib/apps/cli/commands/config/context/index.js +16 -0
- package/lib/apps/cli/commands/config/context/init.d.ts +12 -0
- package/lib/apps/cli/commands/config/context/init.js +31 -0
- package/lib/apps/cli/commands/config/context/list.d.ts +8 -0
- package/lib/apps/cli/commands/config/context/list.js +36 -0
- package/lib/apps/cli/commands/config/context/remove.d.ts +11 -0
- package/lib/apps/cli/commands/config/context/remove.js +39 -0
- package/lib/apps/cli/commands/config/context/use.d.ts +11 -0
- package/lib/apps/cli/commands/config/context/use.js +40 -0
- package/lib/apps/cli/commands/config/index.d.ts +5 -0
- package/lib/apps/cli/commands/config/index.js +16 -0
- package/lib/apps/cli/commands/config/versions.d.ts +8 -0
- package/lib/apps/cli/commands/config/versions.js +56 -0
- package/lib/apps/cli/commands/convert.d.ts +21 -0
- package/lib/apps/cli/commands/convert.js +85 -0
- package/lib/apps/cli/commands/diff.d.ts +36 -0
- package/lib/apps/cli/commands/diff.js +335 -0
- package/lib/apps/cli/commands/format.d.ts +18 -0
- package/lib/apps/cli/commands/format.js +97 -0
- package/lib/apps/cli/commands/generate/client.d.ts +30 -0
- package/lib/apps/cli/commands/generate/client.js +94 -0
- package/lib/apps/cli/commands/generate/fromTemplate.d.ts +29 -0
- package/lib/apps/cli/commands/generate/fromTemplate.js +91 -0
- package/lib/apps/cli/commands/generate/index.d.ts +5 -0
- package/lib/apps/cli/commands/generate/index.js +15 -0
- package/lib/apps/cli/commands/generate/models.d.ts +16 -0
- package/lib/apps/cli/commands/generate/models.js +166 -0
- package/lib/apps/cli/commands/new/file.d.ts +16 -0
- package/lib/apps/cli/commands/new/file.js +180 -0
- package/lib/apps/cli/commands/new/index.d.ts +5 -0
- package/lib/apps/cli/commands/new/index.js +15 -0
- package/lib/apps/cli/commands/new/template.d.ts +18 -0
- package/lib/apps/cli/commands/new/template.js +102 -0
- package/lib/apps/cli/commands/optimize.d.ts +41 -0
- package/lib/apps/cli/commands/optimize.js +289 -0
- package/lib/apps/cli/commands/pretty.d.ts +12 -0
- package/lib/apps/cli/commands/pretty.js +70 -0
- package/lib/apps/cli/commands/start/api.d.ts +11 -0
- package/lib/apps/cli/commands/start/api.js +23 -0
- package/lib/apps/cli/commands/start/index.d.ts +5 -0
- package/lib/apps/cli/commands/start/index.js +15 -0
- package/lib/apps/cli/commands/start/preview.d.ts +17 -0
- package/lib/apps/cli/commands/start/preview.js +41 -0
- package/lib/apps/cli/commands/start/studio.d.ts +16 -0
- package/lib/apps/cli/commands/start/studio.js +94 -0
- package/lib/apps/cli/commands/validate.d.ts +23 -0
- package/lib/apps/cli/commands/validate.js +95 -0
- package/lib/apps/cli/internal/args/generate.args.d.ts +3 -0
- package/lib/apps/cli/internal/args/generate.args.js +10 -0
- package/lib/apps/cli/internal/base/BaseGeneratorCommand.d.ts +42 -0
- package/lib/apps/cli/internal/base/BaseGeneratorCommand.js +119 -0
- package/lib/apps/cli/internal/base.d.ts +20 -0
- package/lib/apps/cli/internal/base.js +173 -0
- package/lib/apps/cli/internal/flags/bundle.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/bundle.flags.js +26 -0
- package/lib/apps/cli/internal/flags/config/analytics.flags.d.ts +6 -0
- package/lib/apps/cli/internal/flags/config/analytics.flags.js +24 -0
- package/lib/apps/cli/internal/flags/config/context.flags.d.ts +4 -0
- package/lib/apps/cli/internal/flags/config/context.flags.js +16 -0
- package/lib/apps/cli/internal/flags/convert.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/convert.flags.js +32 -0
- package/lib/apps/cli/internal/flags/diff.flags.d.ts +13 -0
- package/lib/apps/cli/internal/flags/diff.flags.js +29 -0
- package/lib/apps/cli/internal/flags/format.flags.d.ts +6 -0
- package/lib/apps/cli/internal/flags/format.flags.js +22 -0
- package/lib/apps/cli/internal/flags/generate/clients.flags.d.ts +16 -0
- package/lib/apps/cli/internal/flags/generate/clients.flags.js +8 -0
- package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.d.ts +16 -0
- package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.js +8 -0
- package/lib/apps/cli/internal/flags/generate/models.flags.d.ts +1 -0
- package/lib/apps/cli/internal/flags/generate/models.flags.js +14 -0
- package/lib/apps/cli/internal/flags/generate/sharedFlags.d.ts +16 -0
- package/lib/apps/cli/internal/flags/generate/sharedFlags.js +57 -0
- package/lib/apps/cli/internal/flags/global.flags.d.ts +4 -0
- package/lib/apps/cli/internal/flags/global.flags.js +18 -0
- package/lib/apps/cli/internal/flags/new/file.flags.d.ts +8 -0
- package/lib/apps/cli/internal/flags/new/file.flags.js +20 -0
- package/lib/apps/cli/internal/flags/new/template.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/new/template.flags.js +28 -0
- package/lib/apps/cli/internal/flags/optimize.flags.d.ts +21 -0
- package/lib/apps/cli/internal/flags/optimize.flags.js +51 -0
- package/lib/apps/cli/internal/flags/parser.flags.d.ts +10 -0
- package/lib/apps/cli/internal/flags/parser.flags.js +28 -0
- package/lib/apps/cli/internal/flags/pretty.flags.d.ts +3 -0
- package/lib/apps/cli/internal/flags/pretty.flags.js +13 -0
- package/lib/apps/cli/internal/flags/proxy.flags.d.ts +4 -0
- package/lib/apps/cli/internal/flags/proxy.flags.js +17 -0
- package/lib/apps/cli/internal/flags/start/api.flags.d.ts +5 -0
- package/lib/apps/cli/internal/flags/start/api.flags.js +20 -0
- package/lib/apps/cli/internal/flags/start/preview.flags.d.ts +9 -0
- package/lib/apps/cli/internal/flags/start/preview.flags.js +32 -0
- package/lib/apps/cli/internal/flags/start/studio.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/start/studio.flags.js +25 -0
- package/lib/apps/cli/internal/flags/validate.flags.d.ts +11 -0
- package/lib/apps/cli/internal/flags/validate.flags.js +22 -0
- package/lib/apps/cli/internal/globals.d.ts +10 -0
- package/lib/apps/cli/internal/globals.js +46 -0
- package/lib/apps/cli/internal/hooks/command_not_found/myhook.d.ts +4 -0
- package/lib/apps/cli/internal/hooks/command_not_found/myhook.js +85 -0
- package/lib/domains/models/Context.d.ts +21 -0
- package/lib/domains/models/Context.js +321 -0
- package/lib/domains/models/Preview.d.ts +2 -0
- package/lib/domains/models/Preview.js +227 -0
- package/lib/domains/models/SpecificationFile.d.ts +40 -0
- package/lib/domains/models/SpecificationFile.js +295 -0
- package/lib/domains/models/Studio.d.ts +2 -0
- package/lib/domains/models/Studio.js +182 -0
- package/lib/domains/models/generate/ClientLanguages.d.ts +12 -0
- package/lib/domains/models/generate/ClientLanguages.js +17 -0
- package/lib/domains/models/generate/Flags.d.ts +9 -0
- package/lib/domains/models/generate/Flags.js +2 -0
- package/lib/domains/services/archiver.service.d.ts +17 -0
- package/lib/domains/services/archiver.service.js +53 -0
- package/lib/domains/services/base.service.d.ts +6 -0
- package/lib/domains/services/base.service.js +26 -0
- package/lib/domains/services/config.service.d.ts +42 -0
- package/lib/domains/services/config.service.js +95 -0
- package/lib/domains/services/convert.service.d.ts +12 -0
- package/lib/domains/services/convert.service.js +65 -0
- package/lib/domains/services/generator.service.d.ts +15 -0
- package/lib/domains/services/generator.service.js +75 -0
- package/lib/domains/services/validation.service.d.ts +54 -0
- package/lib/domains/services/validation.service.js +375 -0
- package/lib/errors/context-error.d.ts +26 -0
- package/lib/errors/context-error.js +71 -0
- package/lib/errors/diff-error.d.ts +9 -0
- package/lib/errors/diff-error.js +27 -0
- package/lib/errors/generator-error.d.ts +3 -0
- package/lib/errors/generator-error.js +11 -0
- package/lib/errors/specification-file.d.ts +18 -0
- package/lib/errors/specification-file.js +65 -0
- package/lib/errors/validation-error.d.ts +11 -0
- package/lib/errors/validation-error.js +55 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +11 -0
- package/lib/interfaces/index.d.ts +87 -0
- package/lib/interfaces/index.js +7 -0
- package/lib/utils/ajv.d.ts +2 -0
- package/lib/utils/ajv.js +18 -0
- package/lib/utils/app-openapi.d.ts +4 -0
- package/lib/utils/app-openapi.js +28 -0
- package/lib/utils/generate/flags.d.ts +2 -0
- package/lib/utils/generate/flags.js +14 -0
- package/lib/utils/generate/mapBaseUrl.d.ts +6 -0
- package/lib/utils/generate/mapBaseUrl.js +34 -0
- package/lib/utils/generate/parseParams.d.ts +3 -0
- package/lib/utils/generate/parseParams.js +58 -0
- package/lib/utils/generate/prompts.d.ts +4 -0
- package/lib/utils/generate/prompts.js +77 -0
- package/lib/utils/generate/registry.d.ts +2 -0
- package/lib/utils/generate/registry.js +30 -0
- package/lib/utils/generate/watcher.d.ts +51 -0
- package/lib/utils/generate/watcher.js +230 -0
- package/lib/utils/logger.d.ts +6 -0
- package/lib/utils/logger.js +33 -0
- package/lib/utils/retrieve-language.d.ts +1 -0
- package/lib/utils/retrieve-language.js +9 -0
- package/lib/utils/scoreCalculator.d.ts +2 -0
- package/lib/utils/scoreCalculator.js +22 -0
- package/lib/utils/temp-dir.d.ts +2 -0
- package/lib/utils/temp-dir.js +26 -0
- package/oclif.manifest.json +2137 -0
- package/openapi.yaml +713 -0
- package/package.json +203 -0
- package/scripts/enableAutoComplete.js +160 -0
- package/scripts/fetch-asyncapi-example.js +126 -0
- package/scripts/generateTypesForGenerateCommand.js +40 -0
- package/scripts/releasePackagesRename.js +88 -0
- package/scripts/updateUsageDocs.js +73 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Command from '../internal/base';
|
|
2
|
+
import { Parser } from '@asyncapi/parser';
|
|
3
|
+
export declare enum Optimizations {
|
|
4
|
+
REMOVE_COMPONENTS = "remove-components",
|
|
5
|
+
REUSE_COMPONENTS = "reuse-components",
|
|
6
|
+
MOVE_DUPLICATES_TO_COMPONENTS = "move-duplicates-to-components",
|
|
7
|
+
MOVE_ALL_TO_COMPONENTS = "move-all-to-components"
|
|
8
|
+
}
|
|
9
|
+
export declare enum DisableOptimizations {
|
|
10
|
+
SCHEMA = "schema"
|
|
11
|
+
}
|
|
12
|
+
export declare enum Outputs {
|
|
13
|
+
TERMINAL = "terminal",
|
|
14
|
+
NEW_FILE = "new-file",
|
|
15
|
+
OVERWRITE = "overwrite"
|
|
16
|
+
}
|
|
17
|
+
export default class Optimize extends Command {
|
|
18
|
+
static description: string;
|
|
19
|
+
isInteractive: boolean;
|
|
20
|
+
selectedOptimizations?: Optimizations[];
|
|
21
|
+
disableOptimizations?: DisableOptimizations[];
|
|
22
|
+
outputMethod?: Outputs;
|
|
23
|
+
static examples: string[];
|
|
24
|
+
static flags: {
|
|
25
|
+
proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
26
|
+
proxyPort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
27
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
28
|
+
optimization: import("@oclif/core/lib/interfaces").OptionFlag<string[], import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
29
|
+
ignore: import("@oclif/core/lib/interfaces").OptionFlag<string[], import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
30
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
31
|
+
'no-tty': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
32
|
+
};
|
|
33
|
+
static args: {
|
|
34
|
+
'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
35
|
+
};
|
|
36
|
+
parser: Parser;
|
|
37
|
+
run(): Promise<void>;
|
|
38
|
+
private showOptimizations;
|
|
39
|
+
private interactiveRun;
|
|
40
|
+
private collectMetricsData;
|
|
41
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Outputs = exports.DisableOptimizations = exports.Optimizations = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
const optimizer_1 = require("@asyncapi/optimizer");
|
|
7
|
+
const base_1 = tslib_1.__importDefault(require("../internal/base"));
|
|
8
|
+
const validation_error_1 = require("../../../errors/validation-error");
|
|
9
|
+
const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
|
|
10
|
+
const inquirer = tslib_1.__importStar(require("inquirer"));
|
|
11
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
12
|
+
const fs_1 = require("fs");
|
|
13
|
+
const parser_1 = require("@asyncapi/parser");
|
|
14
|
+
const optimize_flags_1 = require("../internal/flags/optimize.flags");
|
|
15
|
+
const proxy_flags_1 = require("../internal/flags/proxy.flags");
|
|
16
|
+
const { writeFile } = fs_1.promises;
|
|
17
|
+
var Optimizations;
|
|
18
|
+
(function (Optimizations) {
|
|
19
|
+
Optimizations["REMOVE_COMPONENTS"] = "remove-components";
|
|
20
|
+
Optimizations["REUSE_COMPONENTS"] = "reuse-components";
|
|
21
|
+
Optimizations["MOVE_DUPLICATES_TO_COMPONENTS"] = "move-duplicates-to-components";
|
|
22
|
+
Optimizations["MOVE_ALL_TO_COMPONENTS"] = "move-all-to-components";
|
|
23
|
+
})(Optimizations || (exports.Optimizations = Optimizations = {}));
|
|
24
|
+
var DisableOptimizations;
|
|
25
|
+
(function (DisableOptimizations) {
|
|
26
|
+
DisableOptimizations["SCHEMA"] = "schema";
|
|
27
|
+
})(DisableOptimizations || (exports.DisableOptimizations = DisableOptimizations = {}));
|
|
28
|
+
var Outputs;
|
|
29
|
+
(function (Outputs) {
|
|
30
|
+
Outputs["TERMINAL"] = "terminal";
|
|
31
|
+
Outputs["NEW_FILE"] = "new-file";
|
|
32
|
+
Outputs["OVERWRITE"] = "overwrite";
|
|
33
|
+
})(Outputs || (exports.Outputs = Outputs = {}));
|
|
34
|
+
class Optimize extends base_1.default {
|
|
35
|
+
constructor() {
|
|
36
|
+
super(...arguments);
|
|
37
|
+
this.isInteractive = false;
|
|
38
|
+
this.parser = new parser_1.Parser();
|
|
39
|
+
}
|
|
40
|
+
run() {
|
|
41
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
var _a, _b, _c, _d;
|
|
43
|
+
const { args, flags } = yield this.parse(Optimize); //NOSONAR
|
|
44
|
+
let filePath = args['spec-file'];
|
|
45
|
+
const proxyHost = flags['proxyHost'];
|
|
46
|
+
const proxyPort = flags['proxyPort'];
|
|
47
|
+
if (proxyHost && proxyPort) {
|
|
48
|
+
const proxyUrl = `http://${proxyHost}:${proxyPort}`;
|
|
49
|
+
filePath = `${filePath}+${proxyUrl}`; // Update filePath with proxyUrl
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
this.specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
if (err.message.includes('Failed to download')) {
|
|
56
|
+
throw new Error('Proxy Connection Error: Unable to establish a connection to the proxy check hostName or PortNumber.');
|
|
57
|
+
}
|
|
58
|
+
else if (filePath) {
|
|
59
|
+
this.error(new validation_error_1.ValidationError({
|
|
60
|
+
type: 'invalid-file',
|
|
61
|
+
filepath: filePath,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.error(new validation_error_1.ValidationError({
|
|
66
|
+
type: 'no-spec-found',
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
let optimizer;
|
|
71
|
+
let report;
|
|
72
|
+
try {
|
|
73
|
+
optimizer = new optimizer_1.Optimizer(this.specFile.text());
|
|
74
|
+
report = yield optimizer.getReport();
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
this.error(new validation_error_1.ValidationError({
|
|
78
|
+
type: 'invalid-syntax-file',
|
|
79
|
+
filepath: this.specFile.getFilePath(),
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
this.isInteractive = !flags['no-tty'];
|
|
83
|
+
this.selectedOptimizations = flags.optimization;
|
|
84
|
+
this.disableOptimizations = flags.ignore;
|
|
85
|
+
this.outputMethod = flags.output;
|
|
86
|
+
this.metricsMetadata.optimized = false;
|
|
87
|
+
if (!(((_a = report.moveDuplicatesToComponents) === null || _a === void 0 ? void 0 : _a.length) ||
|
|
88
|
+
((_b = report.removeComponents) === null || _b === void 0 ? void 0 : _b.length) ||
|
|
89
|
+
((_c = report.reuseComponents) === null || _c === void 0 ? void 0 : _c.length))) {
|
|
90
|
+
this.log(`🎉 Great news! Your file at ${(_d = this.specFile.getFilePath()) !== null && _d !== void 0 ? _d : this.specFile.getFileURL()} is already optimized.`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const isTTY = process.stdout.isTTY;
|
|
94
|
+
if (this.isInteractive && isTTY) {
|
|
95
|
+
yield this.interactiveRun(report);
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const fileFormat = (0, SpecificationFile_1.retrieveFileFormat)(this.specFile.text());
|
|
99
|
+
let optimizedDocument = optimizer.getOptimizedDocument({
|
|
100
|
+
rules: {
|
|
101
|
+
moveDuplicatesToComponents: this.selectedOptimizations.includes(Optimizations.MOVE_DUPLICATES_TO_COMPONENTS),
|
|
102
|
+
moveAllToComponents: this.selectedOptimizations.includes(Optimizations.MOVE_ALL_TO_COMPONENTS),
|
|
103
|
+
removeComponents: this.selectedOptimizations.includes(Optimizations.REMOVE_COMPONENTS),
|
|
104
|
+
reuseComponents: this.selectedOptimizations.includes(Optimizations.REUSE_COMPONENTS),
|
|
105
|
+
},
|
|
106
|
+
disableOptimizationFor: {
|
|
107
|
+
schema: this.disableOptimizations.includes(DisableOptimizations.SCHEMA),
|
|
108
|
+
},
|
|
109
|
+
output: fileFormat === 'json' ? optimizer_1.Output.JSON : optimizer_1.Output.YAML,
|
|
110
|
+
});
|
|
111
|
+
if (fileFormat === 'json') {
|
|
112
|
+
optimizedDocument = JSON.stringify((JSON.parse(optimizedDocument)), null, 2);
|
|
113
|
+
}
|
|
114
|
+
this.collectMetricsData(report);
|
|
115
|
+
const specPath = this.specFile.getFilePath();
|
|
116
|
+
let newPath = '';
|
|
117
|
+
if (specPath) {
|
|
118
|
+
const pos = specPath.lastIndexOf('.');
|
|
119
|
+
newPath = `${specPath.substring(0, pos)}_optimized.${specPath.substring(pos + 1)}`;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
newPath = `optimized-asyncapi.${fileFormat}`;
|
|
123
|
+
}
|
|
124
|
+
switch (this.outputMethod) {
|
|
125
|
+
case Outputs.TERMINAL:
|
|
126
|
+
this.log('📄 Here is your optimized AsyncAPI document:\n');
|
|
127
|
+
this.log(optimizedDocument);
|
|
128
|
+
break;
|
|
129
|
+
case Outputs.NEW_FILE:
|
|
130
|
+
yield writeFile(newPath, optimizedDocument, { encoding: 'utf8' });
|
|
131
|
+
this.log(`✅ Success! Your optimized file has been created at ${chalk_1.default.blue(newPath)}.`);
|
|
132
|
+
break;
|
|
133
|
+
case Outputs.OVERWRITE:
|
|
134
|
+
yield writeFile(specPath !== null && specPath !== void 0 ? specPath : `asyncapi.${fileFormat}`, optimizedDocument, {
|
|
135
|
+
encoding: 'utf8',
|
|
136
|
+
});
|
|
137
|
+
this.log(`✅ Success! Your original file at ${specPath} has been updated.`);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
throw new validation_error_1.ValidationError({
|
|
143
|
+
type: 'parser-error',
|
|
144
|
+
err: error,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
showOptimizations(elements) {
|
|
150
|
+
if (!elements) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
for (let i = 0; i < elements.length; i++) {
|
|
154
|
+
const element = elements[+i];
|
|
155
|
+
if (element.action === 'move') {
|
|
156
|
+
this.log(`${chalk_1.default.green('move')} ${element.path} to ${element.target} and reference it.`);
|
|
157
|
+
}
|
|
158
|
+
else if (element.action === 'reuse') {
|
|
159
|
+
this.log(`${chalk_1.default.green('reuse')} ${element.target} in ${element.path}.`);
|
|
160
|
+
}
|
|
161
|
+
else if (element.action === 'remove') {
|
|
162
|
+
this.log(`${chalk_1.default.red('remove')} ${element.path}.`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
this.log('\n');
|
|
166
|
+
}
|
|
167
|
+
interactiveRun(report) {
|
|
168
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
170
|
+
const canMoveDuplicates = (_a = report.moveDuplicatesToComponents) === null || _a === void 0 ? void 0 : _a.length;
|
|
171
|
+
const canMoveAll = (_b = report.moveAllToComponents) === null || _b === void 0 ? void 0 : _b.length;
|
|
172
|
+
const canRemove = (_c = report.removeComponents) === null || _c === void 0 ? void 0 : _c.length;
|
|
173
|
+
const canReuse = (_d = report.reuseComponents) === null || _d === void 0 ? void 0 : _d.length;
|
|
174
|
+
const choices = [];
|
|
175
|
+
if (canMoveAll) {
|
|
176
|
+
const totalMove = (_e = report.moveAllToComponents) === null || _e === void 0 ? void 0 : _e.filter((e) => e.action === 'move').length;
|
|
177
|
+
this.log(`${chalk_1.default.green(totalMove)} components can be moved to the components sections.\nthe following changes will be made:`);
|
|
178
|
+
this.showOptimizations(report.moveAllToComponents);
|
|
179
|
+
choices.push({
|
|
180
|
+
name: 'move all $refs to components section',
|
|
181
|
+
value: Optimizations.MOVE_ALL_TO_COMPONENTS,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (canMoveDuplicates) {
|
|
185
|
+
const totalMove = (_f = report.moveDuplicatesToComponents) === null || _f === void 0 ? void 0 : _f.filter((e) => e.action === 'move').length;
|
|
186
|
+
this.log(`\n${chalk_1.default.green(totalMove)} components can be moved to the components sections.\nthe following changes will be made:`);
|
|
187
|
+
this.showOptimizations(report.moveDuplicatesToComponents);
|
|
188
|
+
choices.push({
|
|
189
|
+
name: 'move to components section',
|
|
190
|
+
value: Optimizations.MOVE_DUPLICATES_TO_COMPONENTS,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (canRemove) {
|
|
194
|
+
const totalMove = (_g = report.removeComponents) === null || _g === void 0 ? void 0 : _g.length;
|
|
195
|
+
this.log(`${chalk_1.default.green(totalMove)} unused components can be removed.\nthe following changes will be made:`);
|
|
196
|
+
this.showOptimizations(report.removeComponents);
|
|
197
|
+
choices.push({
|
|
198
|
+
name: 'remove components',
|
|
199
|
+
value: Optimizations.REMOVE_COMPONENTS,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (canReuse) {
|
|
203
|
+
const totalMove = (_h = report.reuseComponents) === null || _h === void 0 ? void 0 : _h.length;
|
|
204
|
+
this.log(`${chalk_1.default.green(totalMove)} components can be reused.\nthe following changes will be made:`);
|
|
205
|
+
this.showOptimizations(report.reuseComponents);
|
|
206
|
+
choices.push({
|
|
207
|
+
name: 'reuse components',
|
|
208
|
+
value: Optimizations.REUSE_COMPONENTS,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
if ((_j = this.disableOptimizations) === null || _j === void 0 ? void 0 : _j.includes(DisableOptimizations.SCHEMA)) {
|
|
212
|
+
choices.push({
|
|
213
|
+
name: 'Do not ignore schema',
|
|
214
|
+
value: DisableOptimizations.SCHEMA,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
choices.push({
|
|
219
|
+
name: 'Ignore schema',
|
|
220
|
+
value: DisableOptimizations.SCHEMA,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
const optimizationRes = yield inquirer.prompt([
|
|
224
|
+
{
|
|
225
|
+
name: 'optimization',
|
|
226
|
+
message: 'select the type of optimization that you want to apply:',
|
|
227
|
+
type: 'checkbox',
|
|
228
|
+
default: 'all',
|
|
229
|
+
choices,
|
|
230
|
+
},
|
|
231
|
+
]);
|
|
232
|
+
if (optimizationRes.optimization.includes('schema')) {
|
|
233
|
+
if ((_k = this.disableOptimizations) === null || _k === void 0 ? void 0 : _k.includes(DisableOptimizations.SCHEMA)) {
|
|
234
|
+
this.disableOptimizations = (_l = this.disableOptimizations) === null || _l === void 0 ? void 0 : _l.filter((opt) => opt !== DisableOptimizations.SCHEMA);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
this.disableOptimizations = [
|
|
238
|
+
...(this.disableOptimizations || []),
|
|
239
|
+
DisableOptimizations.SCHEMA,
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
this.selectedOptimizations = optimizationRes.optimization;
|
|
244
|
+
const outputRes = yield inquirer.prompt([
|
|
245
|
+
{
|
|
246
|
+
name: 'output',
|
|
247
|
+
message: 'where do you want to save the result:',
|
|
248
|
+
type: 'list',
|
|
249
|
+
default: 'log to terminal',
|
|
250
|
+
choices: [
|
|
251
|
+
{ name: 'log to terminal', value: Outputs.TERMINAL },
|
|
252
|
+
{ name: 'create new file', value: Outputs.NEW_FILE },
|
|
253
|
+
{ name: 'update original file', value: Outputs.OVERWRITE },
|
|
254
|
+
],
|
|
255
|
+
},
|
|
256
|
+
]);
|
|
257
|
+
this.outputMethod = outputRes.output;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
collectMetricsData(report) {
|
|
261
|
+
var _a;
|
|
262
|
+
for (const availableOptimization in report) {
|
|
263
|
+
const availableOptimizationKebabCase = availableOptimization
|
|
264
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
265
|
+
.toLowerCase(); // optimization flags are kebab case
|
|
266
|
+
if (availableOptimization.length &&
|
|
267
|
+
((_a = this.selectedOptimizations) === null || _a === void 0 ? void 0 : _a.includes(availableOptimizationKebabCase))) {
|
|
268
|
+
this.metricsMetadata[`optimization_${availableOptimization}`] = true;
|
|
269
|
+
this.metricsMetadata.optimized = true;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
Optimize.description = 'optimize asyncapi specification file';
|
|
275
|
+
Optimize.examples = [
|
|
276
|
+
'asyncapi optimize ./asyncapi.yaml',
|
|
277
|
+
'asyncapi optimize ./asyncapi.yaml --no-tty',
|
|
278
|
+
'asyncapi optimize ./asyncapi.yaml --optimization=remove-components --optimization=reuse-components --optimization=move-all-to-components --no-tty',
|
|
279
|
+
'asyncapi optimize ./asyncapi.yaml --optimization=remove-components --output=terminal --no-tty',
|
|
280
|
+
'asyncapi optimize ./asyncapi.yaml --ignore=schema',
|
|
281
|
+
];
|
|
282
|
+
Optimize.flags = Object.assign(Object.assign({}, (0, optimize_flags_1.optimizeFlags)()), (0, proxy_flags_1.proxyFlags)());
|
|
283
|
+
Optimize.args = {
|
|
284
|
+
'spec-file': core_1.Args.string({
|
|
285
|
+
description: 'spec path, url, or context-name',
|
|
286
|
+
required: false,
|
|
287
|
+
}),
|
|
288
|
+
};
|
|
289
|
+
exports.default = Optimize;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Command from '../internal/base';
|
|
2
|
+
export default class Pretty extends Command {
|
|
3
|
+
static readonly description = "Beautify the AsyncAPI spec file (indentation, styling) in place or output the formatted spec to a new file.";
|
|
4
|
+
static readonly examples: string[];
|
|
5
|
+
static readonly flags: {
|
|
6
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
|
+
};
|
|
8
|
+
static readonly args: {
|
|
9
|
+
'spec-file': import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const yaml = tslib_1.__importStar(require("yaml"));
|
|
7
|
+
const base_1 = tslib_1.__importDefault(require("../internal/base"));
|
|
8
|
+
const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
|
|
9
|
+
const validation_error_1 = require("../../../errors/validation-error");
|
|
10
|
+
const pretty_flags_1 = require("../internal/flags/pretty.flags");
|
|
11
|
+
class Pretty extends base_1.default {
|
|
12
|
+
run() {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const { args, flags } = yield this.parse(Pretty);
|
|
15
|
+
const filePath = args['spec-file'];
|
|
16
|
+
const outputPath = flags.output;
|
|
17
|
+
try {
|
|
18
|
+
this.specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
this.error(new validation_error_1.ValidationError({
|
|
22
|
+
type: 'invalid-file',
|
|
23
|
+
filepath: filePath,
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
const content = this.specFile.text();
|
|
27
|
+
let formatted;
|
|
28
|
+
try {
|
|
29
|
+
const fileFormat = (0, SpecificationFile_1.retrieveFileFormat)(this.specFile.text());
|
|
30
|
+
if (fileFormat === 'yaml' || fileFormat === 'yml') {
|
|
31
|
+
const yamlDoc = yaml.parseDocument(content);
|
|
32
|
+
formatted = yamlDoc.toString({
|
|
33
|
+
lineWidth: 0,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else if (fileFormat === 'json') {
|
|
37
|
+
const jsonObj = JSON.parse(content);
|
|
38
|
+
formatted = JSON.stringify(jsonObj, null, 2);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error('Unsupported file format');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
this.error(`Error formatting file: ${err}`);
|
|
46
|
+
}
|
|
47
|
+
if (outputPath) {
|
|
48
|
+
yield fs_1.promises.writeFile(outputPath, formatted, 'utf8');
|
|
49
|
+
this.log(`Asyncapi document has been beautified ${outputPath}`);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
yield fs_1.promises.writeFile(filePath, formatted, 'utf8');
|
|
53
|
+
this.log(`Asyncapi document ${filePath} has been beautified in-place.`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
Pretty.description = 'Beautify the AsyncAPI spec file (indentation, styling) in place or output the formatted spec to a new file.';
|
|
59
|
+
Pretty.examples = [
|
|
60
|
+
'asyncapi pretty ./asyncapi.yaml',
|
|
61
|
+
'asyncapi pretty ./asyncapi.yaml --output formatted-asyncapi.yaml',
|
|
62
|
+
];
|
|
63
|
+
Pretty.flags = (0, pretty_flags_1.prettyFlags)();
|
|
64
|
+
Pretty.args = {
|
|
65
|
+
'spec-file': core_1.Args.string({
|
|
66
|
+
description: 'spec path, url, or context-name',
|
|
67
|
+
required: true,
|
|
68
|
+
}),
|
|
69
|
+
};
|
|
70
|
+
exports.default = Pretty;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Command from '../../internal/base';
|
|
2
|
+
export default class Api extends Command {
|
|
3
|
+
static readonly description = "starts the AsyncAPI server API.";
|
|
4
|
+
static readonly flags: {
|
|
5
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
6
|
+
mode: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
|
+
port: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
};
|
|
9
|
+
static readonly args: {};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
process.env['NODE_CONFIG_DIR'] = `${__dirname}/../../../api/configs`;
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
6
|
+
const api_flags_1 = require("../../internal/flags/start/api.flags");
|
|
7
|
+
const app_1 = require("../../../../apps/api/app");
|
|
8
|
+
const api_1 = require("../../../../apps/api");
|
|
9
|
+
class Api extends base_1.default {
|
|
10
|
+
run() {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
const { flags } = yield this.parse(Api);
|
|
13
|
+
const app = new app_1.App(api_1.CONTROLLERS, flags.port || 3000, // Default port if not specified
|
|
14
|
+
flags.mode);
|
|
15
|
+
yield app.init();
|
|
16
|
+
app.listen();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
Api.description = 'starts the AsyncAPI server API.';
|
|
21
|
+
Api.flags = (0, api_flags_1.apiFlags)();
|
|
22
|
+
Api.args = {};
|
|
23
|
+
exports.default = Api;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
class Start extends base_1.default {
|
|
7
|
+
run() {
|
|
8
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
const help = new core_1.Help(this.config);
|
|
10
|
+
help.showHelp(['start', '--help']);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
Start.description = 'Starts AsyncAPI-related services. Currently, it supports launching the AsyncAPI Studio';
|
|
15
|
+
exports.default = Start;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Command from '../../internal/base';
|
|
2
|
+
export default class PreviewStudio extends Command {
|
|
3
|
+
static readonly description = "starts a new local instance of Studio in minimal state bundling all the refs of the schema file and with no editing allowed.";
|
|
4
|
+
static readonly flags: {
|
|
5
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
6
|
+
port: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
|
+
base: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
baseDir: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
xOrigin: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
suppressLogs: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
noBrowser: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
};
|
|
13
|
+
static readonly args: {
|
|
14
|
+
'spec-file': import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
15
|
+
};
|
|
16
|
+
run(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
6
|
+
const preview_flags_1 = require("../../internal/flags/start/preview.flags");
|
|
7
|
+
const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
|
|
8
|
+
const Preview_1 = require("../../../../domains/models/Preview");
|
|
9
|
+
class PreviewStudio extends base_1.default {
|
|
10
|
+
run() {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const { args, flags } = yield this.parse(PreviewStudio);
|
|
14
|
+
let filePath = (_a = args['spec-file']) !== null && _a !== void 0 ? _a : flags.file;
|
|
15
|
+
const previewPort = parseInt((_b = flags.port) !== null && _b !== void 0 ? _b : '0', 10);
|
|
16
|
+
if (!filePath) {
|
|
17
|
+
filePath = (yield (0, SpecificationFile_1.load)()).getFilePath();
|
|
18
|
+
this.log(`Loaded the specification from: ${filePath}`);
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
this.specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (filePath) {
|
|
25
|
+
this.error(error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
this.metricsMetadata.port = previewPort;
|
|
29
|
+
yield (0, Preview_1.startPreview)(filePath, flags.base, flags.baseDir, flags.xOrigin, flags.suppressLogs, previewPort, flags.noBrowser);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
PreviewStudio.description = 'starts a new local instance of Studio in minimal state bundling all the refs of the schema file and with no editing allowed.';
|
|
34
|
+
PreviewStudio.flags = (0, preview_flags_1.previewFlags)();
|
|
35
|
+
PreviewStudio.args = {
|
|
36
|
+
'spec-file': core_1.Args.string({
|
|
37
|
+
description: 'the path to the file to be opened with studio or context name',
|
|
38
|
+
required: true,
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
exports.default = PreviewStudio;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Command from '../../internal/base';
|
|
2
|
+
export default class StartStudio extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
6
|
+
file: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
|
+
port: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
'no-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
noBrowser: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
};
|
|
11
|
+
static readonly args: {
|
|
12
|
+
'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
private parseArgs;
|
|
16
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
5
|
+
const Studio_1 = require("../../../../domains/models/Studio");
|
|
6
|
+
const SpecificationFile_1 = require("../../../../domains/models/SpecificationFile");
|
|
7
|
+
const studio_flags_1 = require("../../internal/flags/start/studio.flags");
|
|
8
|
+
const core_1 = require("@oclif/core");
|
|
9
|
+
const prompts_1 = require("@clack/prompts");
|
|
10
|
+
class StartStudio extends base_1.default {
|
|
11
|
+
run() {
|
|
12
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
const { args, flags } = yield this.parse(StartStudio);
|
|
15
|
+
let filePath = (_a = args['spec-file']) !== null && _a !== void 0 ? _a : flags.file;
|
|
16
|
+
let port = parseInt((_b = flags.port) !== null && _b !== void 0 ? _b : '0', 10);
|
|
17
|
+
if (flags.file) {
|
|
18
|
+
this.warn('The file flag has been removed and is being replaced by the argument spec-file. Please pass the filename directly like `asyncapi start studio asyncapi.yml`');
|
|
19
|
+
}
|
|
20
|
+
const isInteractive = !flags['no-interactive'];
|
|
21
|
+
if (isInteractive && !filePath) {
|
|
22
|
+
const parsedArgs = yield this.parseArgs({ filePath }, port === null || port === void 0 ? void 0 : port.toString());
|
|
23
|
+
filePath = parsedArgs.filePath;
|
|
24
|
+
port = parseInt(parsedArgs.port, 10);
|
|
25
|
+
}
|
|
26
|
+
if (!filePath) {
|
|
27
|
+
try {
|
|
28
|
+
filePath = (yield (0, SpecificationFile_1.load)()).getFilePath();
|
|
29
|
+
this.log(`Loaded specification from: ${filePath}`);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
filePath = '';
|
|
33
|
+
this.error('No file specified.');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
this.specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (filePath) {
|
|
41
|
+
this.error(error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.metricsMetadata.port = port;
|
|
45
|
+
(0, Studio_1.start)(filePath, port, flags.noBrowser);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
parseArgs(args, port) {
|
|
49
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const operationCancelled = 'Operation cancelled by the user.';
|
|
51
|
+
let askForPort = false;
|
|
52
|
+
let { filePath } = args;
|
|
53
|
+
if (!filePath) {
|
|
54
|
+
filePath = yield (0, prompts_1.text)({
|
|
55
|
+
message: 'Enter the path to the AsyncAPI document',
|
|
56
|
+
defaultValue: 'asyncapi.yaml',
|
|
57
|
+
placeholder: 'asyncapi.yaml',
|
|
58
|
+
validate: (value) => {
|
|
59
|
+
if (!value) {
|
|
60
|
+
return 'The path to the AsyncAPI document is required';
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
askForPort = true;
|
|
65
|
+
}
|
|
66
|
+
if ((0, prompts_1.isCancel)(filePath)) {
|
|
67
|
+
(0, prompts_1.cancel)(operationCancelled);
|
|
68
|
+
this.exit();
|
|
69
|
+
}
|
|
70
|
+
if (!port && askForPort) {
|
|
71
|
+
port = (yield (0, prompts_1.text)({
|
|
72
|
+
message: 'Enter the port in which to start Studio',
|
|
73
|
+
defaultValue: '3210',
|
|
74
|
+
placeholder: '3210',
|
|
75
|
+
validate: (value) => !value ? 'The port number is required' : undefined,
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
if ((0, prompts_1.isCancel)(port)) {
|
|
79
|
+
(0, prompts_1.cancel)(operationCancelled);
|
|
80
|
+
this.exit();
|
|
81
|
+
}
|
|
82
|
+
return { filePath, port: port !== null && port !== void 0 ? port : '3210' };
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
StartStudio.description = 'starts a new local instance of Studio';
|
|
87
|
+
StartStudio.flags = (0, studio_flags_1.studioFlags)();
|
|
88
|
+
StartStudio.args = {
|
|
89
|
+
'spec-file': core_1.Args.string({
|
|
90
|
+
description: 'spec path, url, or context-name',
|
|
91
|
+
required: false,
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
exports.default = StartStudio;
|