@asyncapi/cli 2.1.1 → 2.3.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.
@@ -6,6 +6,9 @@ export declare enum Optimizations {
6
6
  MOVE_DUPLICATES_TO_COMPONENTS = "move-duplicates-to-components",
7
7
  MOVE_ALL_TO_COMPONENTS = "move-all-to-components"
8
8
  }
9
+ export declare enum DisableOptimizations {
10
+ SCHEMA = "schema"
11
+ }
9
12
  export declare enum Outputs {
10
13
  TERMINAL = "terminal",
11
14
  NEW_FILE = "new-file",
@@ -15,11 +18,13 @@ export default class Optimize extends Command {
15
18
  static description: string;
16
19
  isInteractive: boolean;
17
20
  selectedOptimizations?: Optimizations[];
21
+ disableOptimizations?: DisableOptimizations[];
18
22
  outputMethod?: Outputs;
19
23
  static examples: string[];
20
24
  static flags: {
21
25
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
22
26
  optimization: import("@oclif/core/lib/interfaces").OptionFlag<string[], import("@oclif/core/lib/interfaces").CustomOptions>;
27
+ ignore: import("@oclif/core/lib/interfaces").OptionFlag<string[], import("@oclif/core/lib/interfaces").CustomOptions>;
23
28
  output: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
24
29
  'no-tty': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
25
30
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Outputs = exports.Optimizations = void 0;
3
+ exports.Outputs = exports.DisableOptimizations = exports.Optimizations = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@oclif/core");
6
6
  const optimizer_1 = require("@asyncapi/optimizer");
@@ -20,6 +20,10 @@ var Optimizations;
20
20
  Optimizations["MOVE_DUPLICATES_TO_COMPONENTS"] = "move-duplicates-to-components";
21
21
  Optimizations["MOVE_ALL_TO_COMPONENTS"] = "move-all-to-components";
22
22
  })(Optimizations = exports.Optimizations || (exports.Optimizations = {}));
23
+ var DisableOptimizations;
24
+ (function (DisableOptimizations) {
25
+ DisableOptimizations["SCHEMA"] = "schema";
26
+ })(DisableOptimizations = exports.DisableOptimizations || (exports.DisableOptimizations = {}));
23
27
  var Outputs;
24
28
  (function (Outputs) {
25
29
  Outputs["TERMINAL"] = "terminal";
@@ -60,6 +64,7 @@ class Optimize extends base_1.default {
60
64
  }
61
65
  this.isInteractive = !flags['no-tty'];
62
66
  this.selectedOptimizations = flags.optimization;
67
+ this.disableOptimizations = flags.ignore;
63
68
  this.outputMethod = flags.output;
64
69
  this.metricsMetadata.optimized = false;
65
70
  if (!(((_a = report.moveDuplicatesToComponents) === null || _a === void 0 ? void 0 : _a.length) || ((_b = report.removeComponents) === null || _b === void 0 ? void 0 : _b.length) || ((_c = report.reuseComponents) === null || _c === void 0 ? void 0 : _c.length))) {
@@ -76,7 +81,11 @@ class Optimize extends base_1.default {
76
81
  moveAllToComponents: this.selectedOptimizations.includes(Optimizations.MOVE_ALL_TO_COMPONENTS),
77
82
  removeComponents: this.selectedOptimizations.includes(Optimizations.REMOVE_COMPONENTS),
78
83
  reuseComponents: this.selectedOptimizations.includes(Optimizations.REUSE_COMPONENTS)
79
- }, output: optimizer_1.Output.YAML });
84
+ },
85
+ disableOptimizationFor: {
86
+ schema: this.disableOptimizations.includes(DisableOptimizations.SCHEMA)
87
+ },
88
+ output: optimizer_1.Output.YAML });
80
89
  this.collectMetricsData(report);
81
90
  const specPath = this.specFile.getFilePath();
82
91
  let newPath = '';
@@ -128,7 +137,7 @@ class Optimize extends base_1.default {
128
137
  this.log('\n');
129
138
  }
130
139
  interactiveRun(report) {
131
- var _a, _b, _c, _d, _e, _f, _g, _h;
140
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
132
141
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
133
142
  const canMoveDuplicates = (_a = report.moveDuplicatesToComponents) === null || _a === void 0 ? void 0 : _a.length;
134
143
  const canMoveAll = (_b = report.moveAllToComponents) === null || _b === void 0 ? void 0 : _b.length;
@@ -159,6 +168,12 @@ class Optimize extends base_1.default {
159
168
  this.showOptimizations(report.reuseComponents);
160
169
  choices.push({ name: 'reuse components', value: Optimizations.REUSE_COMPONENTS });
161
170
  }
171
+ if ((_j = this.disableOptimizations) === null || _j === void 0 ? void 0 : _j.includes(DisableOptimizations.SCHEMA)) {
172
+ choices.push({ name: 'Do not ignore schema', value: DisableOptimizations.SCHEMA });
173
+ }
174
+ else {
175
+ choices.push({ name: 'Ignore schema', value: DisableOptimizations.SCHEMA });
176
+ }
162
177
  const optimizationRes = yield inquirer.prompt([{
163
178
  name: 'optimization',
164
179
  message: 'select the type of optimization that you want to apply:',
@@ -166,6 +181,14 @@ class Optimize extends base_1.default {
166
181
  default: 'all',
167
182
  choices
168
183
  }]);
184
+ if (optimizationRes.optimization.includes('schema')) {
185
+ if ((_k = this.disableOptimizations) === null || _k === void 0 ? void 0 : _k.includes(DisableOptimizations.SCHEMA)) {
186
+ this.disableOptimizations = (_l = this.disableOptimizations) === null || _l === void 0 ? void 0 : _l.filter(opt => opt !== DisableOptimizations.SCHEMA);
187
+ }
188
+ else {
189
+ this.disableOptimizations = [...(this.disableOptimizations || []), DisableOptimizations.SCHEMA];
190
+ }
191
+ }
169
192
  this.selectedOptimizations = optimizationRes.optimization;
170
193
  const outputRes = yield inquirer.prompt([{
171
194
  name: 'output',
@@ -195,6 +218,7 @@ Optimize.examples = [
195
218
  'asyncapi optimize ./asyncapi.yaml --no-tty',
196
219
  'asyncapi optimize ./asyncapi.yaml --optimization=remove-components --optimization=reuse-components --optimization=move-all-to-components --no-tty',
197
220
  'asyncapi optimize ./asyncapi.yaml --optimization=remove-components --output=terminal --no-tty',
221
+ 'asyncapi optimize ./asyncapi.yaml --ignore=schema'
198
222
  ];
199
223
  Optimize.flags = (0, optimize_flags_1.optimizeFlags)();
200
224
  Optimize.args = {
@@ -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>;
@@ -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' });
@@ -4,6 +4,9 @@ export declare enum Optimizations {
4
4
  MOVE_DUPLICATES_TO_COMPONENTS = "move-duplicates-to-components",
5
5
  MOVE_ALL_TO_COMPONENTS = "move-all-to-components"
6
6
  }
7
+ export declare enum DisableOptimizations {
8
+ SCHEMA = "schema"
9
+ }
7
10
  export declare enum Outputs {
8
11
  TERMINAL = "terminal",
9
12
  NEW_FILE = "new-file",
@@ -12,6 +15,7 @@ export declare enum Outputs {
12
15
  export declare const optimizeFlags: () => {
13
16
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
14
17
  optimization: import("@oclif/core/lib/interfaces").OptionFlag<string[], import("@oclif/core/lib/interfaces").CustomOptions>;
18
+ ignore: import("@oclif/core/lib/interfaces").OptionFlag<string[], import("@oclif/core/lib/interfaces").CustomOptions>;
15
19
  output: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
16
20
  'no-tty': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
21
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.optimizeFlags = exports.Outputs = exports.Optimizations = void 0;
3
+ exports.optimizeFlags = exports.Outputs = exports.DisableOptimizations = exports.Optimizations = void 0;
4
4
  const core_1 = require("@oclif/core");
5
5
  var Optimizations;
6
6
  (function (Optimizations) {
@@ -9,6 +9,10 @@ var Optimizations;
9
9
  Optimizations["MOVE_DUPLICATES_TO_COMPONENTS"] = "move-duplicates-to-components";
10
10
  Optimizations["MOVE_ALL_TO_COMPONENTS"] = "move-all-to-components";
11
11
  })(Optimizations = exports.Optimizations || (exports.Optimizations = {}));
12
+ var DisableOptimizations;
13
+ (function (DisableOptimizations) {
14
+ DisableOptimizations["SCHEMA"] = "schema";
15
+ })(DisableOptimizations = exports.DisableOptimizations || (exports.DisableOptimizations = {}));
12
16
  var Outputs;
13
17
  (function (Outputs) {
14
18
  Outputs["TERMINAL"] = "terminal";
@@ -19,6 +23,7 @@ const optimizeFlags = () => {
19
23
  return {
20
24
  help: core_1.Flags.help({ char: 'h' }),
21
25
  optimization: core_1.Flags.string({ char: 'p', default: Object.values(Optimizations), options: Object.values(Optimizations), multiple: true, description: 'select the type of optimizations that you want to apply.' }),
26
+ ignore: core_1.Flags.string({ char: 'i', default: [], options: Object.values(DisableOptimizations), multiple: true, description: 'list of components to be ignored from the optimization process' }),
22
27
  output: core_1.Flags.string({ char: 'o', default: Outputs.TERMINAL, options: Object.values(Outputs), description: 'select where you want the output.' }),
23
28
  'no-tty': core_1.Flags.boolean({ description: 'do not use an interactive terminal', default: false }),
24
29
  };
@@ -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,2 @@
1
+ import { AsyncAPIDocumentInterface } from '@asyncapi/parser/cjs/models';
2
+ export declare function calculateScore(document: AsyncAPIDocumentInterface | undefined): Promise<number>;
@@ -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;
@@ -268,7 +268,8 @@
268
268
  "asyncapi optimize ./asyncapi.yaml",
269
269
  "asyncapi optimize ./asyncapi.yaml --no-tty",
270
270
  "asyncapi optimize ./asyncapi.yaml --optimization=remove-components --optimization=reuse-components --optimization=move-all-to-components --no-tty",
271
- "asyncapi optimize ./asyncapi.yaml --optimization=remove-components --output=terminal --no-tty"
271
+ "asyncapi optimize ./asyncapi.yaml --optimization=remove-components --output=terminal --no-tty",
272
+ "asyncapi optimize ./asyncapi.yaml --ignore=schema"
272
273
  ],
273
274
  "flags": {
274
275
  "help": {
@@ -298,6 +299,18 @@
298
299
  ],
299
300
  "type": "option"
300
301
  },
302
+ "ignore": {
303
+ "char": "i",
304
+ "description": "list of components to be ignored from the optimization process",
305
+ "name": "ignore",
306
+ "default": [],
307
+ "hasDynamicHelp": false,
308
+ "multiple": true,
309
+ "options": [
310
+ "schema"
311
+ ],
312
+ "type": "option"
313
+ },
301
314
  "output": {
302
315
  "char": "o",
303
316
  "description": "select where you want the output.",
@@ -394,6 +407,13 @@
394
407
  "hint"
395
408
  ],
396
409
  "type": "option"
410
+ },
411
+ "score": {
412
+ "description": "Compute the score of the AsyncAPI document. Scoring is based on whether the document has description, license, server and/or channels.",
413
+ "name": "score",
414
+ "required": false,
415
+ "allowNo": false,
416
+ "type": "boolean"
397
417
  }
398
418
  },
399
419
  "hasDynamicHelp": false,
@@ -1567,5 +1587,5 @@
1567
1587
  ]
1568
1588
  }
1569
1589
  },
1570
- "version": "2.1.1"
1590
+ "version": "2.3.0"
1571
1591
  }
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.1.1",
4
+ "version": "2.3.0",
5
5
  "author": "@asyncapi",
6
6
  "bin": {
7
7
  "asyncapi": "./bin/run_bin"