@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,335 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/* eslint-disable sonarjs/no-duplicate-string */
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
const diff = tslib_1.__importStar(require("@asyncapi/diff"));
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
9
|
+
const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
|
|
10
|
+
const base_1 = tslib_1.__importDefault(require("../internal/base"));
|
|
11
|
+
const validation_error_1 = require("../../../errors/validation-error");
|
|
12
|
+
const specification_file_1 = require("../../../errors/specification-file");
|
|
13
|
+
const diff_error_1 = require("../../../errors/diff-error");
|
|
14
|
+
const globals_1 = require("../internal/globals");
|
|
15
|
+
const diff_flags_1 = require("../internal/flags/diff.flags");
|
|
16
|
+
const validation_service_1 = require("../../../domains/services/validation.service");
|
|
17
|
+
const { readFile } = fs_1.promises;
|
|
18
|
+
class Diff extends base_1.default {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
this.validationService = new validation_service_1.ValidationService();
|
|
22
|
+
}
|
|
23
|
+
/* eslint-disable sonarjs/cognitive-complexity */
|
|
24
|
+
run() {
|
|
25
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const { args, flags } = yield this.parse(Diff); // NOSONAR
|
|
27
|
+
const firstDocumentPath = args['old'];
|
|
28
|
+
const secondDocumentPath = args['new'];
|
|
29
|
+
const outputFormat = flags['format'];
|
|
30
|
+
const outputType = flags['type'];
|
|
31
|
+
const overrideFilePath = flags['overrides'];
|
|
32
|
+
let markdownSubtype = flags['markdownSubtype'];
|
|
33
|
+
const watchMode = flags['watch'];
|
|
34
|
+
const noError = flags['no-error'];
|
|
35
|
+
const writeOutput = flags['save-output'];
|
|
36
|
+
let firstDocument, secondDocument;
|
|
37
|
+
checkAndWarnFalseFlag(outputFormat, markdownSubtype);
|
|
38
|
+
markdownSubtype = setDefaultMarkdownSubtype(outputFormat, markdownSubtype);
|
|
39
|
+
this.metricsMetadata.output_format = outputFormat;
|
|
40
|
+
this.metricsMetadata.output_type = outputType;
|
|
41
|
+
if (outputFormat === 'md') {
|
|
42
|
+
this.metricsMetadata.output_markdown_subtype = flags['markdownSubtype'];
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
firstDocument = yield (0, SpecificationFile_1.load)(firstDocumentPath);
|
|
46
|
+
enableWatch(watchMode, {
|
|
47
|
+
spec: firstDocument,
|
|
48
|
+
handler: this,
|
|
49
|
+
handlerName: 'diff',
|
|
50
|
+
docVersion: 'old',
|
|
51
|
+
label: 'DIFF_OLD',
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
if (err instanceof specification_file_1.SpecificationFileNotFound) {
|
|
56
|
+
this.error(new validation_error_1.ValidationError({
|
|
57
|
+
type: 'invalid-file',
|
|
58
|
+
filepath: firstDocumentPath,
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
this.error(err);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
secondDocument = yield (0, SpecificationFile_1.load)(secondDocumentPath);
|
|
65
|
+
enableWatch(watchMode, {
|
|
66
|
+
spec: secondDocument,
|
|
67
|
+
handler: this,
|
|
68
|
+
handlerName: 'diff',
|
|
69
|
+
docVersion: 'new',
|
|
70
|
+
label: 'DIFF_NEW',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
if (err instanceof specification_file_1.SpecificationFileNotFound) {
|
|
75
|
+
this.error(new validation_error_1.ValidationError({
|
|
76
|
+
type: 'invalid-file',
|
|
77
|
+
filepath: secondDocumentPath,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
this.error(err);
|
|
81
|
+
}
|
|
82
|
+
let overrides = {};
|
|
83
|
+
if (overrideFilePath) {
|
|
84
|
+
try {
|
|
85
|
+
overrides = yield readOverrideFile(overrideFilePath);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
this.error(err);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const parsed = yield this.parseDocuments(this, firstDocument, secondDocument, flags);
|
|
93
|
+
if (!parsed) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const diffOutput = diff.diff(parsed.firstDocumentParsed.json(), parsed.secondDocumentParsed.json(), {
|
|
97
|
+
override: overrides,
|
|
98
|
+
outputType: outputFormat, // NOSONAR
|
|
99
|
+
markdownSubtype: markdownSubtype,
|
|
100
|
+
});
|
|
101
|
+
if (writeOutput) {
|
|
102
|
+
yield this.writeOutputToFile(diffOutput, outputType, writeOutput, outputFormat);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
if (outputFormat === 'json') {
|
|
106
|
+
this.outputJSON(diffOutput, outputType);
|
|
107
|
+
}
|
|
108
|
+
else if (outputFormat === 'yaml' || outputFormat === 'yml') {
|
|
109
|
+
this.outputYAML(diffOutput, outputType);
|
|
110
|
+
}
|
|
111
|
+
else if (outputFormat === 'md') {
|
|
112
|
+
this.outputMarkdown(diffOutput, outputType);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
this.log(`The output format ${outputFormat} is not supported at the moment.`);
|
|
116
|
+
}
|
|
117
|
+
if (!noError) {
|
|
118
|
+
throwOnBreakingChange(diffOutput, outputFormat);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (error instanceof diff_error_1.DiffBreakingChangeError ||
|
|
124
|
+
error instanceof TypeError) {
|
|
125
|
+
this.error(error);
|
|
126
|
+
}
|
|
127
|
+
throw new validation_error_1.ValidationError({
|
|
128
|
+
type: 'parser-error',
|
|
129
|
+
err: error,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
outputJSON(diffOutput, outputType) {
|
|
135
|
+
if (outputType === 'breaking') {
|
|
136
|
+
this.log(JSON.stringify(diffOutput.breaking(), null, 2));
|
|
137
|
+
}
|
|
138
|
+
else if (outputType === 'non-breaking') {
|
|
139
|
+
this.log(JSON.stringify(diffOutput.nonBreaking(), null, 2));
|
|
140
|
+
}
|
|
141
|
+
else if (outputType === 'unclassified') {
|
|
142
|
+
this.log(JSON.stringify(diffOutput.unclassified(), null, 2));
|
|
143
|
+
}
|
|
144
|
+
else if (outputType === 'all') {
|
|
145
|
+
this.log(JSON.stringify(diffOutput.getOutput(), null, 2));
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
this.log(`The output type ${outputType} is not supported at the moment.`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
writeOutputToFile(diffOutput, outputType, filePath, outputFormat) {
|
|
152
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
let content;
|
|
154
|
+
if (outputFormat === 'json') {
|
|
155
|
+
if (outputType === 'breaking') {
|
|
156
|
+
content = JSON.stringify(diffOutput.breaking(), null, 2);
|
|
157
|
+
}
|
|
158
|
+
else if (outputType === 'non-breaking') {
|
|
159
|
+
content = JSON.stringify(diffOutput.nonBreaking(), null, 2);
|
|
160
|
+
}
|
|
161
|
+
else if (outputType === 'unclassified') {
|
|
162
|
+
content = JSON.stringify(diffOutput.unclassified(), null, 2);
|
|
163
|
+
}
|
|
164
|
+
else if (outputType === 'all') {
|
|
165
|
+
content = JSON.stringify(diffOutput.getOutput(), null, 2);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
content = `The output type ${outputType} is not supported at the moment.`;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else if (outputFormat === 'yaml' || outputFormat === 'yml') {
|
|
172
|
+
content = genericOutput(diffOutput, outputType);
|
|
173
|
+
}
|
|
174
|
+
else if (outputFormat === 'md') {
|
|
175
|
+
content = genericOutput(diffOutput, outputType);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
content = `The output format ${outputFormat} is not supported at the moment.`;
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
yield fs_1.promises.writeFile(filePath, content);
|
|
182
|
+
this.log(`Output successfully written to: ${filePath}`);
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
this.error(`Failed to write output to file: ${error.message}`);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
outputYAML(diffOutput, outputType) {
|
|
190
|
+
this.log(genericOutput(diffOutput, outputType));
|
|
191
|
+
}
|
|
192
|
+
outputMarkdown(diffOutput, outputType) {
|
|
193
|
+
this.log(genericOutput(diffOutput, outputType));
|
|
194
|
+
}
|
|
195
|
+
parseDocuments(command, firstDocument, secondDocument, flags) {
|
|
196
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
197
|
+
const firstResult = yield this.validationService.parseDocument(firstDocument, {}, flags);
|
|
198
|
+
const secondResult = yield this.validationService.parseDocument(secondDocument, {}, flags);
|
|
199
|
+
if (!firstResult.success || !secondResult.success) {
|
|
200
|
+
this.error(new validation_error_1.ValidationError({
|
|
201
|
+
type: 'invalid-file',
|
|
202
|
+
filepath: firstDocument.getFilePath() || secondDocument.getFilePath(),
|
|
203
|
+
err: firstResult.error || secondResult.error,
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
if (!firstResult.data || !secondResult.data) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const { document: firstDocumentParsed, status: firstDocumentStatus, diagnostics: firstDiagnostics, } = firstResult.data;
|
|
210
|
+
const { document: secondDocumentParsed, status: secondDocumentStatus, diagnostics: secondDiagnostics, } = secondResult.data;
|
|
211
|
+
if (flags['log-diagnostics']) {
|
|
212
|
+
this.log(`Diagnostics for ${firstDocument.getFilePath() || firstDocument.getFileURL()}:`);
|
|
213
|
+
this.handleGovernanceMessage(firstDocument, firstDiagnostics, firstDocumentStatus);
|
|
214
|
+
this.log(this.validationService.formatDiagnosticsOutput(firstDiagnostics, flags['diagnostics-format'], flags['fail-severity']));
|
|
215
|
+
this.log(`Diagnostics for ${secondDocument.getFilePath() || secondDocument.getFileURL()}:`);
|
|
216
|
+
this.handleGovernanceMessage(secondDocument, secondDiagnostics, secondDocumentStatus);
|
|
217
|
+
this.log(this.validationService.formatDiagnosticsOutput(secondDiagnostics, flags['diagnostics-format'], flags['fail-severity']));
|
|
218
|
+
}
|
|
219
|
+
if (!firstDocumentParsed ||
|
|
220
|
+
!secondDocumentParsed ||
|
|
221
|
+
firstDocumentStatus === 'invalid' ||
|
|
222
|
+
secondDocumentStatus === 'invalid') {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
return { firstDocumentParsed, secondDocumentParsed };
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
handleGovernanceMessage(document, diagnostics, status) {
|
|
229
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
const sourceString = document.toSourceString();
|
|
231
|
+
const hasIssues = diagnostics && diagnostics.length > 0;
|
|
232
|
+
const isFailSeverity = status === validation_service_1.ValidationStatus.INVALID;
|
|
233
|
+
const governanceMessage = this.validationService.generateGovernanceMessage(sourceString, hasIssues, isFailSeverity);
|
|
234
|
+
if (isFailSeverity) {
|
|
235
|
+
this.logToStderr(governanceMessage);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
this.log(governanceMessage);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
Diff.description = 'Find diff between two asyncapi files';
|
|
244
|
+
Diff.flags = (0, diff_flags_1.diffFlags)();
|
|
245
|
+
Diff.args = {
|
|
246
|
+
old: core_1.Args.string({
|
|
247
|
+
description: 'old spec path, URL or context-name',
|
|
248
|
+
required: true,
|
|
249
|
+
}),
|
|
250
|
+
new: core_1.Args.string({
|
|
251
|
+
description: 'new spec path, URL or context-name',
|
|
252
|
+
required: true,
|
|
253
|
+
}),
|
|
254
|
+
};
|
|
255
|
+
exports.default = Diff;
|
|
256
|
+
/**
|
|
257
|
+
* A generic output function for diff output
|
|
258
|
+
* @param diffOutput The diff output data
|
|
259
|
+
* @param outputType The output format requested by the user
|
|
260
|
+
* @returns The output(if the format exists) or a message indicating the format doesn't exist
|
|
261
|
+
*/
|
|
262
|
+
function genericOutput(diffOutput, outputType) {
|
|
263
|
+
switch (outputType) {
|
|
264
|
+
case 'breaking':
|
|
265
|
+
return diffOutput.breaking();
|
|
266
|
+
case 'non-breaking':
|
|
267
|
+
return diffOutput.nonBreaking();
|
|
268
|
+
case 'unclassified':
|
|
269
|
+
return diffOutput.unclassified();
|
|
270
|
+
case 'all':
|
|
271
|
+
return diffOutput.getOutput();
|
|
272
|
+
default:
|
|
273
|
+
return `The output type ${outputType} is not supported at the moment.`;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Reads the file from give path and parses it as JSON
|
|
278
|
+
* @param path The path to override file
|
|
279
|
+
* @returns The override object
|
|
280
|
+
*/
|
|
281
|
+
function readOverrideFile(path) {
|
|
282
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
let overrideStringData;
|
|
284
|
+
try {
|
|
285
|
+
overrideStringData = yield readFile(path, { encoding: 'utf8' });
|
|
286
|
+
}
|
|
287
|
+
catch (err) {
|
|
288
|
+
throw new diff_error_1.DiffOverrideFileError();
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
return JSON.parse(overrideStringData);
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
throw new diff_error_1.DiffOverrideJSONError();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* function to enable watchmode.
|
|
300
|
+
* The function is abstracted here, to avoid eslint cognitive complexity error.
|
|
301
|
+
*/
|
|
302
|
+
const enableWatch = (status, watcher) => {
|
|
303
|
+
if (status) {
|
|
304
|
+
(0, globals_1.specWatcher)(watcher);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Throws `DiffBreakingChangeError` when breaking changes are detected
|
|
309
|
+
*/
|
|
310
|
+
function throwOnBreakingChange(diffOutput, outputFormat) {
|
|
311
|
+
const breakingChanges = diffOutput.breaking();
|
|
312
|
+
if ((outputFormat === 'json' && breakingChanges.length !== 0) ||
|
|
313
|
+
((outputFormat === 'yaml' || outputFormat === 'yml') &&
|
|
314
|
+
breakingChanges !== '[]\n')) {
|
|
315
|
+
throw new diff_error_1.DiffBreakingChangeError();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Checks and warns user about providing unnecessary markdownSubtype option.
|
|
320
|
+
*/
|
|
321
|
+
function checkAndWarnFalseFlag(format, markdownSubtype) {
|
|
322
|
+
if (format !== 'md' && typeof markdownSubtype !== 'undefined') {
|
|
323
|
+
const warningMessage = chalk_1.default.yellowBright(`Warning: The given markdownSubtype flag will not work with the given format.\nProvided flag markdownSubtype: ${markdownSubtype}`);
|
|
324
|
+
console.log(warningMessage);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Sets the default markdownSubtype option in case user doesn't provide one.
|
|
329
|
+
*/
|
|
330
|
+
function setDefaultMarkdownSubtype(format, markdownSubtype) {
|
|
331
|
+
if (format === 'md' && typeof markdownSubtype === 'undefined') {
|
|
332
|
+
return 'yaml';
|
|
333
|
+
}
|
|
334
|
+
return markdownSubtype;
|
|
335
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Command from '../internal/base';
|
|
2
|
+
export default class Convert extends Command {
|
|
3
|
+
static specFile: any;
|
|
4
|
+
static metricsMetadata: any;
|
|
5
|
+
static description: string;
|
|
6
|
+
static flags: {
|
|
7
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
8
|
+
format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
|
+
};
|
|
11
|
+
static args: {
|
|
12
|
+
'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
private handleConversion;
|
|
16
|
+
private handleOutput;
|
|
17
|
+
private removeExtensionFromOutputPath;
|
|
18
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
|
+
const base_1 = tslib_1.__importDefault(require("../internal/base"));
|
|
8
|
+
const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
|
|
9
|
+
const specification_file_1 = require("../../../errors/specification-file");
|
|
10
|
+
const picocolors_1 = require("picocolors");
|
|
11
|
+
const format_flags_1 = require("../internal/flags/format.flags");
|
|
12
|
+
class Convert extends base_1.default {
|
|
13
|
+
run() {
|
|
14
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const { args, flags } = yield this.parse(Convert);
|
|
16
|
+
const filePath = args['spec-file'];
|
|
17
|
+
const outputFileFormat = flags['format'];
|
|
18
|
+
let convertedFile;
|
|
19
|
+
try {
|
|
20
|
+
this.specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
21
|
+
// eslint-disable-next-line sonarjs/no-duplicate-string
|
|
22
|
+
this.metricsMetadata.to_version = flags['target-version'];
|
|
23
|
+
const ff = (0, SpecificationFile_1.retrieveFileFormat)(this.specFile.text());
|
|
24
|
+
const isSpecFileJson = ff === 'json';
|
|
25
|
+
const isSpecFileYaml = ff === 'yaml';
|
|
26
|
+
if (!isSpecFileJson && !isSpecFileYaml) {
|
|
27
|
+
throw new specification_file_1.SpecificationWrongFileFormat(filePath);
|
|
28
|
+
}
|
|
29
|
+
convertedFile = this.handleConversion(isSpecFileJson, isSpecFileYaml, outputFileFormat);
|
|
30
|
+
if (!convertedFile) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
yield this.handleOutput(flags.output, convertedFile, outputFileFormat);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
this.error(err);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
handleConversion(isSpecFileJson, isSpecFileYaml, outputFileFormat) {
|
|
41
|
+
var _a;
|
|
42
|
+
const text = (_a = this.specFile) === null || _a === void 0 ? void 0 : _a.text();
|
|
43
|
+
if (isSpecFileJson && text) {
|
|
44
|
+
if (outputFileFormat === 'json') {
|
|
45
|
+
throw new Error(`Your document is already a ${(0, picocolors_1.cyan)('JSON')}`);
|
|
46
|
+
}
|
|
47
|
+
return (0, SpecificationFile_1.convertToYaml)(text);
|
|
48
|
+
}
|
|
49
|
+
if (isSpecFileYaml && text) {
|
|
50
|
+
if (outputFileFormat === 'yaml' || outputFileFormat === 'yml') {
|
|
51
|
+
throw new Error(`Your document is already a ${(0, picocolors_1.cyan)('YAML')}`);
|
|
52
|
+
}
|
|
53
|
+
return (0, SpecificationFile_1.convertToJSON)(text);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
handleOutput(outputPath, formattedFile, outputFileFormat) {
|
|
57
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
if (outputPath) {
|
|
59
|
+
outputPath = this.removeExtensionFromOutputPath(outputPath);
|
|
60
|
+
const finalFileName = `${outputPath}.${outputFileFormat}`;
|
|
61
|
+
yield fs_1.promises.writeFile(finalFileName, formattedFile, {
|
|
62
|
+
encoding: 'utf8',
|
|
63
|
+
});
|
|
64
|
+
this.log(`succesfully formatted to ${outputFileFormat} at ${(0, picocolors_1.green)(finalFileName)} ✅`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.log(formattedFile);
|
|
68
|
+
this.log(`succesfully logged after formatting to ${outputFileFormat} ✅`);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
removeExtensionFromOutputPath(filename) {
|
|
73
|
+
var _a;
|
|
74
|
+
// Removes the extension from a filename if it is .json, .yaml, or .yml
|
|
75
|
+
// this is so that we can remove the provided extension name in the -o flag and
|
|
76
|
+
// apply our own extension name according to the content of the file
|
|
77
|
+
const validExtensions = ['json', 'yaml', 'yml'];
|
|
78
|
+
const parts = filename.split('.');
|
|
79
|
+
if (parts.length > 1) {
|
|
80
|
+
const extension = (_a = parts.pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
81
|
+
if (extension && validExtensions.includes(extension)) {
|
|
82
|
+
return parts.join('.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return filename;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
Convert.metricsMetadata = {};
|
|
89
|
+
Convert.description = 'Convert asyncapi documents from any format to yaml, yml or JSON';
|
|
90
|
+
Convert.flags = (0, format_flags_1.convertFormatFlags)();
|
|
91
|
+
Convert.args = {
|
|
92
|
+
'spec-file': core_1.Args.string({
|
|
93
|
+
description: 'spec path, url, or context-name',
|
|
94
|
+
required: false,
|
|
95
|
+
}),
|
|
96
|
+
};
|
|
97
|
+
exports.default = Convert;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseGeneratorCommand } from '../../internal/base/BaseGeneratorCommand';
|
|
2
|
+
export default class Client extends BaseGeneratorCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static readonly flags: {
|
|
6
|
+
proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
|
+
proxyPort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
9
|
+
'disable-hook': import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
|
+
'no-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
install: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
debug: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
'no-overwrite': import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
14
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
15
|
+
'force-write': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
param: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
18
|
+
'map-base-url': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
19
|
+
'registry-url': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
20
|
+
'registry-auth': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
21
|
+
'registry-token': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
22
|
+
};
|
|
23
|
+
static args: {
|
|
24
|
+
asyncapi: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
25
|
+
language: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
26
|
+
};
|
|
27
|
+
run(): Promise<void>;
|
|
28
|
+
private parseArgs;
|
|
29
|
+
private getTemplateName;
|
|
30
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
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 BaseGeneratorCommand_1 = require("../../internal/base/BaseGeneratorCommand");
|
|
6
|
+
// eslint-disable-next-line
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const generator_1 = require("@asyncapi/generator");
|
|
9
|
+
const prompts_1 = require("@clack/prompts");
|
|
10
|
+
const picocolors_1 = require("picocolors");
|
|
11
|
+
const clients_flags_1 = require("../../internal/flags/generate/clients.flags");
|
|
12
|
+
const flags_1 = require("../../../../utils/generate/flags");
|
|
13
|
+
const prompts_2 = require("../../../../utils/generate/prompts");
|
|
14
|
+
const ClientLanguages_1 = require("../../../../domains/models/generate/ClientLanguages");
|
|
15
|
+
const generator_error_1 = require("../../../../errors/generator-error");
|
|
16
|
+
class Client extends BaseGeneratorCommand_1.BaseGeneratorCommand {
|
|
17
|
+
run() {
|
|
18
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a, _b, _c;
|
|
20
|
+
const { args, flags } = yield this.parse(Client); // NOSONAR
|
|
21
|
+
const interactive = !flags['no-interactive'];
|
|
22
|
+
let asyncapi = (_a = args['asyncapi']) !== null && _a !== void 0 ? _a : '';
|
|
23
|
+
let language = args['language'];
|
|
24
|
+
let output = flags.output;
|
|
25
|
+
const { proxyPort, proxyHost } = flags;
|
|
26
|
+
if (interactive) {
|
|
27
|
+
(0, prompts_1.intro)((0, picocolors_1.inverse)('Client generation with AsyncAPI Generator'));
|
|
28
|
+
(0, prompts_1.note)((0, picocolors_1.yellow)('This feature is in the experimental phase. Please provide feedback at: https://github.com/asyncapi/generator/issues'));
|
|
29
|
+
const parsedArgs = yield this.parseArgs(args, output);
|
|
30
|
+
asyncapi = parsedArgs.asyncapi;
|
|
31
|
+
language = parsedArgs.language;
|
|
32
|
+
output = parsedArgs.output;
|
|
33
|
+
}
|
|
34
|
+
const template = this.getTemplateName(language);
|
|
35
|
+
const parsedFlags = (0, flags_1.parseGeneratorFlags)(flags['disable-hook'], flags['param'], flags['map-base-url'], flags['registry-url'], flags['registry-auth'], flags['registry-token']);
|
|
36
|
+
const options = yield this.buildGeneratorOptions(flags, parsedFlags);
|
|
37
|
+
// Apply proxy configuration using base class method
|
|
38
|
+
asyncapi = this.applyProxyConfiguration(asyncapi, proxyHost, proxyPort);
|
|
39
|
+
const asyncapiInput = yield this.loadAsyncAPIInput(asyncapi);
|
|
40
|
+
this.specFile = asyncapiInput;
|
|
41
|
+
this.metricsMetadata.language = language;
|
|
42
|
+
const watchTemplate = flags['watch'];
|
|
43
|
+
const genOption = this.buildGenOption(flags, parsedFlags);
|
|
44
|
+
// Use GeneratorService for client generation
|
|
45
|
+
const specification = yield this.loadSpecificationSafely(asyncapi);
|
|
46
|
+
const result = yield this.generatorService.generate(specification, template, output, options, // GeneratorService expects different options interface
|
|
47
|
+
genOption, interactive);
|
|
48
|
+
if (!result.success) {
|
|
49
|
+
throw new generator_error_1.GeneratorError(new Error(result.error));
|
|
50
|
+
}
|
|
51
|
+
this.log((_c = (_b = result.data) === null || _b === void 0 ? void 0 : _b.logs) === null || _c === void 0 ? void 0 : _c.join('\n'));
|
|
52
|
+
if (watchTemplate) {
|
|
53
|
+
yield this.handleWatchMode(asyncapi, template, output, options, genOption, interactive);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
parseArgs(args, output) {
|
|
58
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
// Use base class method for common args
|
|
60
|
+
const commonArgs = yield this.parseCommonArgs(args, output);
|
|
61
|
+
let language = args['language'];
|
|
62
|
+
if (!language) {
|
|
63
|
+
const defaultLanguage = (0, ClientLanguages_1.getDefaultLanguage)();
|
|
64
|
+
language = (yield (0, prompts_2.promptForLanguage)(defaultLanguage));
|
|
65
|
+
}
|
|
66
|
+
this.handleCancellation(language);
|
|
67
|
+
return {
|
|
68
|
+
asyncapi: commonArgs.asyncapi,
|
|
69
|
+
language,
|
|
70
|
+
output: commonArgs.output
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
getTemplateName(language) {
|
|
75
|
+
var _a;
|
|
76
|
+
const template = (_a = (0, generator_1.listBakedInTemplates)({ type: 'client' }).find((template) => {
|
|
77
|
+
return template.target === language;
|
|
78
|
+
})) === null || _a === void 0 ? void 0 : _a.name;
|
|
79
|
+
if (!template) {
|
|
80
|
+
this.log(`❌ Client generation for "${language}" is not yet available.`);
|
|
81
|
+
this.log(`✅ Available languages: ${ClientLanguages_1.availableLanguages.join(', ')}`);
|
|
82
|
+
this.log('🙏 Help us create the missing one. Start discussion at: https://github.com/asyncapi/generator/issues.');
|
|
83
|
+
this.exit(1);
|
|
84
|
+
}
|
|
85
|
+
return template;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
Client.description = `Generates clients baked-in AsyncAPI Generator. Available for: ${ClientLanguages_1.availableLanguages.join(', ')}. If some language is not supported or you want to improve existing client, join us at https://github.com/asyncapi/generator`;
|
|
89
|
+
Client.examples = [
|
|
90
|
+
'asyncapi generate client javascript asyncapi.yaml --param version=1.0.0 singleFile=true --output ./docs --force-write'
|
|
91
|
+
];
|
|
92
|
+
Client.flags = Object.assign(Object.assign({}, (0, clients_flags_1.clientsFlags)()), BaseGeneratorCommand_1.BaseGeneratorCommand.flags);
|
|
93
|
+
Client.args = Object.assign({ language: core_1.Args.string({ description: `The language you want the client generated for. Available target languages: ${ClientLanguages_1.availableLanguages.join(', ')}`, required: true }) }, BaseGeneratorCommand_1.BaseGeneratorCommand.args);
|
|
94
|
+
exports.default = Client;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseGeneratorCommand } from '../../internal/base/BaseGeneratorCommand';
|
|
2
|
+
export default class Template extends BaseGeneratorCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static readonly flags: {
|
|
6
|
+
proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
|
+
proxyPort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
9
|
+
'disable-hook': import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
|
+
'no-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
install: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
debug: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
'no-overwrite': import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
14
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
15
|
+
'force-write': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
param: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
18
|
+
'map-base-url': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
19
|
+
'registry-url': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
20
|
+
'registry-auth': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
21
|
+
'registry-token': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
22
|
+
};
|
|
23
|
+
static args: {
|
|
24
|
+
template: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
25
|
+
asyncapi: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
26
|
+
};
|
|
27
|
+
run(): Promise<undefined>;
|
|
28
|
+
private parseArgs;
|
|
29
|
+
}
|