@asyncapi/cli 0.48.8 → 0.50.0
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/lib/commands/diff.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export default class Diff extends Command {
|
|
|
9
9
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
10
10
|
format: import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
11
11
|
type: import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
12
|
+
markdownSubtype: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
12
13
|
overrides: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
13
14
|
'no-error': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
14
15
|
watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
@@ -21,4 +22,5 @@ export default class Diff extends Command {
|
|
|
21
22
|
run(): Promise<void>;
|
|
22
23
|
outputJSON(diffOutput: AsyncAPIDiff, outputType: string): void;
|
|
23
24
|
outputYAML(diffOutput: AsyncAPIDiff, outputType: string): void;
|
|
25
|
+
outputMarkdown(diffOutput: AsyncAPIDiff, outputType: string): void;
|
|
24
26
|
}
|
package/lib/commands/diff.js
CHANGED
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
6
|
const diff = tslib_1.__importStar(require("@asyncapi/diff"));
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
8
9
|
const SpecificationFile_1 = require("../models/SpecificationFile");
|
|
9
10
|
const base_1 = tslib_1.__importDefault(require("../base"));
|
|
10
11
|
const validation_error_1 = require("../errors/validation-error");
|
|
@@ -24,9 +25,12 @@ class Diff extends base_1.default {
|
|
|
24
25
|
const outputFormat = flags['format'];
|
|
25
26
|
const outputType = flags['type'];
|
|
26
27
|
const overrideFilePath = flags['overrides'];
|
|
28
|
+
let markdownSubtype = flags['markdownSubtype'];
|
|
27
29
|
const watchMode = flags['watch'];
|
|
28
30
|
const noError = flags['no-error'];
|
|
29
31
|
let firstDocument, secondDocument;
|
|
32
|
+
checkAndWarnFalseFlag(outputFormat, markdownSubtype);
|
|
33
|
+
markdownSubtype = setDefaultMarkdownSubtype(outputFormat, markdownSubtype);
|
|
30
34
|
try {
|
|
31
35
|
firstDocument = yield (0, SpecificationFile_1.load)(firstDocumentPath);
|
|
32
36
|
enableWatch(watchMode, {
|
|
@@ -81,7 +85,8 @@ class Diff extends base_1.default {
|
|
|
81
85
|
}
|
|
82
86
|
const diffOutput = diff.diff(parsed.firstDocumentParsed.json(), parsed.secondDocumentParsed.json(), {
|
|
83
87
|
override: overrides,
|
|
84
|
-
outputType: outputFormat,
|
|
88
|
+
outputType: outputFormat,
|
|
89
|
+
markdownSubtype: markdownSubtype
|
|
85
90
|
});
|
|
86
91
|
if (outputFormat === 'json') {
|
|
87
92
|
this.outputJSON(diffOutput, outputType);
|
|
@@ -89,6 +94,9 @@ class Diff extends base_1.default {
|
|
|
89
94
|
else if (outputFormat === 'yaml' || outputFormat === 'yml') {
|
|
90
95
|
this.outputYAML(diffOutput, outputType);
|
|
91
96
|
}
|
|
97
|
+
else if (outputFormat === 'md') {
|
|
98
|
+
this.outputMarkdown(diffOutput, outputType);
|
|
99
|
+
}
|
|
92
100
|
else {
|
|
93
101
|
this.log(`The output format ${outputFormat} is not supported at the moment.`);
|
|
94
102
|
}
|
|
@@ -125,21 +133,10 @@ class Diff extends base_1.default {
|
|
|
125
133
|
}
|
|
126
134
|
}
|
|
127
135
|
outputYAML(diffOutput, outputType) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.log(diffOutput.nonBreaking());
|
|
133
|
-
}
|
|
134
|
-
else if (outputType === 'unclassified') {
|
|
135
|
-
this.log(diffOutput.unclassified());
|
|
136
|
-
}
|
|
137
|
-
else if (outputType === 'all') {
|
|
138
|
-
this.log(diffOutput.getOutput());
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
this.log(`The output type ${outputType} is not supported at the moment.`);
|
|
142
|
-
}
|
|
136
|
+
this.log(genericOutput(diffOutput, outputType));
|
|
137
|
+
}
|
|
138
|
+
outputMarkdown(diffOutput, outputType) {
|
|
139
|
+
this.log(genericOutput(diffOutput, outputType));
|
|
143
140
|
}
|
|
144
141
|
}
|
|
145
142
|
exports.default = Diff;
|
|
@@ -148,12 +145,16 @@ Diff.flags = Object.assign({ help: core_1.Flags.help({ char: 'h' }), format: cor
|
|
|
148
145
|
char: 'f',
|
|
149
146
|
description: 'format of the output',
|
|
150
147
|
default: 'yaml',
|
|
151
|
-
options: ['json', 'yaml', 'yml'],
|
|
148
|
+
options: ['json', 'yaml', 'yml', 'md'],
|
|
152
149
|
}), type: core_1.Flags.string({
|
|
153
150
|
char: 't',
|
|
154
151
|
description: 'type of the output',
|
|
155
152
|
default: 'all',
|
|
156
153
|
options: ['breaking', 'non-breaking', 'unclassified', 'all'],
|
|
154
|
+
}), markdownSubtype: core_1.Flags.string({
|
|
155
|
+
description: 'the format of changes made to AsyncAPI document. It works only when diff is generated using md type. For example, when you specify subtype as json, then diff information in markdown is dumped as json structure.',
|
|
156
|
+
default: undefined,
|
|
157
|
+
options: ['json', 'yaml', 'yml']
|
|
157
158
|
}), overrides: core_1.Flags.string({
|
|
158
159
|
char: 'o',
|
|
159
160
|
description: 'path to JSON file containing the override properties',
|
|
@@ -172,6 +173,21 @@ Diff.args = [
|
|
|
172
173
|
required: true,
|
|
173
174
|
},
|
|
174
175
|
];
|
|
176
|
+
/**
|
|
177
|
+
* A generic output function for diff output
|
|
178
|
+
* @param diffOutput The diff output data
|
|
179
|
+
* @param outputType The output format requested by the user
|
|
180
|
+
* @returns The output(if the format exists) or a message indicating the format doesn't exist
|
|
181
|
+
*/
|
|
182
|
+
function genericOutput(diffOutput, outputType) {
|
|
183
|
+
switch (outputType) {
|
|
184
|
+
case 'breaking': return diffOutput.breaking();
|
|
185
|
+
case 'non-breaking': return diffOutput.nonBreaking();
|
|
186
|
+
case 'unclassified': return diffOutput.unclassified();
|
|
187
|
+
case 'all': return diffOutput.getOutput();
|
|
188
|
+
default: return `The output type ${outputType} is not supported at the moment.`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
175
191
|
function parseDocuments(command, firstDocument, secondDocument, flags) {
|
|
176
192
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
177
193
|
const { document: newFirstDocumentParsed, status: firstDocumentStatus } = yield (0, parser_1.parse)(command, firstDocument, flags);
|
|
@@ -221,7 +237,26 @@ const enableWatch = (status, watcher) => {
|
|
|
221
237
|
function throwOnBreakingChange(diffOutput, outputFormat) {
|
|
222
238
|
const breakingChanges = diffOutput.breaking();
|
|
223
239
|
if ((outputFormat === 'json' && breakingChanges.length !== 0) ||
|
|
224
|
-
((outputFormat === 'yaml' || outputFormat === 'yml') && breakingChanges !== '[]\n')
|
|
240
|
+
((outputFormat === 'yaml' || outputFormat === 'yml') && breakingChanges !== '[]\n') ||
|
|
241
|
+
(outputFormat === 'md' && breakingChanges.length !== 0)) {
|
|
225
242
|
throw new diff_error_1.DiffBreakingChangeError();
|
|
226
243
|
}
|
|
227
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Checks and warns user about providing unnecessary markdownSubtype option.
|
|
247
|
+
*/
|
|
248
|
+
function checkAndWarnFalseFlag(format, markdownSubtype) {
|
|
249
|
+
if (format !== 'md' && typeof (markdownSubtype) !== 'undefined') {
|
|
250
|
+
const warningMessage = chalk_1.default.yellowBright(`Warning: The given markdownSubtype flag will not work with the given format.\nProvided flag markdownSubtype: ${markdownSubtype}`);
|
|
251
|
+
console.log(warningMessage);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Sets the default markdownSubtype option in case user doesn't provide one.
|
|
256
|
+
*/
|
|
257
|
+
function setDefaultMarkdownSubtype(format, markdownSubtype) {
|
|
258
|
+
if (format === 'md' && typeof (markdownSubtype) === 'undefined') {
|
|
259
|
+
return 'yaml';
|
|
260
|
+
}
|
|
261
|
+
return markdownSubtype;
|
|
262
|
+
}
|
|
@@ -27,6 +27,7 @@ export default class Models extends Command {
|
|
|
27
27
|
tsIncludeComments: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
28
28
|
tsExportType: import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
29
29
|
tsJsonBinPack: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
30
|
+
tsMarshalling: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
30
31
|
/**
|
|
31
32
|
* Go and Java specific package name to use for the generated models
|
|
32
33
|
*/
|
|
@@ -26,7 +26,7 @@ class Models extends base_1.default {
|
|
|
26
26
|
run() {
|
|
27
27
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
const { args, flags } = yield this.parse(Models);
|
|
29
|
-
const { tsModelType, tsEnumType, tsIncludeComments, tsModuleSystem, tsExportType, tsJsonBinPack, namespace, csharpAutoImplement, csharpArrayType, csharpNewtonsoft, csharpHashcode, csharpEqual, csharpSystemJson, packageName, output } = flags;
|
|
29
|
+
const { tsModelType, tsEnumType, tsIncludeComments, tsModuleSystem, tsExportType, tsJsonBinPack, tsMarshalling, namespace, csharpAutoImplement, csharpArrayType, csharpNewtonsoft, csharpHashcode, csharpEqual, csharpSystemJson, packageName, output } = flags;
|
|
30
30
|
const { language, file } = args;
|
|
31
31
|
const inputFile = (yield (0, SpecificationFile_1.load)(file)) || (yield (0, SpecificationFile_1.load)());
|
|
32
32
|
const { document, diagnostics, status } = yield (0, parser_1.parse)(this, inputFile, flags);
|
|
@@ -65,6 +65,14 @@ class Models extends base_1.default {
|
|
|
65
65
|
}
|
|
66
66
|
}, modelina_1.TS_JSONBINPACK_PRESET);
|
|
67
67
|
}
|
|
68
|
+
if (tsMarshalling) {
|
|
69
|
+
presets.push({
|
|
70
|
+
preset: modelina_1.TS_COMMON_PRESET,
|
|
71
|
+
options: {
|
|
72
|
+
marshalling: true
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
68
76
|
fileGenerator = new modelina_1.TypeScriptFileGenerator({
|
|
69
77
|
modelType: tsModelType,
|
|
70
78
|
enumType: tsEnumType,
|
|
@@ -243,6 +251,10 @@ Models.flags = Object.assign({ help: core_1.Flags.help({ char: 'h' }), output: c
|
|
|
243
251
|
description: 'TypeScript specific, define basic support for serializing to and from binary with jsonbinpack.',
|
|
244
252
|
required: false,
|
|
245
253
|
default: false,
|
|
254
|
+
}), tsMarshalling: core_1.Flags.boolean({
|
|
255
|
+
description: 'TypeScript specific, generate the models with marshalling functions.',
|
|
256
|
+
required: false,
|
|
257
|
+
default: false,
|
|
246
258
|
}),
|
|
247
259
|
/**
|
|
248
260
|
* Go and Java specific package name to use for the generated models
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.50.0",
|
|
3
3
|
"commands": {
|
|
4
4
|
"bundle": {
|
|
5
5
|
"id": "bundle",
|
|
@@ -112,7 +112,8 @@
|
|
|
112
112
|
"options": [
|
|
113
113
|
"json",
|
|
114
114
|
"yaml",
|
|
115
|
-
"yml"
|
|
115
|
+
"yml",
|
|
116
|
+
"md"
|
|
116
117
|
],
|
|
117
118
|
"default": "yaml"
|
|
118
119
|
},
|
|
@@ -130,6 +131,17 @@
|
|
|
130
131
|
],
|
|
131
132
|
"default": "all"
|
|
132
133
|
},
|
|
134
|
+
"markdownSubtype": {
|
|
135
|
+
"name": "markdownSubtype",
|
|
136
|
+
"type": "option",
|
|
137
|
+
"description": "the format of changes made to AsyncAPI document. It works only when diff is generated using md type. For example, when you specify subtype as json, then diff information in markdown is dumped as json structure.",
|
|
138
|
+
"multiple": false,
|
|
139
|
+
"options": [
|
|
140
|
+
"json",
|
|
141
|
+
"yaml",
|
|
142
|
+
"yml"
|
|
143
|
+
]
|
|
144
|
+
},
|
|
133
145
|
"overrides": {
|
|
134
146
|
"name": "overrides",
|
|
135
147
|
"type": "option",
|
|
@@ -557,6 +569,13 @@
|
|
|
557
569
|
"required": false,
|
|
558
570
|
"allowNo": false
|
|
559
571
|
},
|
|
572
|
+
"tsMarshalling": {
|
|
573
|
+
"name": "tsMarshalling",
|
|
574
|
+
"type": "boolean",
|
|
575
|
+
"description": "TypeScript specific, generate the models with marshalling functions.",
|
|
576
|
+
"required": false,
|
|
577
|
+
"allowNo": false
|
|
578
|
+
},
|
|
560
579
|
"packageName": {
|
|
561
580
|
"name": "packageName",
|
|
562
581
|
"type": "option",
|