@clerc/plugin-not-found 0.43.0 → 1.0.0-beta.1

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 CHANGED
@@ -1,5 +1,6 @@
1
- import * as _clerc_core from '@clerc/core';
1
+ import { Plugin } from "@clerc/core";
2
2
 
3
- declare const notFoundPlugin: () => _clerc_core.Plugin<_clerc_core.Clerc<{}, {}>, _clerc_core.Clerc<{}, {}>>;
4
-
5
- export { notFoundPlugin };
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 { definePlugin, NoSuchCommandError, NoCommandGivenError } from '@clerc/core';
2
- import { semanticArray } from '@clerc/utils';
3
- import didyoumean from 'didyoumean2';
4
- import * as yc from 'yoctocolors';
1
+ import { NoCommandGivenError, NoSuchCommandError, definePlugin } from "@clerc/core";
2
+ import didyoumean from "didyoumean2";
3
+ import * as yc from "yoctocolors";
5
4
 
6
- const locales = {
7
- "en": {
8
- "notFound.possibleCommands": "Possible commands: %s.",
9
- "notFound.commandNotFound": 'Command "%s" not found.',
10
- "notFound.didyoumean": 'Did you mean "%s"?',
11
- "notFound.commandNotRegisteredNote": "NOTE: You haven't register any command yet."
12
- },
13
- "zh-CN": {
14
- "notFound.possibleCommands": "\u53EF\u80FD\u7684\u547D\u4EE4: %s\u3002",
15
- "notFound.commandNotFound": '\u672A\u627E\u5230\u547D\u4EE4 "%s"\u3002',
16
- "notFound.didyoumean": '\u4F60\u662F\u4E0D\u662F\u6307 "%s"\uFF1F',
17
- "notFound.commandNotRegisteredNote": "\u63D0\u793A: \u4F60\u8FD8\u6CA1\u6709\u6CE8\u518C\u4EFB\u4F55\u547D\u4EE4\u3002"
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 NoCommandGivenError)) throw e;
15
+ if (e instanceof NoCommandGivenError) {
16
+ console.error("No command specified.");
17
+ if (hasCommands) console.error(`Possible commands: ${commandKeys.join(", ")}`);
18
+ return;
19
+ }
20
+ const { commandName } = e;
21
+ const closestCommandName = didyoumean(commandName, commandKeys);
22
+ console.error(`Command "${yc.strikethrough(commandName)}" not found.`);
23
+ if (hasCommands && closestCommandName) console.error(`Did you mean "${yc.bold(closestCommandName)}"?`);
24
+ else if (!hasCommands) console.error("No commands registered.");
25
+ process.exit(2);
26
+ }
27
+ }
28
+ }) });
20
29
 
21
- const notFoundPlugin = () => definePlugin({
22
- setup: (cli) => {
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.43.0",
3
+ "version": "1.0.0-beta.1",
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,18 @@
48
45
  "access": "public"
49
46
  },
50
47
  "dependencies": {
51
- "didyoumean2": "^6.0.1",
52
- "yoctocolors": "^1.0.0",
53
- "@clerc/utils": "0.43.0"
48
+ "didyoumean2": "^7.0.4",
49
+ "yoctocolors": "^2.1.2",
50
+ "@clerc/utils": "1.0.0-beta.1"
51
+ },
52
+ "devDependencies": {
53
+ "@clerc/core": "1.0.0-beta.1"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@clerc/core": "*"
57
57
  },
58
58
  "scripts": {
59
- "build": "pkgroll",
60
- "watch": "pkgroll --watch"
59
+ "build": "tsdown",
60
+ "watch": "tsdown --watch"
61
61
  }
62
62
  }