@asyncapi/cli 0.58.10 → 0.58.12

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.
@@ -2492,9 +2492,9 @@
2492
2492
  }
2493
2493
  },
2494
2494
  "node_modules/@babel/traverse": {
2495
- "version": "7.23.0",
2496
- "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.0.tgz",
2497
- "integrity": "sha512-t/QaEvyIoIkwzpiZ7aoSKK8kObQYeF7T2v+dazAYCb8SXtp58zEVkWW7zAnju8FNKNdr4ScAOEDmMItbyOmEYw==",
2495
+ "version": "7.23.2",
2496
+ "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz",
2497
+ "integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==",
2498
2498
  "dependencies": {
2499
2499
  "@babel/code-frame": "^7.22.13",
2500
2500
  "@babel/generator": "^7.23.0",
@@ -14296,9 +14296,9 @@
14296
14296
  }
14297
14297
  },
14298
14298
  "@babel/traverse": {
14299
- "version": "7.23.0",
14300
- "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.0.tgz",
14301
- "integrity": "sha512-t/QaEvyIoIkwzpiZ7aoSKK8kObQYeF7T2v+dazAYCb8SXtp58zEVkWW7zAnju8FNKNdr4ScAOEDmMItbyOmEYw==",
14299
+ "version": "7.23.2",
14300
+ "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz",
14301
+ "integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==",
14302
14302
  "requires": {
14303
14303
  "@babel/code-frame": "^7.22.13",
14304
14304
  "@babel/generator": "^7.23.0",
package/bin/run CHANGED
@@ -6,7 +6,6 @@ oclif.run()
6
6
  .then(require('@oclif/core/flush'))
7
7
  .catch((err) => {
8
8
  const oclifHandler = require('@oclif/core/handle');
9
- console.error(err.message);
10
9
  return oclifHandler(err.message);
11
10
  });
12
11
 
@@ -0,0 +1,4 @@
1
+ import { Hook } from '@oclif/core';
2
+ export declare const closest: (target: string, possibilities: string[]) => string;
3
+ declare const hook: Hook.CommandNotFound;
4
+ export default hook;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.closest = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const core_1 = require("@oclif/core");
6
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
+ const fast_levenshtein_1 = tslib_1.__importDefault(require("fast-levenshtein"));
8
+ const core_2 = require("@oclif/core");
9
+ const closest = (target, possibilities) => {
10
+ var _a, _b;
11
+ return (_b = (_a = possibilities
12
+ .map((id) => ({ distance: fast_levenshtein_1.default.get(target, id, { useCollator: true }), id }))
13
+ .sort((a, b) => a.distance - b.distance)[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '';
14
+ };
15
+ exports.closest = closest;
16
+ const hook = function (opts) {
17
+ var _a;
18
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
19
+ if (opts.id === '--help') {
20
+ const help = new core_2.Help(this.config);
21
+ help.showHelp(['--help']);
22
+ return;
23
+ }
24
+ const hiddenCommandIds = new Set(opts.config.commands.filter((c) => c.hidden).map((c) => c.id));
25
+ const commandIDs = [...opts.config.commandIDs, ...opts.config.commands.flatMap((c) => c.aliases)].filter((c) => !hiddenCommandIds.has(c));
26
+ if (commandIDs.length === 0) {
27
+ return;
28
+ }
29
+ // now we we return if the command id are not there.
30
+ let binHelp = `${opts.config.bin} help`;
31
+ const idSplit = opts.id.split(':');
32
+ if (opts.config.findTopic(idSplit[0])) {
33
+ // if valid topic, update binHelp with topic
34
+ binHelp = `${binHelp} ${idSplit[0]}`;
35
+ }
36
+ //if there is a topic in the opts we just upgrade the our commnad like
37
+ // alter the suggestion in the help scenario so that help is the first command
38
+ // otherwise the user will be presented 'did you mean 'help'?' instead of 'did you mean "help <command>"?'
39
+ let suggestion = (/:?help:?/).test(opts.id)
40
+ ? ['help', ...opts.id.split(':').filter((cmd) => cmd !== 'help')].join(':')
41
+ : (0, exports.closest)(opts.id, commandIDs);
42
+ let readableSuggestion = (0, core_1.toConfiguredId)(suggestion, this.config);
43
+ const originalCmd = (0, core_1.toConfiguredId)(opts.id, this.config);
44
+ this.warn(`${chalk_1.default.yellow(originalCmd)} is not a ${opts.config.bin} command.`);
45
+ let response = '';
46
+ try {
47
+ if (opts.id === 'help') {
48
+ readableSuggestion = '--help';
49
+ }
50
+ response = yield core_1.CliUx.ux.prompt(`Did you mean ${chalk_1.default.blueBright(readableSuggestion)}? [y/n]`, { timeout: 10000 });
51
+ }
52
+ catch (error) {
53
+ this.log('');
54
+ this.debug(error);
55
+ }
56
+ if (response === 'y') {
57
+ // this will split the original command from the suggested replacement, and gather the remaining args as varargs to help with situations like:
58
+ // confit set foo-bar -> confit:set:foo-bar -> config:set:foo-bar -> config:set foo-bar
59
+ let argv = ((_a = opts.argv) === null || _a === void 0 ? void 0 : _a.length) ? opts.argv : opts.id.split(':').slice(suggestion.split(':').length);
60
+ if (suggestion.startsWith('help:')) {
61
+ // the args are the command/partial command you need help for (package:version)
62
+ // we created the suggestion variable to start with "help" so slice the first entry
63
+ argv = suggestion.split(':').slice(1);
64
+ // the command is just the word "help"
65
+ suggestion = 'help';
66
+ }
67
+ if (opts.id === 'help') {
68
+ return this.config.runCommand('--help');
69
+ }
70
+ return this.config.runCommand(suggestion, argv);
71
+ }
72
+ this.error(`Run ${chalk_1.default.bold.cyan(binHelp)} for a list of available commands.`, { exit: 127 });
73
+ });
74
+ };
75
+ exports.default = hook;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.58.10",
2
+ "version": "0.58.12",
3
3
  "commands": {
4
4
  "bundle": {
5
5
  "id": "bundle",
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.58.10",
4
+ "version": "0.58.12",
5
5
  "author": "@asyncapi",
6
6
  "bin": {
7
7
  "asyncapi": "./bin/run"
@@ -14,7 +14,7 @@
14
14
  "@asyncapi/diff": "^0.4.1",
15
15
  "@asyncapi/generator": "^1.13.1",
16
16
  "@asyncapi/modelina": "^1.9.1",
17
- "@asyncapi/openapi-schema-parser": "^3.0.3",
17
+ "@asyncapi/openapi-schema-parser": "^3.0.5",
18
18
  "@asyncapi/optimizer": "^0.2.1",
19
19
  "@asyncapi/parser": "^3.0.0-next-major-spec.2",
20
20
  "@asyncapi/protobuf-schema-parser": "3.0.0",
@@ -28,6 +28,7 @@
28
28
  "ajv": "^8.12.0",
29
29
  "chalk": "^4.1.0",
30
30
  "chokidar": "^3.5.2",
31
+ "fast-levenshtein": "^3.0.0",
31
32
  "fs-extra": "^11.1.0",
32
33
  "indent-string": "^4.0.0",
33
34
  "inquirer": "^8.2.0",
@@ -50,6 +51,7 @@
50
51
  "@oclif/test": "^2",
51
52
  "@swc/core": "^1.3.2",
52
53
  "@types/chai": "^4.3.6",
54
+ "@types/fast-levenshtein": "^0.0.2",
53
55
  "@types/fs-extra": "^11.0.1",
54
56
  "@types/inquirer": "^8.1.3",
55
57
  "@types/js-yaml": "^4.0.5",
@@ -104,9 +106,12 @@
104
106
  "oclif": {
105
107
  "commands": "./lib/commands",
106
108
  "bin": "asyncapi",
107
- "plugins": [
108
- "@oclif/plugin-not-found"
109
- ],
109
+ "plugins": [],
110
+ "hooks": {
111
+ "command_not_found": [
112
+ "./lib/hooks/command_not_found/myhook"
113
+ ]
114
+ },
110
115
  "macos": {
111
116
  "identifier": "com.asyncapi.cli"
112
117
  },
@@ -152,7 +157,9 @@
152
157
  "release": "semantic-release",
153
158
  "test": "npm run test:unit",
154
159
  "test:unit": "cross-env NODE_ENV=development TEST=1 CUSTOM_CONTEXT_FILENAME=\"test.asyncapi-cli\" CUSTOM_CONTEXT_FILE_LOCATION=\"\" nyc --extension .ts mocha --require ts-node/register --require test/helpers/init.js --reporter spec --timeout 100000 \"test/**/*.test.ts\"",
155
- "get-version": "echo $npm_package_version"
160
+ "get-version": "echo $npm_package_version",
161
+ "createhook": "oclif generate hook myhook --event=command_not_found",
162
+ "createhookinit": "oclif generate hook inithook --event=init"
156
163
  },
157
164
  "types": "lib/index.d.ts"
158
165
  }