@asyncapi/cli 2.10.0 → 2.11.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/assets/create-glee-app/templates/default/package-lock.json +3 -3
- package/assets/create-glee-app/templates/tutorial/package-lock.json +3 -3
- package/lib/commands/pretty.d.ts +12 -0
- package/lib/commands/pretty.js +67 -0
- package/lib/core/flags/pretty.flags.d.ts +3 -0
- package/lib/core/flags/pretty.flags.js +13 -0
- package/oclif.manifest.json +39 -1
- package/package.json +4 -3
|
@@ -5462,9 +5462,9 @@
|
|
|
5462
5462
|
}
|
|
5463
5463
|
},
|
|
5464
5464
|
"node_modules/cross-spawn": {
|
|
5465
|
-
"version": "7.0.
|
|
5466
|
-
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.
|
|
5467
|
-
"integrity": "sha512-
|
|
5465
|
+
"version": "7.0.6",
|
|
5466
|
+
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
|
5467
|
+
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
|
5468
5468
|
"dependencies": {
|
|
5469
5469
|
"path-key": "^3.1.0",
|
|
5470
5470
|
"shebang-command": "^2.0.0",
|
|
@@ -5459,9 +5459,9 @@
|
|
|
5459
5459
|
}
|
|
5460
5460
|
},
|
|
5461
5461
|
"node_modules/cross-spawn": {
|
|
5462
|
-
"version": "7.0.
|
|
5463
|
-
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.
|
|
5464
|
-
"integrity": "sha512-
|
|
5462
|
+
"version": "7.0.5",
|
|
5463
|
+
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.5.tgz",
|
|
5464
|
+
"integrity": "sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==",
|
|
5465
5465
|
"dependencies": {
|
|
5466
5466
|
"path-key": "^3.1.0",
|
|
5467
5467
|
"shebang-command": "^2.0.0",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Command from '../core/base';
|
|
2
|
+
export default class Pretty extends Command {
|
|
3
|
+
static readonly description = "Format AsyncAPI specification file";
|
|
4
|
+
static readonly examples: string[];
|
|
5
|
+
static readonly flags: {
|
|
6
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
|
+
};
|
|
8
|
+
static readonly args: {
|
|
9
|
+
'spec-file': import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const yaml = tslib_1.__importStar(require("yaml"));
|
|
7
|
+
const base_1 = tslib_1.__importDefault(require("../core/base"));
|
|
8
|
+
const SpecificationFile_1 = require("../core/models/SpecificationFile");
|
|
9
|
+
const validation_error_1 = require("../core/errors/validation-error");
|
|
10
|
+
const pretty_flags_1 = require("../core/flags/pretty.flags");
|
|
11
|
+
class Pretty extends base_1.default {
|
|
12
|
+
run() {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const { args, flags } = yield this.parse(Pretty);
|
|
15
|
+
const filePath = args['spec-file'];
|
|
16
|
+
const outputPath = flags.output;
|
|
17
|
+
try {
|
|
18
|
+
this.specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
this.error(new validation_error_1.ValidationError({
|
|
22
|
+
type: 'invalid-file',
|
|
23
|
+
filepath: filePath,
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
const content = this.specFile.text();
|
|
27
|
+
let formatted;
|
|
28
|
+
try {
|
|
29
|
+
const fileFormat = (0, SpecificationFile_1.retrieveFileFormat)(this.specFile.text());
|
|
30
|
+
if (fileFormat === 'yaml' || fileFormat === 'yml') {
|
|
31
|
+
const yamlDoc = yaml.parseDocument(content);
|
|
32
|
+
formatted = yamlDoc.toString({
|
|
33
|
+
lineWidth: 0,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else if (fileFormat === 'json') {
|
|
37
|
+
const jsonObj = JSON.parse(content);
|
|
38
|
+
formatted = JSON.stringify(jsonObj, null, 2);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error('Unsupported file format');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
this.error(`Error formatting file: ${err}`);
|
|
46
|
+
}
|
|
47
|
+
if (outputPath) {
|
|
48
|
+
yield fs_1.promises.writeFile(outputPath, formatted, 'utf8');
|
|
49
|
+
this.log(`Asyncapi document has been beautified ${outputPath}`);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
yield fs_1.promises.writeFile(filePath, formatted, 'utf8');
|
|
53
|
+
this.log(`Asyncapi document ${filePath} has been beautified in-place.`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.default = Pretty;
|
|
59
|
+
Pretty.description = 'Format AsyncAPI specification file';
|
|
60
|
+
Pretty.examples = [
|
|
61
|
+
'asyncapi pretty ./asyncapi.yaml',
|
|
62
|
+
'asyncapi pretty ./asyncapi.yaml --output formatted-asyncapi.yaml',
|
|
63
|
+
];
|
|
64
|
+
Pretty.flags = (0, pretty_flags_1.prettyFlags)();
|
|
65
|
+
Pretty.args = {
|
|
66
|
+
'spec-file': core_1.Args.string({ description: 'spec path, url, or context-name', required: true }),
|
|
67
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prettyFlags = void 0;
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const prettyFlags = () => {
|
|
6
|
+
return {
|
|
7
|
+
output: core_1.Flags.string({
|
|
8
|
+
char: 'o',
|
|
9
|
+
description: 'Output file path',
|
|
10
|
+
}),
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.prettyFlags = prettyFlags;
|
package/oclif.manifest.json
CHANGED
|
@@ -440,6 +440,44 @@
|
|
|
440
440
|
"optimize.js"
|
|
441
441
|
]
|
|
442
442
|
},
|
|
443
|
+
"pretty": {
|
|
444
|
+
"aliases": [],
|
|
445
|
+
"args": {
|
|
446
|
+
"spec-file": {
|
|
447
|
+
"description": "spec path, url, or context-name",
|
|
448
|
+
"name": "spec-file",
|
|
449
|
+
"required": true
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
"description": "Format AsyncAPI specification file",
|
|
453
|
+
"examples": [
|
|
454
|
+
"asyncapi pretty ./asyncapi.yaml",
|
|
455
|
+
"asyncapi pretty ./asyncapi.yaml --output formatted-asyncapi.yaml"
|
|
456
|
+
],
|
|
457
|
+
"flags": {
|
|
458
|
+
"output": {
|
|
459
|
+
"char": "o",
|
|
460
|
+
"description": "Output file path",
|
|
461
|
+
"name": "output",
|
|
462
|
+
"hasDynamicHelp": false,
|
|
463
|
+
"multiple": false,
|
|
464
|
+
"type": "option"
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
"hasDynamicHelp": false,
|
|
468
|
+
"hiddenAliases": [],
|
|
469
|
+
"id": "pretty",
|
|
470
|
+
"pluginAlias": "@asyncapi/cli",
|
|
471
|
+
"pluginName": "@asyncapi/cli",
|
|
472
|
+
"pluginType": "core",
|
|
473
|
+
"strict": true,
|
|
474
|
+
"isESM": false,
|
|
475
|
+
"relativePath": [
|
|
476
|
+
"lib",
|
|
477
|
+
"commands",
|
|
478
|
+
"pretty.js"
|
|
479
|
+
]
|
|
480
|
+
},
|
|
443
481
|
"validate": {
|
|
444
482
|
"aliases": [],
|
|
445
483
|
"args": {
|
|
@@ -1694,5 +1732,5 @@
|
|
|
1694
1732
|
]
|
|
1695
1733
|
}
|
|
1696
1734
|
},
|
|
1697
|
-
"version": "2.
|
|
1735
|
+
"version": "2.11.1"
|
|
1698
1736
|
}
|
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": "2.
|
|
4
|
+
"version": "2.11.1",
|
|
5
5
|
"author": "@asyncapi",
|
|
6
6
|
"bin": {
|
|
7
7
|
"asyncapi": "./bin/run_bin"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@asyncapi/openapi-schema-parser": "^3.0.24",
|
|
18
18
|
"@asyncapi/optimizer": "^1.0.4",
|
|
19
19
|
"@asyncapi/parser": "^3.3.0",
|
|
20
|
-
"@asyncapi/protobuf-schema-parser": "^3.2.
|
|
20
|
+
"@asyncapi/protobuf-schema-parser": "^3.2.15",
|
|
21
21
|
"@asyncapi/raml-dt-schema-parser": "^4.0.24",
|
|
22
22
|
"@asyncapi/studio": "^0.20.0",
|
|
23
23
|
"@clack/prompts": "^0.7.0",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"strip-ansi": "^6.0.0",
|
|
42
42
|
"unzipper": "^0.10.11",
|
|
43
43
|
"uuid": "^9.0.1",
|
|
44
|
-
"ws": "^8.2.3"
|
|
44
|
+
"ws": "^8.2.3",
|
|
45
|
+
"yaml": "^2.6.1"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@asyncapi/minimaltemplate": "./test/fixtures/minimaltemplate",
|