@clerc/plugin-not-found 0.44.0 → 1.0.0-beta.10
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.d.ts +5 -4
- package/dist/index.js +29 -72
- package/package.json +10 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Plugin } from "@clerc/core";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare const notFoundPlugin: () => Plugin;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { notFoundPlugin };
|
package/dist/index.js
CHANGED
|
@@ -1,74 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as yc from 'yoctocolors';
|
|
1
|
+
import { NoCommandSpecifiedError, NoSuchCommandError, definePlugin } from "@clerc/core";
|
|
2
|
+
import didyoumean from "didyoumean2";
|
|
3
|
+
import * as yc from "yoctocolors";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
const notFoundPlugin = () => definePlugin({ setup: (cli) => cli.interceptor({
|
|
7
|
+
enforce: "post",
|
|
8
|
+
handler: async (_ctx, next) => {
|
|
9
|
+
const commandKeys = [...cli._commands.keys()];
|
|
10
|
+
const hasCommands = commandKeys.length > 0;
|
|
11
|
+
try {
|
|
12
|
+
await next();
|
|
13
|
+
} catch (e) {
|
|
14
|
+
if (!(e instanceof NoSuchCommandError || e instanceof NoCommandSpecifiedError)) throw e;
|
|
15
|
+
if (e instanceof NoCommandSpecifiedError) {
|
|
16
|
+
let text$1 = "No command specified.";
|
|
17
|
+
if (hasCommands) text$1 += `\nPossible commands: ${commandKeys.join(", ")}.`;
|
|
18
|
+
throw new NoCommandSpecifiedError(text$1);
|
|
19
|
+
}
|
|
20
|
+
const { commandName } = e;
|
|
21
|
+
const closestCommandName = didyoumean(commandName, commandKeys);
|
|
22
|
+
let text = `Command "${yc.strikethrough(commandName)}" not found.`;
|
|
23
|
+
if (hasCommands && closestCommandName) text += `\nDid you mean "${yc.bold(closestCommandName)}"?`;
|
|
24
|
+
else if (!hasCommands) text += "\nNo commands registered.";
|
|
25
|
+
throw new NoSuchCommandError(commandName, text);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}) });
|
|
20
29
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const { t, add } = cli.i18n;
|
|
24
|
-
add(locales);
|
|
25
|
-
return cli.interceptor({
|
|
26
|
-
enforce: "pre",
|
|
27
|
-
fn: (ctx, next) => {
|
|
28
|
-
const commandKeys = Object.keys(cli._commands);
|
|
29
|
-
const hasCommands = commandKeys.length > 0;
|
|
30
|
-
try {
|
|
31
|
-
next();
|
|
32
|
-
} catch (e) {
|
|
33
|
-
if (!(e instanceof NoSuchCommandError || e instanceof NoCommandGivenError)) {
|
|
34
|
-
throw e;
|
|
35
|
-
}
|
|
36
|
-
if (ctx.raw._.length === 0 || e instanceof NoCommandGivenError) {
|
|
37
|
-
console.error(t("core.noCommandGiven"));
|
|
38
|
-
if (hasCommands) {
|
|
39
|
-
console.error(
|
|
40
|
-
t(
|
|
41
|
-
"notFound.possibleCommands",
|
|
42
|
-
semanticArray(commandKeys, cli.i18n)
|
|
43
|
-
)
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const calledCommandName = e.commandName;
|
|
49
|
-
const closestCommandName = didyoumean(
|
|
50
|
-
calledCommandName,
|
|
51
|
-
commandKeys
|
|
52
|
-
);
|
|
53
|
-
console.error(
|
|
54
|
-
t(
|
|
55
|
-
"notFound.commandNotFound",
|
|
56
|
-
yc.strikethrough(calledCommandName)
|
|
57
|
-
)
|
|
58
|
-
);
|
|
59
|
-
if (hasCommands && closestCommandName) {
|
|
60
|
-
console.error(
|
|
61
|
-
t("notFound.didyoumean", yc.bold(closestCommandName))
|
|
62
|
-
);
|
|
63
|
-
} else if (!hasCommands) {
|
|
64
|
-
console.error(t("notFound.commandNotRegisteredNote"));
|
|
65
|
-
}
|
|
66
|
-
process.stderr.write("\n");
|
|
67
|
-
process.exit(2);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
export { notFoundPlugin };
|
|
30
|
+
//#endregion
|
|
31
|
+
export { notFoundPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-not-found",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.10",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc plugin not found (did you mean)",
|
|
@@ -25,13 +25,10 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"exports": {
|
|
28
|
-
".":
|
|
29
|
-
"types": "./dist/index.d.ts",
|
|
30
|
-
"import": "./dist/index.js"
|
|
31
|
-
}
|
|
28
|
+
".": "./dist/index.js"
|
|
32
29
|
},
|
|
33
|
-
"main": "dist/index.js",
|
|
34
|
-
"module": "dist/index.js",
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"module": "./dist/index.js",
|
|
35
32
|
"types": "dist/index.d.ts",
|
|
36
33
|
"typesVersions": {
|
|
37
34
|
"*": {
|
|
@@ -48,15 +45,14 @@
|
|
|
48
45
|
"access": "public"
|
|
49
46
|
},
|
|
50
47
|
"dependencies": {
|
|
51
|
-
"didyoumean2": "^
|
|
52
|
-
"yoctocolors": "^1.
|
|
53
|
-
|
|
48
|
+
"didyoumean2": "^7.0.4",
|
|
49
|
+
"yoctocolors": "^2.1.2"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@clerc/core": "1.0.0-beta.10",
|
|
53
|
+
"@clerc/utils": "1.0.0-beta.10"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@clerc/core": "*"
|
|
57
|
-
},
|
|
58
|
-
"scripts": {
|
|
59
|
-
"build": "pkgroll",
|
|
60
|
-
"watch": "pkgroll --watch"
|
|
61
57
|
}
|
|
62
58
|
}
|