@asyncapi/cli 0.48.7 → 0.49.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.
@@ -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
  }
@@ -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, // NOSONAR
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
- if (outputType === 'breaking') {
129
- this.log(diffOutput.breaking());
130
- }
131
- else if (outputType === 'non-breaking') {
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
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.48.7",
2
+ "version": "0.49.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",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@asyncapi/cli",
3
3
  "description": "All in one CLI for all AsyncAPI tools",
4
- "version": "0.48.7",
4
+ "version": "0.49.0",
5
5
  "author": "@asyncapi",
6
6
  "bin": {
7
7
  "asyncapi": "./bin/run"
@@ -10,7 +10,7 @@
10
10
  "dependencies": {
11
11
  "@asyncapi/avro-schema-parser": "^3.0.2",
12
12
  "@asyncapi/bundler": "^0.3.8",
13
- "@asyncapi/converter": "^1.2.0",
13
+ "@asyncapi/converter": "^1.2.1",
14
14
  "@asyncapi/diff": "^0.4.1",
15
15
  "@asyncapi/generator": "^1.10.8",
16
16
  "@asyncapi/modelina": "^1.8.6",