@clerc/plugin-not-found 0.20.0 → 0.22.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.
package/dist/index.js CHANGED
@@ -1,8 +1,13 @@
1
1
  import { definePlugin, NoSuchCommandError, NoCommandGivenError } from '@clerc/core';
2
- import { semanticArray } from '@clerc/utils';
3
2
  import didyoumean from 'didyoumean2';
4
3
  import pc from 'picocolors';
5
4
 
5
+ const semanticArray = (arr) => {
6
+ if (arr.length <= 1) {
7
+ return arr[0];
8
+ }
9
+ return `${arr.slice(0, -1).map(pc.bold).join(", ")} and ${pc.bold(arr[arr.length - 1])}`;
10
+ };
6
11
  const notFoundPlugin = () => definePlugin({
7
12
  setup: (cli) => {
8
13
  return cli.inspector({
@@ -16,14 +21,14 @@ const notFoundPlugin = () => definePlugin({
16
21
  if (!(e instanceof NoSuchCommandError || e instanceof NoCommandGivenError)) {
17
22
  throw e;
18
23
  }
19
- if (ctx.raw._.length === 0) {
24
+ if (ctx.raw._.length === 0 || e instanceof NoCommandGivenError) {
20
25
  console.error("No command given.");
21
26
  if (hasCommands) {
22
- console.error(`Possible commands: ${pc.bold(semanticArray(commandKeys))}.`);
27
+ console.error(`Possible commands: ${semanticArray(commandKeys)}.`);
23
28
  }
24
29
  return;
25
30
  }
26
- const calledCommandName = e.message.replace("No such command: ", "");
31
+ const calledCommandName = e.name;
27
32
  const closestCommandName = didyoumean(calledCommandName, commandKeys);
28
33
  console.error(`Command "${pc.strikethrough(calledCommandName)}" not found.`);
29
34
  if (hasCommands && closestCommandName) {
package/dist/index.mjs CHANGED
@@ -1,8 +1,13 @@
1
1
  import { definePlugin, NoSuchCommandError, NoCommandGivenError } from '@clerc/core';
2
- import { semanticArray } from '@clerc/utils';
3
2
  import didyoumean from 'didyoumean2';
4
3
  import pc from 'picocolors';
5
4
 
5
+ const semanticArray = (arr) => {
6
+ if (arr.length <= 1) {
7
+ return arr[0];
8
+ }
9
+ return `${arr.slice(0, -1).map(pc.bold).join(", ")} and ${pc.bold(arr[arr.length - 1])}`;
10
+ };
6
11
  const notFoundPlugin = () => definePlugin({
7
12
  setup: (cli) => {
8
13
  return cli.inspector({
@@ -16,14 +21,14 @@ const notFoundPlugin = () => definePlugin({
16
21
  if (!(e instanceof NoSuchCommandError || e instanceof NoCommandGivenError)) {
17
22
  throw e;
18
23
  }
19
- if (ctx.raw._.length === 0) {
24
+ if (ctx.raw._.length === 0 || e instanceof NoCommandGivenError) {
20
25
  console.error("No command given.");
21
26
  if (hasCommands) {
22
- console.error(`Possible commands: ${pc.bold(semanticArray(commandKeys))}.`);
27
+ console.error(`Possible commands: ${semanticArray(commandKeys)}.`);
23
28
  }
24
29
  return;
25
30
  }
26
- const calledCommandName = e.message.replace("No such command: ", "");
31
+ const calledCommandName = e.name;
27
32
  const closestCommandName = didyoumean(calledCommandName, commandKeys);
28
33
  console.error(`Command "${pc.strikethrough(calledCommandName)}" not found.`);
29
34
  if (hasCommands && closestCommandName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-not-found",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
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": [
@@ -53,10 +53,10 @@
53
53
  "dependencies": {
54
54
  "didyoumean2": "^5.0.0",
55
55
  "picocolors": "^1.0.0",
56
- "@clerc/utils": "0.20.0"
56
+ "@clerc/utils": "0.22.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@clerc/core": "0.20.0"
59
+ "@clerc/core": "0.22.0"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "puild",