@asyncapi/cli 0.16.0 → 0.18.1
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/README.md +17 -20
- package/assets/logo.png +0 -0
- package/lib/commands/convert.d.ts +15 -0
- package/lib/commands/convert.js +64 -0
- package/lib/commands/diff.d.ts +2 -1
- package/lib/commands/diff.js +42 -13
- package/lib/index.js +7 -0
- package/oclif.manifest.json +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<p align="center">
|
|
12
|
-
<a href="https://github.com/asyncapi/cli/blob/master/LICENSE"><img alt="GitHub license" src="https://img.shields.io/github/license/asyncapi/cli"></a>
|
|
13
|
-
<a href="https://github.com/asyncapi/cli/actions/workflows/if-nodejs-pr-testing.yml">
|
|
14
|
-
<img src="https://github.com/asyncapi/cli/actions/workflows/if-nodejs-pr-testing.yml/badge.svg" alt="PR testing - if Node project" />
|
|
15
|
-
</a>
|
|
16
|
-
<a href="https://www.npmjs.com/package/@asyncapi/cli">
|
|
17
|
-
<img alt="npm" src="https://img.shields.io/npm/dw/@asyncapi/cli">
|
|
18
|
-
</a>
|
|
19
|
-
|
|
20
|
-
</p>
|
|
1
|
+
[](https://www.asyncapi.com)
|
|
2
|
+
|
|
3
|
+
CLI to work with your AsyncAPI files. Currently supports validation, but it is under development for more features.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/asyncapi/cli/blob/master/LICENSE)
|
|
6
|
+
[](https://github.com/asyncapi/cli/actions/workflows/if-nodejs-pr-testing.yml)
|
|
7
|
+
[](https://www.npmjs.com/package/@asyncapi/cli)
|
|
8
|
+
|
|
9
|
+
|
|
21
10
|
|
|
22
11
|
## Table of contents
|
|
23
12
|
|
|
24
13
|
<!-- toc -->
|
|
25
14
|
|
|
15
|
+
- [Requirements](#requirements)
|
|
16
|
+
* [Installation](#installation)
|
|
17
|
+
- [Usage](#usage)
|
|
18
|
+
- [Contributing](#contributing)
|
|
19
|
+
* [Set up development environment](#set-up-development-environment)
|
|
20
|
+
* [Command Structure and Patterns](#command-structure-and-patterns)
|
|
21
|
+
- [Contributors](#contributors)
|
|
22
|
+
|
|
26
23
|
<!-- tocstop -->
|
|
27
24
|
|
|
28
25
|
## Requirements
|
package/assets/logo.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Command from '../base';
|
|
2
|
+
export default class Convert extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
6
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
7
|
+
'target-version': import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
8
|
+
};
|
|
9
|
+
static args: {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
required: boolean;
|
|
13
|
+
}[];
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
|
+
const base_1 = (0, tslib_1.__importDefault)(require("../base"));
|
|
8
|
+
const validation_error_1 = require("../errors/validation-error");
|
|
9
|
+
const SpecificationFile_1 = require("../models/SpecificationFile");
|
|
10
|
+
const specification_file_1 = require("../errors/specification-file");
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const converter_1 = require("@asyncapi/converter");
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
const specs_1 = (0, tslib_1.__importDefault)(require("@asyncapi/specs"));
|
|
15
|
+
const latestVersion = Object.keys(specs_1.default).pop();
|
|
16
|
+
class Convert extends base_1.default {
|
|
17
|
+
async run() {
|
|
18
|
+
const { args, flags } = await this.parse(Convert);
|
|
19
|
+
const filePath = args['spec-file'];
|
|
20
|
+
let specFile;
|
|
21
|
+
let convertedFile;
|
|
22
|
+
try {
|
|
23
|
+
// LOAD FILE
|
|
24
|
+
specFile = await (0, SpecificationFile_1.load)(filePath);
|
|
25
|
+
// CONVERSION
|
|
26
|
+
convertedFile = await (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
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (flags.output) {
|
|
36
|
+
await fs_1.promises.writeFile(`${flags.output}`, convertedFile, { encoding: 'utf8' });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.log(convertedFile);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
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
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.default = Convert;
|
|
56
|
+
Convert.description = 'convert asyncapi documents older to newer versions';
|
|
57
|
+
Convert.flags = {
|
|
58
|
+
help: core_1.Flags.help({ char: 'h' }),
|
|
59
|
+
output: core_1.Flags.string({ char: 'o', description: 'path to the file where the result is saved' }),
|
|
60
|
+
'target-version': core_1.Flags.string({ char: 't', description: 'asyncapi version to convert to', default: latestVersion })
|
|
61
|
+
};
|
|
62
|
+
Convert.args = [
|
|
63
|
+
{ name: 'spec-file', description: 'spec path, url, or context-name', required: false },
|
|
64
|
+
];
|
package/lib/commands/diff.d.ts
CHANGED
|
@@ -15,5 +15,6 @@ export default class Diff extends Command {
|
|
|
15
15
|
required: boolean;
|
|
16
16
|
}[];
|
|
17
17
|
run(): Promise<void>;
|
|
18
|
-
|
|
18
|
+
outputJSON(diffOutput: AsyncAPIDiff, outputType: string): void;
|
|
19
|
+
outputYAML(diffOutput: AsyncAPIDiff, outputType: string): void;
|
|
19
20
|
}
|
package/lib/commands/diff.js
CHANGED
|
@@ -26,7 +26,13 @@ class Diff extends base_1.default {
|
|
|
26
26
|
let firstDocument, secondDocument;
|
|
27
27
|
try {
|
|
28
28
|
firstDocument = await (0, SpecificationFile_1.load)(firstDocumentPath);
|
|
29
|
-
enableWatch(watchMode, {
|
|
29
|
+
enableWatch(watchMode, {
|
|
30
|
+
spec: firstDocument,
|
|
31
|
+
handler: this,
|
|
32
|
+
handlerName: 'diff',
|
|
33
|
+
docVersion: 'old',
|
|
34
|
+
label: 'DIFF_OLD',
|
|
35
|
+
});
|
|
30
36
|
}
|
|
31
37
|
catch (err) {
|
|
32
38
|
if (err instanceof specification_file_1.SpecificationFileNotFound) {
|
|
@@ -35,13 +41,17 @@ class Diff extends base_1.default {
|
|
|
35
41
|
filepath: firstDocumentPath,
|
|
36
42
|
}));
|
|
37
43
|
}
|
|
38
|
-
|
|
39
|
-
this.error(err);
|
|
40
|
-
}
|
|
44
|
+
this.error(err);
|
|
41
45
|
}
|
|
42
46
|
try {
|
|
43
47
|
secondDocument = await (0, SpecificationFile_1.load)(secondDocumentPath);
|
|
44
|
-
enableWatch(watchMode, {
|
|
48
|
+
enableWatch(watchMode, {
|
|
49
|
+
spec: secondDocument,
|
|
50
|
+
handler: this,
|
|
51
|
+
handlerName: 'diff',
|
|
52
|
+
docVersion: 'new',
|
|
53
|
+
label: 'DIFF_NEW',
|
|
54
|
+
});
|
|
45
55
|
}
|
|
46
56
|
catch (err) {
|
|
47
57
|
if (err instanceof specification_file_1.SpecificationFileNotFound) {
|
|
@@ -50,9 +60,7 @@ class Diff extends base_1.default {
|
|
|
50
60
|
filepath: secondDocumentPath,
|
|
51
61
|
}));
|
|
52
62
|
}
|
|
53
|
-
|
|
54
|
-
this.error(err);
|
|
55
|
-
}
|
|
63
|
+
this.error(err);
|
|
56
64
|
}
|
|
57
65
|
let overrides = {};
|
|
58
66
|
if (overrideFilePath) {
|
|
@@ -68,9 +76,13 @@ class Diff extends base_1.default {
|
|
|
68
76
|
const secondDocumentParsed = await parser.parse(secondDocument.text());
|
|
69
77
|
const diffOutput = diff.diff(firstDocumentParsed.json(), secondDocumentParsed.json(), {
|
|
70
78
|
override: overrides,
|
|
79
|
+
outputType: outputFormat, // NOSONAR
|
|
71
80
|
});
|
|
72
81
|
if (outputFormat === 'json') {
|
|
73
|
-
this.
|
|
82
|
+
this.outputJSON(diffOutput, outputType);
|
|
83
|
+
}
|
|
84
|
+
else if (outputFormat === 'yaml' || outputFormat === 'yml') {
|
|
85
|
+
this.outputYAML(diffOutput, outputType);
|
|
74
86
|
}
|
|
75
87
|
else {
|
|
76
88
|
this.log(`The output format ${outputFormat} is not supported at the moment.`);
|
|
@@ -83,7 +95,7 @@ class Diff extends base_1.default {
|
|
|
83
95
|
});
|
|
84
96
|
}
|
|
85
97
|
}
|
|
86
|
-
|
|
98
|
+
outputJSON(diffOutput, outputType) {
|
|
87
99
|
if (outputType === 'breaking') {
|
|
88
100
|
this.log(JSON.stringify(diffOutput.breaking(), null, 2));
|
|
89
101
|
}
|
|
@@ -100,6 +112,23 @@ class Diff extends base_1.default {
|
|
|
100
112
|
this.log(`The output type ${outputType} is not supported at the moment.`);
|
|
101
113
|
}
|
|
102
114
|
}
|
|
115
|
+
outputYAML(diffOutput, outputType) {
|
|
116
|
+
if (outputType === 'breaking') {
|
|
117
|
+
this.log(diffOutput.breaking());
|
|
118
|
+
}
|
|
119
|
+
else if (outputType === 'non-breaking') {
|
|
120
|
+
this.log(diffOutput.nonBreaking());
|
|
121
|
+
}
|
|
122
|
+
else if (outputType === 'unclassified') {
|
|
123
|
+
this.log(diffOutput.unclassified());
|
|
124
|
+
}
|
|
125
|
+
else if (outputType === 'all') {
|
|
126
|
+
this.log(diffOutput.getOutput());
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
this.log(`The output type ${outputType} is not supported at the moment.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
103
132
|
}
|
|
104
133
|
exports.default = Diff;
|
|
105
134
|
Diff.description = 'find diff between two asyncapi files';
|
|
@@ -108,8 +137,8 @@ Diff.flags = {
|
|
|
108
137
|
format: core_1.Flags.string({
|
|
109
138
|
char: 'f',
|
|
110
139
|
description: 'format of the output',
|
|
111
|
-
default: '
|
|
112
|
-
options: ['json'],
|
|
140
|
+
default: 'yaml',
|
|
141
|
+
options: ['json', 'yaml', 'yml'],
|
|
113
142
|
}),
|
|
114
143
|
type: core_1.Flags.string({
|
|
115
144
|
char: 't',
|
|
@@ -121,7 +150,7 @@ Diff.flags = {
|
|
|
121
150
|
char: 'o',
|
|
122
151
|
description: 'path to JSON file containing the override properties',
|
|
123
152
|
}),
|
|
124
|
-
watch: flags_1.watchFlag
|
|
153
|
+
watch: flags_1.watchFlag,
|
|
125
154
|
};
|
|
126
155
|
Diff.args = [
|
|
127
156
|
{
|
package/lib/index.js
CHANGED
|
@@ -3,3 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.run = void 0;
|
|
4
4
|
var core_1 = require("@oclif/core");
|
|
5
5
|
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
|
|
6
|
+
/**
|
|
7
|
+
* For NodeJS < 15, unhandled rejections are treated as warnings.
|
|
8
|
+
* This is required for consistency in error handling.
|
|
9
|
+
*/
|
|
10
|
+
process.on('unhandledRejection', (reason) => {
|
|
11
|
+
throw new Error(reason);
|
|
12
|
+
});
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.18.1","commands":{"convert":{"id":"convert","description":"convert asyncapi documents older to newer versions","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false},"output":{"name":"output","type":"option","char":"o","description":"path to the file where the result is saved","multiple":false},"target-version":{"name":"target-version","type":"option","char":"t","description":"asyncapi version to convert to","multiple":false,"default":"2.3.0"}},"args":[{"name":"spec-file","description":"spec path, url, or context-name","required":false}],"_globalFlags":{}},"diff":{"id":"diff","description":"find diff between two asyncapi files","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false},"format":{"name":"format","type":"option","char":"f","description":"format of the output","multiple":false,"options":["json","yaml","yml"],"default":"yaml"},"type":{"name":"type","type":"option","char":"t","description":"type of the output","multiple":false,"options":["breaking","non-breaking","unclassified","all"],"default":"all"},"overrides":{"name":"overrides","type":"option","char":"o","description":"path to JSON file containing the override properties","multiple":false},"watch":{"name":"watch","type":"boolean","char":"w","description":"Enable watch mode","allowNo":false}},"args":[{"name":"old","description":"old spec path, URL or context-name","required":true},{"name":"new","description":"new spec path, URL or context-name","required":true}],"_globalFlags":{}},"new":{"id":"new","description":"creates a new asyncapi file","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false},"file-name":{"name":"file-name","type":"option","char":"n","description":"name of the file","multiple":false},"example":{"name":"example","type":"option","char":"e","description":"name of the example to use","multiple":false},"studio":{"name":"studio","type":"boolean","char":"s","description":"open in Studio","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"port in which to start Studio","multiple":false},"no-tty":{"name":"no-tty","type":"boolean","description":"do not use an interactive terminal","allowNo":false}},"args":[],"_globalFlags":{}},"validate":{"id":"validate","description":"validate asyncapi file","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false},"watch":{"name":"watch","type":"boolean","char":"w","description":"Enable watch mode","allowNo":false}},"args":[{"name":"spec-file","description":"spec path, url, or context-name","required":false}],"_globalFlags":{}},"config":{"id":"config","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"start":{"id":"start","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"start:studio":{"id":"start:studio","description":"starts a new local instance of Studio","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false},"file":{"name":"file","type":"option","char":"f","description":"path to the AsyncAPI file to link with Studio","multiple":false},"port":{"name":"port","type":"option","char":"p","description":"port in which to start Studio","multiple":false}},"args":[],"_globalFlags":{}},"config:context:add":{"id":"config:context:add","description":"Add or modify a context in the store","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false}},"args":[{"name":"context-name","description":"context name","required":true},{"name":"spec-file-path","description":"file path of the spec file","required":true}],"_globalFlags":{}},"config:context:current":{"id":"config:context:current","description":"Shows the current context that is being used","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false}},"args":[],"_globalFlags":{}},"config:context":{"id":"config:context","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"config:context:list":{"id":"config:context:list","description":"List all the stored context in the store","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false}},"args":[],"_globalFlags":{}},"config:context:remove":{"id":"config:context:remove","description":"Delete a context from the store","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false}},"args":[{"name":"context-name","description":"Name of the context to delete","required":true}],"_globalFlags":{}},"config:context:use":{"id":"config:context:use","description":"Set a context as current","strict":true,"pluginName":"@asyncapi/cli","pluginAlias":"@asyncapi/cli","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false}},"args":[{"name":"context-name","description":"name of the saved context","required":true}],"_globalFlags":{}}}}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asyncapi/cli",
|
|
3
3
|
"description": "All in one CLI for all AsyncAPI tools",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.18.1",
|
|
5
5
|
"author": "@asyncapi",
|
|
6
6
|
"bin": {
|
|
7
7
|
"asyncapi": "./bin/run"
|
|
8
8
|
},
|
|
9
9
|
"bugs": "https://github.com/asyncapi/cli/issues",
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"@asyncapi/converter": "^0.9.0",
|
|
11
12
|
"@asyncapi/diff": "^0.3.0",
|
|
12
13
|
"@asyncapi/parser": "^1.14.0",
|
|
13
14
|
"@asyncapi/studio": "^0.10.0",
|