@asyncapi/cli 0.17.0 → 0.18.2
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 +9 -20
- package/assets/logo.png +0 -0
- package/lib/commands/diff.d.ts +2 -1
- package/lib/commands/diff.js +42 -13
- package/lib/index.js +7 -0
- package/lib/models/Studio.js +7 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
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
|
|
package/assets/logo.png
ADDED
|
Binary file
|
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/lib/models/Studio.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.start = exports.DEFAULT_PORT = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
|
+
const specification_file_1 = require("../errors/specification-file");
|
|
6
7
|
const path_1 = require("path");
|
|
7
8
|
const http_1 = require("http");
|
|
8
9
|
const serve_handler_1 = (0, tslib_1.__importDefault)(require("serve-handler"));
|
|
@@ -13,7 +14,13 @@ const { readFile, writeFile } = fs_1.promises;
|
|
|
13
14
|
const sockets = [];
|
|
14
15
|
const messageQueue = [];
|
|
15
16
|
exports.DEFAULT_PORT = 3210;
|
|
17
|
+
function isValidFilePath(filePath) {
|
|
18
|
+
return (0, fs_1.existsSync)(filePath);
|
|
19
|
+
}
|
|
16
20
|
function start(filePath, port = exports.DEFAULT_PORT) {
|
|
21
|
+
if (!isValidFilePath(filePath)) {
|
|
22
|
+
throw new specification_file_1.SpecificationFileNotFound(filePath);
|
|
23
|
+
}
|
|
17
24
|
chokidar_1.default.watch(filePath).on('all', (event, path) => {
|
|
18
25
|
switch (event) {
|
|
19
26
|
case 'add':
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.18.2","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":{}}}}
|