@asyncapi/cli 0.25.0 → 0.25.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/lib/base.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default abstract class extends Command {
3
- catch(e: any): Promise<void>;
3
+ catch(err: Error & {
4
+ exitCode?: number;
5
+ }): Promise<any>;
4
6
  }
package/lib/base.js CHANGED
@@ -1,10 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
3
4
  const core_1 = require("@oclif/core");
4
5
  class default_1 extends core_1.Command {
5
- async catch(e) {
6
- console.error(`${e.name}: ${e.message}`);
7
- process.exitCode = 1;
6
+ catch(err) {
7
+ const _super = Object.create(null, {
8
+ catch: { get: () => super.catch }
9
+ });
10
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
11
+ try {
12
+ return yield _super.catch.call(this, err);
13
+ }
14
+ catch (e) {
15
+ if (e instanceof Error) {
16
+ this.logToStderr(`${e.name}: ${e.message}`);
17
+ process.exitCode = 1;
18
+ }
19
+ }
20
+ });
8
21
  }
9
22
  }
10
23
  exports.default = default_1;
@@ -5,12 +5,14 @@ const core_1 = require("@oclif/core");
5
5
  const base_1 = tslib_1.__importDefault(require("../../../base"));
6
6
  const Context_1 = require("../../../models/Context");
7
7
  class ContextAdd extends base_1.default {
8
- async run() {
9
- const { args } = await this.parse(ContextAdd);
10
- const contextName = args['context-name'];
11
- const specFilePath = args['spec-file-path'];
12
- await (0, Context_1.addContext)(contextName, specFilePath);
13
- this.log(`Added context "${contextName}".\n\nYou can set it as your current context: asyncapi config context use ${contextName}\nYou can use this context when needed by passing ${contextName} as a parameter: asyncapi validate ${contextName}`);
8
+ run() {
9
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
+ const { args } = yield this.parse(ContextAdd);
11
+ const contextName = args['context-name'];
12
+ const specFilePath = args['spec-file-path'];
13
+ yield (0, Context_1.addContext)(contextName, specFilePath);
14
+ this.log(`Added context "${contextName}".\n\nYou can set it as your current context: asyncapi config context use ${contextName}\nYou can use this context when needed by passing ${contextName} as a parameter: asyncapi validate ${contextName}`);
15
+ });
14
16
  }
15
17
  }
16
18
  exports.default = ContextAdd;
@@ -5,9 +5,11 @@ const core_1 = require("@oclif/core");
5
5
  const base_1 = tslib_1.__importDefault(require("../../../base"));
6
6
  const Context_1 = require("../../../models/Context");
7
7
  class ContextCurrent extends base_1.default {
8
- async run() {
9
- const { current, context } = await (0, Context_1.getCurrentContext)();
10
- this.log(`${current}: ${context}`);
8
+ run() {
9
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
+ const { current, context } = yield (0, Context_1.getCurrentContext)();
11
+ this.log(`${current}: ${context}`);
12
+ });
11
13
  }
12
14
  }
13
15
  exports.default = ContextCurrent;
@@ -4,10 +4,12 @@ const tslib_1 = require("tslib");
4
4
  const core_1 = require("@oclif/core");
5
5
  const base_1 = tslib_1.__importDefault(require("../../../base"));
6
6
  class Context extends base_1.default {
7
- async run() {
8
- const Help = await (0, core_1.loadHelpClass)(this.config);
9
- const help = new Help(this.config);
10
- help.showHelp(['config', 'context', '--help']);
7
+ run() {
8
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
+ const Help = yield (0, core_1.loadHelpClass)(this.config);
10
+ const help = new Help(this.config);
11
+ help.showHelp(['config', 'context', '--help']);
12
+ });
11
13
  }
12
14
  }
13
15
  exports.default = Context;
@@ -5,11 +5,13 @@ const core_1 = require("@oclif/core");
5
5
  const base_1 = tslib_1.__importDefault(require("../../../base"));
6
6
  const Context_1 = require("../../../models/Context");
7
7
  class ContextList extends base_1.default {
8
- async run() {
9
- const fileContent = await (0, Context_1.loadContextFile)();
10
- for (const [contextName, filePath] of Object.entries(fileContent.store)) {
11
- this.log(`${contextName}: ${filePath}`);
12
- }
8
+ run() {
9
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
+ const fileContent = yield (0, Context_1.loadContextFile)();
11
+ for (const [contextName, filePath] of Object.entries(fileContent.store)) {
12
+ this.log(`${contextName}: ${filePath}`);
13
+ }
14
+ });
13
15
  }
14
16
  }
15
17
  exports.default = ContextList;
@@ -5,16 +5,18 @@ const core_1 = require("@oclif/core");
5
5
  const base_1 = tslib_1.__importDefault(require("../../../base"));
6
6
  const Context_1 = require("../../../models/Context");
7
7
  class ContextRemove extends base_1.default {
8
- async run() {
9
- const { args } = await this.parse(ContextRemove);
10
- const contextName = args['context-name'];
11
- try {
12
- await (0, Context_1.removeContext)(contextName);
13
- this.log(`${contextName} successfully deleted`);
14
- }
15
- catch (err) {
16
- this.error(err);
17
- }
8
+ run() {
9
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
+ const { args } = yield this.parse(ContextRemove);
11
+ const contextName = args['context-name'];
12
+ try {
13
+ yield (0, Context_1.removeContext)(contextName);
14
+ this.log(`${contextName} successfully deleted`);
15
+ }
16
+ catch (err) {
17
+ this.error(err);
18
+ }
19
+ });
18
20
  }
19
21
  }
20
22
  exports.default = ContextRemove;
@@ -5,11 +5,13 @@ const core_1 = require("@oclif/core");
5
5
  const base_1 = tslib_1.__importDefault(require("../../../base"));
6
6
  const Context_1 = require("../../../models/Context");
7
7
  class ContextUse extends base_1.default {
8
- async run() {
9
- const { args } = await this.parse(ContextUse);
10
- const contextName = args['context-name'];
11
- await (0, Context_1.setCurrentContext)(contextName);
12
- this.log(`${contextName} is set as current`);
8
+ run() {
9
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
+ const { args } = yield this.parse(ContextUse);
11
+ const contextName = args['context-name'];
12
+ yield (0, Context_1.setCurrentContext)(contextName);
13
+ this.log(`${contextName} is set as current`);
14
+ });
13
15
  }
14
16
  }
15
17
  exports.default = ContextUse;
@@ -4,10 +4,12 @@ const tslib_1 = require("tslib");
4
4
  const base_1 = tslib_1.__importDefault(require("../../base"));
5
5
  const core_1 = require("@oclif/core");
6
6
  class Config extends base_1.default {
7
- async run() {
8
- const Help = await (0, core_1.loadHelpClass)(this.config);
9
- const help = new Help(this.config);
10
- help.showHelp(['config', '--help']);
7
+ run() {
8
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
+ const Help = yield (0, core_1.loadHelpClass)(this.config);
10
+ const help = new Help(this.config);
11
+ help.showHelp(['config', '--help']);
12
+ });
11
13
  }
12
14
  }
13
15
  exports.default = Config;
@@ -13,42 +13,44 @@ const converter_1 = require("@asyncapi/converter");
13
13
  const specs_1 = tslib_1.__importDefault(require("@asyncapi/specs"));
14
14
  const latestVersion = Object.keys(specs_1.default).pop();
15
15
  class Convert extends base_1.default {
16
- async run() {
17
- const { args, flags } = await this.parse(Convert);
18
- const filePath = args['spec-file'];
19
- let specFile;
20
- let convertedFile;
21
- try {
22
- // LOAD FILE
23
- specFile = await (0, SpecificationFile_1.load)(filePath);
24
- // CONVERSION
25
- convertedFile = (0, converter_1.convert)(specFile.text(), flags['target-version']);
26
- if (convertedFile) {
27
- if (specFile.getFilePath()) {
28
- this.log(`File ${specFile.getFilePath()} successfully converted!`);
16
+ run() {
17
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
18
+ const { args, flags } = yield this.parse(Convert);
19
+ const filePath = args['spec-file'];
20
+ let specFile;
21
+ let convertedFile;
22
+ try {
23
+ // LOAD FILE
24
+ specFile = yield (0, SpecificationFile_1.load)(filePath);
25
+ // CONVERSION
26
+ convertedFile = (0, converter_1.convert)(specFile.text(), flags['target-version']);
27
+ if (convertedFile) {
28
+ if (specFile.getFilePath()) {
29
+ this.log(`File ${specFile.getFilePath()} successfully converted!`);
30
+ }
31
+ else if (specFile.getFileURL()) {
32
+ this.log(`URL ${specFile.getFileURL()} successfully converted!`);
33
+ }
29
34
  }
30
- else if (specFile.getFileURL()) {
31
- this.log(`URL ${specFile.getFileURL()} successfully converted!`);
35
+ if (flags.output) {
36
+ yield fs_1.promises.writeFile(`${flags.output}`, convertedFile, { encoding: 'utf8' });
37
+ }
38
+ else {
39
+ this.log(convertedFile);
32
40
  }
33
41
  }
34
- if (flags.output) {
35
- await fs_1.promises.writeFile(`${flags.output}`, convertedFile, { encoding: 'utf8' });
36
- }
37
- else {
38
- this.log(convertedFile);
39
- }
40
- }
41
- catch (err) {
42
- if (err instanceof specification_file_1.SpecificationFileNotFound) {
43
- this.error(new validation_error_1.ValidationError({
44
- type: 'invalid-file',
45
- filepath: filePath
46
- }));
47
- }
48
- else {
49
- this.error(err);
42
+ catch (err) {
43
+ if (err instanceof specification_file_1.SpecificationFileNotFound) {
44
+ this.error(new validation_error_1.ValidationError({
45
+ type: 'invalid-file',
46
+ filepath: filePath
47
+ }));
48
+ }
49
+ else {
50
+ this.error(err);
51
+ }
50
52
  }
51
- }
53
+ });
52
54
  }
53
55
  }
54
56
  exports.default = Convert;
@@ -15,85 +15,87 @@ const globals_1 = require("../globals");
15
15
  const flags_1 = require("../flags");
16
16
  const { readFile } = fs_1.promises;
17
17
  class Diff extends base_1.default {
18
- async run() {
19
- const { args, flags } = await this.parse(Diff); // NOSONAR
20
- const firstDocumentPath = args['old'];
21
- const secondDocumentPath = args['new'];
22
- const outputFormat = flags['format'];
23
- const outputType = flags['type'];
24
- const overrideFilePath = flags['overrides'];
25
- const watchMode = flags['watch'];
26
- let firstDocument, secondDocument;
27
- try {
28
- firstDocument = await (0, SpecificationFile_1.load)(firstDocumentPath);
29
- enableWatch(watchMode, {
30
- spec: firstDocument,
31
- handler: this,
32
- handlerName: 'diff',
33
- docVersion: 'old',
34
- label: 'DIFF_OLD',
35
- });
36
- }
37
- catch (err) {
38
- if (err instanceof specification_file_1.SpecificationFileNotFound) {
39
- this.error(new validation_error_1.ValidationError({
40
- type: 'invalid-file',
41
- filepath: firstDocumentPath,
42
- }));
18
+ run() {
19
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
20
+ const { args, flags } = yield this.parse(Diff); // NOSONAR
21
+ const firstDocumentPath = args['old'];
22
+ const secondDocumentPath = args['new'];
23
+ const outputFormat = flags['format'];
24
+ const outputType = flags['type'];
25
+ const overrideFilePath = flags['overrides'];
26
+ const watchMode = flags['watch'];
27
+ let firstDocument, secondDocument;
28
+ try {
29
+ firstDocument = yield (0, SpecificationFile_1.load)(firstDocumentPath);
30
+ enableWatch(watchMode, {
31
+ spec: firstDocument,
32
+ handler: this,
33
+ handlerName: 'diff',
34
+ docVersion: 'old',
35
+ label: 'DIFF_OLD',
36
+ });
43
37
  }
44
- this.error(err);
45
- }
46
- try {
47
- secondDocument = await (0, SpecificationFile_1.load)(secondDocumentPath);
48
- enableWatch(watchMode, {
49
- spec: secondDocument,
50
- handler: this,
51
- handlerName: 'diff',
52
- docVersion: 'new',
53
- label: 'DIFF_NEW',
54
- });
55
- }
56
- catch (err) {
57
- if (err instanceof specification_file_1.SpecificationFileNotFound) {
58
- this.error(new validation_error_1.ValidationError({
59
- type: 'invalid-file',
60
- filepath: secondDocumentPath,
61
- }));
38
+ catch (err) {
39
+ if (err instanceof specification_file_1.SpecificationFileNotFound) {
40
+ this.error(new validation_error_1.ValidationError({
41
+ type: 'invalid-file',
42
+ filepath: firstDocumentPath,
43
+ }));
44
+ }
45
+ this.error(err);
62
46
  }
63
- this.error(err);
64
- }
65
- let overrides = {};
66
- if (overrideFilePath) {
67
47
  try {
68
- overrides = await readOverrideFile(overrideFilePath);
48
+ secondDocument = yield (0, SpecificationFile_1.load)(secondDocumentPath);
49
+ enableWatch(watchMode, {
50
+ spec: secondDocument,
51
+ handler: this,
52
+ handlerName: 'diff',
53
+ docVersion: 'new',
54
+ label: 'DIFF_NEW',
55
+ });
69
56
  }
70
57
  catch (err) {
58
+ if (err instanceof specification_file_1.SpecificationFileNotFound) {
59
+ this.error(new validation_error_1.ValidationError({
60
+ type: 'invalid-file',
61
+ filepath: secondDocumentPath,
62
+ }));
63
+ }
71
64
  this.error(err);
72
65
  }
73
- }
74
- try {
75
- const firstDocumentParsed = await parser.parse(firstDocument.text());
76
- const secondDocumentParsed = await parser.parse(secondDocument.text());
77
- const diffOutput = diff.diff(firstDocumentParsed.json(), secondDocumentParsed.json(), {
78
- override: overrides,
79
- outputType: outputFormat, // NOSONAR
80
- });
81
- if (outputFormat === 'json') {
82
- this.outputJSON(diffOutput, outputType);
66
+ let overrides = {};
67
+ if (overrideFilePath) {
68
+ try {
69
+ overrides = yield readOverrideFile(overrideFilePath);
70
+ }
71
+ catch (err) {
72
+ this.error(err);
73
+ }
83
74
  }
84
- else if (outputFormat === 'yaml' || outputFormat === 'yml') {
85
- this.outputYAML(diffOutput, outputType);
75
+ try {
76
+ const firstDocumentParsed = yield parser.parse(firstDocument.text());
77
+ const secondDocumentParsed = yield parser.parse(secondDocument.text());
78
+ const diffOutput = diff.diff(firstDocumentParsed.json(), secondDocumentParsed.json(), {
79
+ override: overrides,
80
+ outputType: outputFormat, // NOSONAR
81
+ });
82
+ if (outputFormat === 'json') {
83
+ this.outputJSON(diffOutput, outputType);
84
+ }
85
+ else if (outputFormat === 'yaml' || outputFormat === 'yml') {
86
+ this.outputYAML(diffOutput, outputType);
87
+ }
88
+ else {
89
+ this.log(`The output format ${outputFormat} is not supported at the moment.`);
90
+ }
86
91
  }
87
- else {
88
- this.log(`The output format ${outputFormat} is not supported at the moment.`);
92
+ catch (error) {
93
+ throw new validation_error_1.ValidationError({
94
+ type: 'parser-error',
95
+ err: error,
96
+ });
89
97
  }
90
- }
91
- catch (error) {
92
- throw new validation_error_1.ValidationError({
93
- type: 'parser-error',
94
- err: error,
95
- });
96
- }
98
+ });
97
99
  }
98
100
  outputJSON(diffOutput, outputType) {
99
101
  if (outputType === 'breaking') {
@@ -169,20 +171,22 @@ Diff.args = [
169
171
  * @param path The path to override file
170
172
  * @returns The override object
171
173
  */
172
- async function readOverrideFile(path) {
173
- let overrideStringData;
174
- try {
175
- overrideStringData = await readFile(path, { encoding: 'utf8' });
176
- }
177
- catch (err) {
178
- throw new diff_error_1.DiffOverrideFileError();
179
- }
180
- try {
181
- return JSON.parse(overrideStringData);
182
- }
183
- catch (err) {
184
- throw new diff_error_1.DiffOverrideJSONError();
185
- }
174
+ function readOverrideFile(path) {
175
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
176
+ let overrideStringData;
177
+ try {
178
+ overrideStringData = yield readFile(path, { encoding: 'utf8' });
179
+ }
180
+ catch (err) {
181
+ throw new diff_error_1.DiffOverrideFileError();
182
+ }
183
+ try {
184
+ return JSON.parse(overrideStringData);
185
+ }
186
+ catch (err) {
187
+ throw new diff_error_1.DiffOverrideJSONError();
188
+ }
189
+ });
186
190
  }
187
191
  /**
188
192
  * function to enable watchmode.
@@ -5,14 +5,14 @@ export default class Template extends Command {
5
5
  static examples: Example[];
6
6
  static flags: {
7
7
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
8
- 'disable-hook': import("@oclif/core/lib/interfaces").OptionFlag<string[]>;
8
+ 'disable-hook': import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined>;
9
9
  install: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
10
  debug: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
- 'no-overwrite': import("@oclif/core/lib/interfaces").OptionFlag<string[]>;
11
+ 'no-overwrite': import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined>;
12
12
  output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
13
13
  'force-write': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
14
  watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
15
- param: import("@oclif/core/lib/interfaces").OptionFlag<string[]>;
15
+ param: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined>;
16
16
  'map-base-url': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
17
17
  };
18
18
  static args: {