@asyncapi/cli 0.51.2 → 0.51.4
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 +3 -0
- package/lib/commands/bundle.d.ts +2 -1
- package/lib/commands/bundle.js +10 -3
- package/lib/commands/diff.js +7 -2
- package/lib/commands/generate/fromTemplate.js +31 -0
- package/lib/commands/generate/models.js +3 -0
- package/lib/commands/optimize.js +12 -1
- package/lib/models/SpecificationFile.d.ts +2 -0
- package/lib/models/SpecificationFile.js +13 -0
- package/oclif.manifest.json +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -81,6 +81,9 @@ Thanks go to these wonderful people ([emoji key](https://allcontributors.org/doc
|
|
|
81
81
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/meetagrawal09"><img src="https://avatars.githubusercontent.com/u/73902874?v=4?s=100" width="100px;" alt="Meet Agrawal"/><br /><sub><b>Meet Agrawal</b></sub></a><br /><a href="#infra-meetagrawal09" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
|
|
82
82
|
<td align="center" valign="top" width="14.28%"><a href="https://www.chinmayyy.tech"><img src="https://avatars.githubusercontent.com/u/112387862?v=4?s=100" width="100px;" alt="Chinmay Shewale"/><br /><sub><b>Chinmay Shewale</b></sub></a><br /><a href="https://github.com/asyncapi/cli/commits?author=chinma-yyy" title="Code">💻</a> <a href="https://github.com/asyncapi/cli/commits?author=chinma-yyy" title="Tests">⚠️</a></td>
|
|
83
83
|
</tr>
|
|
84
|
+
<tr>
|
|
85
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mhmohona"><img src="https://avatars.githubusercontent.com/u/14244685?v=4?s=100" width="100px;" alt="Mahfuza Humayra Mohona"/><br /><sub><b>Mahfuza Humayra Mohona</b></sub></a><br /><a href="https://github.com/asyncapi/cli/commits?author=mhmohona" title="Documentation">📖</a></td>
|
|
86
|
+
</tr>
|
|
84
87
|
</tbody>
|
|
85
88
|
</table>
|
|
86
89
|
|
package/lib/commands/bundle.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Example } from '@oclif/core/lib/interfaces';
|
|
2
2
|
import Command from '../base';
|
|
3
|
+
import { Specification } from '../models/SpecificationFile';
|
|
3
4
|
export default class Bundle extends Command {
|
|
4
5
|
static description: string;
|
|
5
6
|
static strict: boolean;
|
|
@@ -11,5 +12,5 @@ export default class Bundle extends Command {
|
|
|
11
12
|
base: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
12
13
|
};
|
|
13
14
|
run(): Promise<void>;
|
|
14
|
-
loadFiles(filepaths: string[]): Promise<
|
|
15
|
+
loadFiles(filepaths: string[]): Promise<Specification[]>;
|
|
15
16
|
}
|
package/lib/commands/bundle.js
CHANGED
|
@@ -16,10 +16,17 @@ class Bundle extends base_1.default {
|
|
|
16
16
|
let baseFile;
|
|
17
17
|
const outputFormat = path_1.default.extname(argv[0]);
|
|
18
18
|
const AsyncAPIFiles = yield this.loadFiles(argv);
|
|
19
|
+
const containsAsyncAPI3 = AsyncAPIFiles.filter((file) => {
|
|
20
|
+
return file.isAsyncAPI3();
|
|
21
|
+
});
|
|
22
|
+
if (containsAsyncAPI3.length > 0) {
|
|
23
|
+
this.error('One of the files you tried to bundle is AsyncAPI v3 format, the bundle command does not support it yet, please checkout https://github.com/asyncapi/bundler/issues/133');
|
|
24
|
+
}
|
|
19
25
|
if (flags.base) {
|
|
20
26
|
baseFile = (yield (0, SpecificationFile_1.load)(flags.base)).text();
|
|
21
27
|
}
|
|
22
|
-
const
|
|
28
|
+
const fileContents = AsyncAPIFiles.map((file) => file.text());
|
|
29
|
+
const document = yield (0, bundler_1.default)(fileContents, {
|
|
23
30
|
referenceIntoComponents: flags['reference-into-components'],
|
|
24
31
|
base: baseFile
|
|
25
32
|
});
|
|
@@ -39,7 +46,7 @@ class Bundle extends base_1.default {
|
|
|
39
46
|
});
|
|
40
47
|
}
|
|
41
48
|
if (format === '.json') {
|
|
42
|
-
yield writeFile(path_1.default.resolve(process.cwd(), output), document.
|
|
49
|
+
yield writeFile(path_1.default.resolve(process.cwd(), output), document.string(), {
|
|
43
50
|
encoding: 'utf-8',
|
|
44
51
|
});
|
|
45
52
|
}
|
|
@@ -52,7 +59,7 @@ class Bundle extends base_1.default {
|
|
|
52
59
|
const files = [];
|
|
53
60
|
for (const filepath of filepaths) {
|
|
54
61
|
const file = yield (0, SpecificationFile_1.load)(filepath);
|
|
55
|
-
files.push(file
|
|
62
|
+
files.push(file);
|
|
56
63
|
}
|
|
57
64
|
return files;
|
|
58
65
|
});
|
package/lib/commands/diff.js
CHANGED
|
@@ -33,6 +33,9 @@ class Diff extends base_1.default {
|
|
|
33
33
|
markdownSubtype = setDefaultMarkdownSubtype(outputFormat, markdownSubtype);
|
|
34
34
|
try {
|
|
35
35
|
firstDocument = yield (0, SpecificationFile_1.load)(firstDocumentPath);
|
|
36
|
+
if (firstDocument.isAsyncAPI3()) {
|
|
37
|
+
this.error('Diff command does not support AsyncAPI v3 yet which was your first document, please checkout https://github.com/asyncapi/diff/issues/154');
|
|
38
|
+
}
|
|
36
39
|
enableWatch(watchMode, {
|
|
37
40
|
spec: firstDocument,
|
|
38
41
|
handler: this,
|
|
@@ -52,6 +55,9 @@ class Diff extends base_1.default {
|
|
|
52
55
|
}
|
|
53
56
|
try {
|
|
54
57
|
secondDocument = yield (0, SpecificationFile_1.load)(secondDocumentPath);
|
|
58
|
+
if (secondDocument.isAsyncAPI3()) {
|
|
59
|
+
this.error('Diff command does not support AsyncAPI v3 yet which was your second document, please checkout https://github.com/asyncapi/diff/issues/154');
|
|
60
|
+
}
|
|
55
61
|
enableWatch(watchMode, {
|
|
56
62
|
spec: secondDocument,
|
|
57
63
|
handler: this,
|
|
@@ -237,8 +243,7 @@ const enableWatch = (status, watcher) => {
|
|
|
237
243
|
function throwOnBreakingChange(diffOutput, outputFormat) {
|
|
238
244
|
const breakingChanges = diffOutput.breaking();
|
|
239
245
|
if ((outputFormat === 'json' && breakingChanges.length !== 0) ||
|
|
240
|
-
((outputFormat === 'yaml' || outputFormat === 'yml') && breakingChanges !== '[]\n')
|
|
241
|
-
(outputFormat === 'md' && breakingChanges.length !== 0)) {
|
|
246
|
+
((outputFormat === 'yaml' || outputFormat === 'yml') && breakingChanges !== '[]\n')) {
|
|
242
247
|
throw new diff_error_1.DiffBreakingChangeError();
|
|
243
248
|
}
|
|
244
249
|
}
|
|
@@ -18,6 +18,30 @@ const red = (text) => `\x1b[31m${text}\x1b[0m`;
|
|
|
18
18
|
const magenta = (text) => `\x1b[35m${text}\x1b[0m`;
|
|
19
19
|
const yellow = (text) => `\x1b[33m${text}\x1b[0m`;
|
|
20
20
|
const green = (text) => `\x1b[32m${text}\x1b[0m`;
|
|
21
|
+
const templatesNotSupportingV3 = {
|
|
22
|
+
'@asyncapi/minimaltemplate': 'some link',
|
|
23
|
+
'@asyncapi/html-template': 'https://github.com/asyncapi/html-template/issues/430',
|
|
24
|
+
'@asyncapi/dotnet-nats-template': 'https://github.com/asyncapi/dotnet-nats-template/issues/384',
|
|
25
|
+
'@asyncapi/ts-nats-template': 'https://github.com/asyncapi/ts-nats-template/issues/545',
|
|
26
|
+
'@asyncapi/python-paho-template': 'https://github.com/asyncapi/python-paho-template/issues/189',
|
|
27
|
+
'@asyncapi/nodejs-ws-template': 'https://github.com/asyncapi/nodejs-ws-template/issues/294',
|
|
28
|
+
'@asyncapi/java-spring-cloud-stream-template': 'https://github.com/asyncapi/java-spring-cloud-stream-template/issues/336',
|
|
29
|
+
'@asyncapi/go-watermill-template': 'https://github.com/asyncapi/go-watermill-template/issues/243',
|
|
30
|
+
'@asyncapi/java-spring-template': 'https://github.com/asyncapi/java-spring-template/issues/308',
|
|
31
|
+
'@asyncapi/markdown-template': 'https://github.com/asyncapi/markdown-template/issues/341',
|
|
32
|
+
'@asyncapi/nodejs-template': 'https://github.com/asyncapi/nodejs-template/issues/215',
|
|
33
|
+
'@asyncapi/java-template': 'https://github.com/asyncapi/java-template/issues/118',
|
|
34
|
+
'@asyncapi/php-template': 'https://github.com/asyncapi/php-template/issues/191'
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Verify that a given template support v3, if not, return the link to the issue that needs to be solved.
|
|
38
|
+
*/
|
|
39
|
+
function verifyTemplateSupportForV3(template) {
|
|
40
|
+
if (templatesNotSupportingV3[`${template}`] !== undefined) {
|
|
41
|
+
return templatesNotSupportingV3[`${template}`];
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
21
45
|
class Template extends base_1.default {
|
|
22
46
|
constructor() {
|
|
23
47
|
super(...arguments);
|
|
@@ -67,11 +91,18 @@ class Template extends base_1.default {
|
|
|
67
91
|
mapBaseUrlToFolder: parsedFlags.mapBaseUrlToFolder,
|
|
68
92
|
disabledHooks: parsedFlags.disableHooks,
|
|
69
93
|
};
|
|
94
|
+
const asyncapiInput = (yield (0, SpecificationFile_1.load)(asyncapi)) || (yield (0, SpecificationFile_1.load)());
|
|
70
95
|
const watchTemplate = flags['watch'];
|
|
71
96
|
const genOption = {};
|
|
72
97
|
if (flags['map-base-url']) {
|
|
73
98
|
genOption.resolve = { resolve: this.getMapBaseUrlToFolderResolver(parsedFlags.mapBaseUrlToFolder) };
|
|
74
99
|
}
|
|
100
|
+
if (asyncapiInput.isAsyncAPI3()) {
|
|
101
|
+
const v3IssueLink = verifyTemplateSupportForV3(template);
|
|
102
|
+
if (v3IssueLink !== undefined) {
|
|
103
|
+
this.error(`${template} template does not support AsyncAPI v3 documents, please checkout ${v3IssueLink}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
75
106
|
yield this.generate(asyncapi, template, output, options, genOption);
|
|
76
107
|
if (watchTemplate) {
|
|
77
108
|
const watcherHandler = this.watcherHandler(asyncapi, template, output, options, genOption);
|
|
@@ -29,6 +29,9 @@ class Models extends base_1.default {
|
|
|
29
29
|
const { tsModelType, tsEnumType, tsIncludeComments, tsModuleSystem, tsExportType, tsJsonBinPack, tsMarshalling, tsExampleInstance, namespace, csharpAutoImplement, csharpArrayType, csharpNewtonsoft, csharpHashcode, csharpEqual, csharpSystemJson, packageName, output } = flags;
|
|
30
30
|
const { language, file } = args;
|
|
31
31
|
const inputFile = (yield (0, SpecificationFile_1.load)(file)) || (yield (0, SpecificationFile_1.load)());
|
|
32
|
+
if (inputFile.isAsyncAPI3()) {
|
|
33
|
+
this.error('Generate Models command does not support AsyncAPI v3 yet, please checkout https://github.com/asyncapi/modelina/issues/1376');
|
|
34
|
+
}
|
|
32
35
|
const { document, diagnostics, status } = yield (0, parser_1.parse)(this, inputFile, flags);
|
|
33
36
|
if (!document || status === 'invalid') {
|
|
34
37
|
const severityErrors = diagnostics.filter((obj) => obj.severity === 0);
|
package/lib/commands/optimize.js
CHANGED
|
@@ -34,10 +34,21 @@ class Optimize extends base_1.default {
|
|
|
34
34
|
const { args, flags } = yield this.parse(Optimize); //NOSONAR
|
|
35
35
|
const filePath = args['spec-file'];
|
|
36
36
|
let specFile;
|
|
37
|
+
try {
|
|
38
|
+
specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
this.error(new validation_error_1.ValidationError({
|
|
42
|
+
type: 'invalid-file',
|
|
43
|
+
filepath: filePath,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
if (specFile.isAsyncAPI3()) {
|
|
47
|
+
this.error('Optimize command does not support AsyncAPI v3 yet, please checkout https://github.com/asyncapi/optimizer/issues/168');
|
|
48
|
+
}
|
|
37
49
|
let optimizer;
|
|
38
50
|
let report;
|
|
39
51
|
try {
|
|
40
|
-
specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
41
52
|
optimizer = new optimizer_1.Optimizer(specFile.text());
|
|
42
53
|
report = yield optimizer.getReport();
|
|
43
54
|
}
|
|
@@ -6,6 +6,7 @@ const fs_1 = require("fs");
|
|
|
6
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
7
|
const url_1 = require("url");
|
|
8
8
|
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
9
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
9
10
|
const Context_1 = require("./Context");
|
|
10
11
|
const specification_file_1 = require("../errors/specification-file");
|
|
11
12
|
const context_error_1 = require("../errors/context-error");
|
|
@@ -30,6 +31,18 @@ class Specification {
|
|
|
30
31
|
this.kind = 'url';
|
|
31
32
|
}
|
|
32
33
|
}
|
|
34
|
+
isAsyncAPI3() {
|
|
35
|
+
const jsObj = this.toJson();
|
|
36
|
+
return jsObj.asyncapi === '3.0.0';
|
|
37
|
+
}
|
|
38
|
+
toJson() {
|
|
39
|
+
try {
|
|
40
|
+
return js_yaml_1.default.load(this.spec, { json: true });
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
return JSON.parse(this.spec);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
33
46
|
text() {
|
|
34
47
|
return this.spec;
|
|
35
48
|
}
|
package/oclif.manifest.json
CHANGED
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": "0.51.
|
|
4
|
+
"version": "0.51.4",
|
|
5
5
|
"author": "@asyncapi",
|
|
6
6
|
"bin": {
|
|
7
7
|
"asyncapi": "./bin/run"
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"fs-extra": "^11.1.0",
|
|
30
30
|
"indent-string": "^4.0.0",
|
|
31
31
|
"inquirer": "^8.2.0",
|
|
32
|
+
"js-yaml": "^4.1.0",
|
|
32
33
|
"lodash.template": "^4.4.0",
|
|
33
34
|
"node-fetch": "^2.0.0",
|
|
34
35
|
"oclif": "^3.7.3",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"@types/fs-extra": "^11.0.1",
|
|
53
54
|
"@types/inquirer": "^8.1.3",
|
|
54
55
|
"@types/jest": "^29.0.3",
|
|
56
|
+
"@types/js-yaml": "^4.0.5",
|
|
55
57
|
"@types/lodash.template": "^4.4.4",
|
|
56
58
|
"@types/node": "^10.17.60",
|
|
57
59
|
"@types/node-fetch": "^2.5.12",
|