@clerc/plugin-not-found 0.10.3 → 0.10.5
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/dist/index.js +40 -0
- package/dist/index.mjs +28 -16
- package/package.json +14 -6
- package/dist/index.cjs +0 -36
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { definePlugin, NoSuchCommandError } from '@clerc/core';
|
|
2
|
+
import { semanticArray } from '@clerc/utils';
|
|
3
|
+
import { closest } from 'fastest-levenshtein';
|
|
4
|
+
import pc from 'picocolors';
|
|
5
|
+
|
|
6
|
+
const notFoundPlugin = () => definePlugin({
|
|
7
|
+
setup: (cli) => {
|
|
8
|
+
return cli.inspector({
|
|
9
|
+
enforce: "post",
|
|
10
|
+
fn: (ctx, next) => {
|
|
11
|
+
const commandKeys = Object.keys(cli._commands);
|
|
12
|
+
const hasCommands = !!commandKeys.length;
|
|
13
|
+
try {
|
|
14
|
+
next();
|
|
15
|
+
} catch (e) {
|
|
16
|
+
if (!(e instanceof NoSuchCommandError)) {
|
|
17
|
+
throw e;
|
|
18
|
+
}
|
|
19
|
+
if (ctx.raw._.length === 0) {
|
|
20
|
+
console.log("No command given.");
|
|
21
|
+
if (hasCommands) {
|
|
22
|
+
console.log(`Possible commands: ${pc.bold(semanticArray(commandKeys))}.`);
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const calledCommandName = e.message.replace("No such command: ", "");
|
|
27
|
+
const closestCommandName = closest(calledCommandName, commandKeys);
|
|
28
|
+
console.log(`Command "${pc.strikethrough(calledCommandName)}" not found.`);
|
|
29
|
+
if (hasCommands) {
|
|
30
|
+
console.log(`Did you mean "${pc.bold(closestCommandName)}"?`);
|
|
31
|
+
} else {
|
|
32
|
+
console.log("NOTE: You haven't register any command yet.");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export { notFoundPlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
import { definePlugin, NoSuchCommandError } from '@clerc/core';
|
|
2
|
+
import { semanticArray } from '@clerc/utils';
|
|
2
3
|
import { closest } from 'fastest-levenshtein';
|
|
3
4
|
import pc from 'picocolors';
|
|
4
5
|
|
|
5
6
|
const notFoundPlugin = () => definePlugin({
|
|
6
|
-
setup(cli) {
|
|
7
|
-
return cli.inspector(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
setup: (cli) => {
|
|
8
|
+
return cli.inspector({
|
|
9
|
+
enforce: "post",
|
|
10
|
+
fn: (ctx, next) => {
|
|
11
|
+
const commandKeys = Object.keys(cli._commands);
|
|
12
|
+
const hasCommands = !!commandKeys.length;
|
|
13
|
+
try {
|
|
14
|
+
next();
|
|
15
|
+
} catch (e) {
|
|
16
|
+
if (!(e instanceof NoSuchCommandError)) {
|
|
17
|
+
throw e;
|
|
18
|
+
}
|
|
19
|
+
if (ctx.raw._.length === 0) {
|
|
20
|
+
console.log("No command given.");
|
|
21
|
+
if (hasCommands) {
|
|
22
|
+
console.log(`Possible commands: ${pc.bold(semanticArray(commandKeys))}.`);
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const calledCommandName = e.message.replace("No such command: ", "");
|
|
27
|
+
const closestCommandName = closest(calledCommandName, commandKeys);
|
|
28
|
+
console.log(`Command "${pc.strikethrough(calledCommandName)}" not found.`);
|
|
29
|
+
if (hasCommands) {
|
|
30
|
+
console.log(`Did you mean "${pc.bold(closestCommandName)}"?`);
|
|
31
|
+
} else {
|
|
32
|
+
console.log("NOTE: You haven't register any command yet.");
|
|
33
|
+
}
|
|
13
34
|
}
|
|
14
|
-
if (ctx.raw._.length === 0) {
|
|
15
|
-
console.log("No command given.");
|
|
16
|
-
console.log(`Possible commands: ${pc.bold(Object.keys(cli._commands).join(", "))}.`);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const calledCommandName = e.message.replace("No such command: ", "");
|
|
20
|
-
const closestCommandName = closest(calledCommandName, Object.keys(cli._commands));
|
|
21
|
-
console.log(`Command "${pc.strikethrough(calledCommandName)}" not found.`);
|
|
22
|
-
console.log(`Did you mean "${pc.bold(closestCommandName)}"?`);
|
|
23
35
|
}
|
|
24
36
|
});
|
|
25
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-not-found",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.5",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc plugin not found (did you mean)",
|
|
6
6
|
"keywords": [
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"args",
|
|
13
13
|
"terminal"
|
|
14
14
|
],
|
|
15
|
+
"type": "module",
|
|
15
16
|
"homepage": "https://github.com/so1ve/clerc/tree/main/packages/plugin-not-found#readme",
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
|
@@ -26,13 +27,20 @@
|
|
|
26
27
|
"exports": {
|
|
27
28
|
".": {
|
|
28
29
|
"types": "./dist/index.d.ts",
|
|
29
|
-
"require": "./dist/index.cjs",
|
|
30
30
|
"import": "./dist/index.mjs"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
"main": "dist/index.
|
|
33
|
+
"main": "dist/index.js",
|
|
34
34
|
"module": "dist/index.mjs",
|
|
35
35
|
"types": "dist/index.d.ts",
|
|
36
|
+
"typesVersions": {
|
|
37
|
+
"*": {
|
|
38
|
+
"*": [
|
|
39
|
+
"./dist/*",
|
|
40
|
+
"./dist/index.d.ts"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
36
44
|
"files": [
|
|
37
45
|
"dist"
|
|
38
46
|
],
|
|
@@ -43,12 +51,12 @@
|
|
|
43
51
|
"@clerc/core": "*"
|
|
44
52
|
},
|
|
45
53
|
"dependencies": {
|
|
54
|
+
"@clerc/utils": "0.10.5",
|
|
46
55
|
"fastest-levenshtein": "^1.0.16",
|
|
47
|
-
"picocolors": "^1.0.0"
|
|
48
|
-
"@clerc/utils": "0.10.3"
|
|
56
|
+
"picocolors": "^1.0.0"
|
|
49
57
|
},
|
|
50
58
|
"devDependencies": {
|
|
51
|
-
"@clerc/core": "0.10.
|
|
59
|
+
"@clerc/core": "0.10.5"
|
|
52
60
|
},
|
|
53
61
|
"scripts": {
|
|
54
62
|
"build": "puild",
|
package/dist/index.cjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var core = require('@clerc/core');
|
|
6
|
-
var fastestLevenshtein = require('fastest-levenshtein');
|
|
7
|
-
var pc = require('picocolors');
|
|
8
|
-
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
-
|
|
11
|
-
var pc__default = /*#__PURE__*/_interopDefaultLegacy(pc);
|
|
12
|
-
|
|
13
|
-
const notFoundPlugin = () => core.definePlugin({
|
|
14
|
-
setup(cli) {
|
|
15
|
-
return cli.inspector((ctx, next) => {
|
|
16
|
-
try {
|
|
17
|
-
next();
|
|
18
|
-
} catch (e) {
|
|
19
|
-
if (!(e instanceof core.NoSuchCommandError)) {
|
|
20
|
-
throw e;
|
|
21
|
-
}
|
|
22
|
-
if (ctx.raw._.length === 0) {
|
|
23
|
-
console.log("No command given.");
|
|
24
|
-
console.log(`Possible commands: ${pc__default["default"].bold(Object.keys(cli._commands).join(", "))}.`);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const calledCommandName = e.message.replace("No such command: ", "");
|
|
28
|
-
const closestCommandName = fastestLevenshtein.closest(calledCommandName, Object.keys(cli._commands));
|
|
29
|
-
console.log(`Command "${pc__default["default"].strikethrough(calledCommandName)}" not found.`);
|
|
30
|
-
console.log(`Did you mean "${pc__default["default"].bold(closestCommandName)}"?`);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
exports.notFoundPlugin = notFoundPlugin;
|