@asyncapi/cli 3.5.2 → 3.6.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/bin/dev CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env nod
1
+ #!/usr/bin/env node
2
2
 
3
3
  const oclif = require('@oclif/core')
4
4
 
@@ -10,7 +10,7 @@ export default class Diff extends Command {
10
10
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
11
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
12
12
  'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
13
- output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
13
+ 'save-output': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
14
14
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
15
15
  format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
16
16
  type: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -25,6 +25,7 @@ export default class Diff extends Command {
25
25
  };
26
26
  run(): Promise<void>;
27
27
  outputJSON(diffOutput: AsyncAPIDiff, outputType: string): void;
28
+ writeOutputToFile(diffOutput: AsyncAPIDiff, outputType: string, filePath: string, outputFormat: string): Promise<void>;
28
29
  outputYAML(diffOutput: AsyncAPIDiff, outputType: string): void;
29
30
  outputMarkdown(diffOutput: AsyncAPIDiff, outputType: string): void;
30
31
  parseDocuments(command: Command, firstDocument: Specification, secondDocument: Specification, flags: Record<string, any>): Promise<{
@@ -32,6 +32,7 @@ class Diff extends base_1.default {
32
32
  let markdownSubtype = flags['markdownSubtype'];
33
33
  const watchMode = flags['watch'];
34
34
  const noError = flags['no-error'];
35
+ const writeOutput = flags['save-output'];
35
36
  let firstDocument, secondDocument;
36
37
  checkAndWarnFalseFlag(outputFormat, markdownSubtype);
37
38
  markdownSubtype = setDefaultMarkdownSubtype(outputFormat, markdownSubtype);
@@ -97,20 +98,25 @@ class Diff extends base_1.default {
97
98
  outputType: outputFormat, // NOSONAR
98
99
  markdownSubtype: markdownSubtype,
99
100
  });
100
- if (outputFormat === 'json') {
101
- this.outputJSON(diffOutput, outputType);
102
- }
103
- else if (outputFormat === 'yaml' || outputFormat === 'yml') {
104
- this.outputYAML(diffOutput, outputType);
105
- }
106
- else if (outputFormat === 'md') {
107
- this.outputMarkdown(diffOutput, outputType);
101
+ if (writeOutput) {
102
+ yield this.writeOutputToFile(diffOutput, outputType, writeOutput, outputFormat);
108
103
  }
109
104
  else {
110
- this.log(`The output format ${outputFormat} is not supported at the moment.`);
111
- }
112
- if (!noError) {
113
- throwOnBreakingChange(diffOutput, outputFormat);
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
+ }
114
120
  }
115
121
  }
116
122
  catch (error) {
@@ -142,6 +148,44 @@ class Diff extends base_1.default {
142
148
  this.log(`The output type ${outputType} is not supported at the moment.`);
143
149
  }
144
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
+ }
145
189
  outputYAML(diffOutput, outputType) {
146
190
  this.log(genericOutput(diffOutput, outputType));
147
191
  }
@@ -11,7 +11,7 @@ export default class Validate extends Command {
11
11
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
12
12
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
13
13
  'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
14
- output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
14
+ 'save-output': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
15
15
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
16
16
  watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
17
  };
@@ -55,6 +55,7 @@ class Validate extends base_1.default {
55
55
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
56
56
  var _a, _b, _c, _d, _e, _f, _g;
57
57
  const diagnosticsFormat = (_a = flags['diagnostics-format']) !== null && _a !== void 0 ? _a : 'stylish';
58
+ const writeOutput = flags['save-output'];
58
59
  const hasIssues = (_c = (((_b = result.data) === null || _b === void 0 ? void 0 : _b.diagnostics) && result.data.diagnostics.length > 0)) !== null && _c !== void 0 ? _c : false;
59
60
  const isFailSeverity = ((_d = result.data) === null || _d === void 0 ? void 0 : _d.status) === validation_service_1.ValidationStatus.INVALID;
60
61
  const sourceString = ((_e = this.specFile) === null || _e === void 0 ? void 0 : _e.toSourceString()) || '';
@@ -66,15 +67,15 @@ class Validate extends base_1.default {
66
67
  this.log(governanceMessage);
67
68
  }
68
69
  const diagnosticsOutput = this.validationService.formatDiagnosticsOutput(((_f = result.data) === null || _f === void 0 ? void 0 : _f.diagnostics) || [], diagnosticsFormat, (_g = flags['fail-severity']) !== null && _g !== void 0 ? _g : 'error');
69
- if (flags.output) {
70
- const { success, error } = yield this.validationService.saveDiagnosticsToFile(flags.output, diagnosticsFormat, diagnosticsOutput);
70
+ if (writeOutput) {
71
+ const { success, error } = yield this.validationService.saveDiagnosticsToFile(writeOutput, diagnosticsFormat, diagnosticsOutput);
71
72
  if (!success) {
72
73
  this.logToStderr(error || 'Failed to save diagnostics to file', {
73
74
  exit: 1,
74
75
  });
75
76
  }
76
77
  else {
77
- this.log(`Diagnostics saved to ${flags.output}`);
78
+ this.log(`Diagnostics saved to ${writeOutput}`);
78
79
  }
79
80
  }
80
81
  else {
@@ -2,7 +2,7 @@ export declare const diffFlags: () => {
2
2
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
3
3
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
4
4
  'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
5
- output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
5
+ 'save-output': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
6
6
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
7
7
  format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
8
8
  type: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
@@ -6,5 +6,5 @@ export declare function parserFlags({ logDiagnostics, }?: ValidationFlagsOptions
6
6
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
7
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
8
8
  'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
9
- output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
+ 'save-output': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
10
  };
@@ -20,9 +20,9 @@ function parserFlags({ logDiagnostics = true, } = {}) {
20
20
  options: ['error', 'warn', 'info', 'hint'],
21
21
  default: 'error',
22
22
  })(),
23
- output: core_1.Flags.string({
23
+ 'save-output': core_1.Flags.string({
24
24
  description: 'The output file name. Omitting this flag the result will be printed in the console.',
25
- char: 'o',
25
+ char: 's',
26
26
  }),
27
27
  };
28
28
  }
@@ -5,7 +5,7 @@ export declare const validateFlags: () => {
5
5
  'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
6
6
  'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
7
7
  'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
8
- output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ 'save-output': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
9
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
10
10
  watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
11
  };
@@ -288,10 +288,10 @@
288
288
  ],
289
289
  "type": "option"
290
290
  },
291
- "output": {
292
- "char": "o",
291
+ "save-output": {
292
+ "char": "s",
293
293
  "description": "The output file name. Omitting this flag the result will be printed in the console.",
294
- "name": "output",
294
+ "name": "save-output",
295
295
  "hasDynamicHelp": false,
296
296
  "multiple": false,
297
297
  "type": "option"
@@ -584,10 +584,10 @@
584
584
  ],
585
585
  "type": "option"
586
586
  },
587
- "output": {
588
- "char": "o",
587
+ "save-output": {
588
+ "char": "s",
589
589
  "description": "The output file name. Omitting this flag the result will be printed in the console.",
590
- "name": "output",
590
+ "name": "save-output",
591
591
  "hasDynamicHelp": false,
592
592
  "multiple": false,
593
593
  "type": "option"
@@ -1121,8 +1121,9 @@
1121
1121
  },
1122
1122
  "output": {
1123
1123
  "char": "o",
1124
- "description": "The output file name. Omitting this flag the result will be printed in the console.",
1124
+ "description": "The output directory where the models should be written to. Omitting this flag will write the models to `stdout`.",
1125
1125
  "name": "output",
1126
+ "required": false,
1126
1127
  "hasDynamicHelp": false,
1127
1128
  "multiple": false,
1128
1129
  "type": "option"
@@ -1377,6 +1378,14 @@
1377
1378
  ],
1378
1379
  "type": "option"
1379
1380
  },
1381
+ "save-output": {
1382
+ "char": "s",
1383
+ "description": "The output file name. Omitting this flag the result will be printed in the console.",
1384
+ "name": "save-output",
1385
+ "hasDynamicHelp": false,
1386
+ "multiple": false,
1387
+ "type": "option"
1388
+ },
1380
1389
  "proxyHost": {
1381
1390
  "description": "Name of the ProxyHost",
1382
1391
  "name": "proxyHost",
@@ -2142,5 +2151,5 @@
2142
2151
  ]
2143
2152
  }
2144
2153
  },
2145
- "version": "3.5.2"
2154
+ "version": "3.6.0"
2146
2155
  }
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": "3.5.2",
4
+ "version": "3.6.0",
5
5
  "author": "@asyncapi",
6
6
  "bin": {
7
7
  "asyncapi": "./bin/run_bin"