@asyncapi/cli 0.25.1 → 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 +3 -1
- package/lib/base.js +16 -3
- package/lib/commands/config/context/add.js +8 -6
- package/lib/commands/config/context/current.js +5 -3
- package/lib/commands/config/context/index.js +6 -4
- package/lib/commands/config/context/list.js +7 -5
- package/lib/commands/config/context/remove.js +12 -10
- package/lib/commands/config/context/use.js +7 -5
- package/lib/commands/config/index.js +6 -4
- package/lib/commands/convert.js +34 -32
- package/lib/commands/diff.js +87 -83
- package/lib/commands/generate/fromTemplate.d.ts +3 -3
- package/lib/commands/generate/fromTemplate.js +89 -83
- package/lib/commands/generate/index.js +5 -3
- package/lib/commands/generate/models.js +83 -81
- package/lib/commands/new.js +96 -90
- package/lib/commands/start/index.js +5 -3
- package/lib/commands/start/studio.js +7 -5
- package/lib/commands/validate.js +24 -22
- package/lib/flags.d.ts +1 -1
- package/lib/globals.js +4 -4
- package/lib/models/Context.js +88 -74
- package/lib/models/SpecificationFile.js +122 -103
- package/lib/utils/generator.js +15 -11
- package/oclif.manifest.json +1 -1
- package/package.json +17 -14
package/lib/base.d.ts
CHANGED
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
package/lib/commands/convert.js
CHANGED
|
@@ -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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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;
|
package/lib/commands/diff.js
CHANGED
|
@@ -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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
85
|
-
|
|
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
|
-
|
|
88
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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: {
|