@asyncapi/cli 2.1.0 → 2.2.0
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/commands/generate/fromTemplate.js +1 -1
- package/lib/commands/validate.d.ts +1 -0
- package/lib/commands/validate.js +6 -0
- package/lib/core/flags/validate.flags.d.ts +1 -0
- package/lib/core/flags/validate.flags.js +5 -1
- package/lib/core/utils/scoreCalculator.d.ts +2 -0
- package/lib/core/utils/scoreCalculator.js +23 -0
- package/oclif.manifest.json +8 -1
- package/package.json +1 -1
|
@@ -272,7 +272,7 @@ class Template extends base_1.default {
|
|
|
272
272
|
const s = interactive ? (0, prompts_1.spinner)() : { start: () => null, stop: (string) => console.log(string) };
|
|
273
273
|
s.start('Generation in progress. Keep calm and wait a bit');
|
|
274
274
|
try {
|
|
275
|
-
yield generator.generateFromString(specification.text(), genOption);
|
|
275
|
+
yield generator.generateFromString(specification.text(), Object.assign(Object.assign({}, genOption), { path: asyncapi }));
|
|
276
276
|
}
|
|
277
277
|
catch (err) {
|
|
278
278
|
s.stop('Generation failed');
|
|
@@ -2,6 +2,7 @@ import Command from '../core/base';
|
|
|
2
2
|
export default class Validate extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
|
+
score: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
5
6
|
'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
6
7
|
'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
8
|
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
|
package/lib/commands/validate.js
CHANGED
|
@@ -7,12 +7,18 @@ const parser_1 = require("../core/parser");
|
|
|
7
7
|
const SpecificationFile_1 = require("../core/models/SpecificationFile");
|
|
8
8
|
const globals_1 = require("../core/globals");
|
|
9
9
|
const validate_flags_1 = require("../core/flags/validate.flags");
|
|
10
|
+
const scoreCalculator_1 = require("../core/utils/scoreCalculator");
|
|
10
11
|
class Validate extends base_1.default {
|
|
11
12
|
run() {
|
|
12
13
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
14
|
const { args, flags } = yield this.parse(Validate); //NOSONAR
|
|
14
15
|
const filePath = args['spec-file'];
|
|
15
16
|
const watchMode = flags.watch;
|
|
17
|
+
if (flags['score']) {
|
|
18
|
+
this.specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
19
|
+
const { document } = yield (0, parser_1.parse)(this, this.specFile);
|
|
20
|
+
this.log(`The score of the asyncapi document is ${yield (0, scoreCalculator_1.calculateScore)(document)}`);
|
|
21
|
+
}
|
|
16
22
|
this.specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
17
23
|
if (watchMode) {
|
|
18
24
|
(0, globals_1.specWatcher)({ spec: this.specFile, handler: this, handlerName: 'validate' });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const validateFlags: () => {
|
|
2
|
+
score: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
2
3
|
'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
3
4
|
'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
4
5
|
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
@@ -5,6 +5,10 @@ const core_1 = require("@oclif/core");
|
|
|
5
5
|
const parser_1 = require("../parser");
|
|
6
6
|
const global_flags_1 = require("./global.flags");
|
|
7
7
|
const validateFlags = () => {
|
|
8
|
-
return Object.assign({ help: core_1.Flags.help({ char: 'h' }), watch: (0, global_flags_1.watchFlag)() }, (0, parser_1.validationFlags)())
|
|
8
|
+
return Object.assign(Object.assign({ help: core_1.Flags.help({ char: 'h' }), watch: (0, global_flags_1.watchFlag)() }, (0, parser_1.validationFlags)()), { score: core_1.Flags.boolean({
|
|
9
|
+
description: 'Compute the score of the AsyncAPI document. Scoring is based on whether the document has description, license, server and/or channels.',
|
|
10
|
+
required: false,
|
|
11
|
+
default: false
|
|
12
|
+
}) });
|
|
9
13
|
};
|
|
10
14
|
exports.validateFlags = validateFlags;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateScore = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
function calculateScore(document) {
|
|
6
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
7
|
+
let scoreEvaluate = 0;
|
|
8
|
+
if (document === null || document === void 0 ? void 0 : document.info().hasDescription()) {
|
|
9
|
+
scoreEvaluate += 0.15;
|
|
10
|
+
}
|
|
11
|
+
if (document === null || document === void 0 ? void 0 : document.info().hasLicense()) {
|
|
12
|
+
scoreEvaluate += 0.25;
|
|
13
|
+
}
|
|
14
|
+
if (!(document === null || document === void 0 ? void 0 : document.servers().isEmpty())) {
|
|
15
|
+
scoreEvaluate += 0.25;
|
|
16
|
+
}
|
|
17
|
+
if (!(document === null || document === void 0 ? void 0 : document.channels().isEmpty())) {
|
|
18
|
+
scoreEvaluate += 0.35;
|
|
19
|
+
}
|
|
20
|
+
return (scoreEvaluate / 1) * 100;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.calculateScore = calculateScore;
|
package/oclif.manifest.json
CHANGED
|
@@ -394,6 +394,13 @@
|
|
|
394
394
|
"hint"
|
|
395
395
|
],
|
|
396
396
|
"type": "option"
|
|
397
|
+
},
|
|
398
|
+
"score": {
|
|
399
|
+
"description": "Compute the score of the AsyncAPI document. Scoring is based on whether the document has description, license, server and/or channels.",
|
|
400
|
+
"name": "score",
|
|
401
|
+
"required": false,
|
|
402
|
+
"allowNo": false,
|
|
403
|
+
"type": "boolean"
|
|
397
404
|
}
|
|
398
405
|
},
|
|
399
406
|
"hasDynamicHelp": false,
|
|
@@ -1567,5 +1574,5 @@
|
|
|
1567
1574
|
]
|
|
1568
1575
|
}
|
|
1569
1576
|
},
|
|
1570
|
-
"version": "2.
|
|
1577
|
+
"version": "2.2.0"
|
|
1571
1578
|
}
|