bob-core 0.1.4 → 0.2.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/Cli.d.ts CHANGED
@@ -8,5 +8,5 @@ export declare class Cli {
8
8
  constructor();
9
9
  loadCommandsPath(commandsPath: string): Promise<void>;
10
10
  registerCommand(command: Command): void;
11
- runCommand(command: string, ...args: any[]): Promise<void>;
11
+ runCommand(command: string, ...args: any[]): Promise<number>;
12
12
  }
package/dist/Cli.js CHANGED
@@ -25,7 +25,7 @@ class Cli {
25
25
  this.commandRegistry.registerCommand(command);
26
26
  }
27
27
  async runCommand(command, ...args) {
28
- await this.commandRegistry.runCommand(command, ...args);
28
+ return await this.commandRegistry.runCommand(command, ...args);
29
29
  }
30
30
  }
31
31
  exports.Cli = Cli;
@@ -9,4 +9,5 @@ export declare class CommandRegistry {
9
9
  loadCommandsPath(commandsPath: string): Promise<void>;
10
10
  runCommand(command: string, ...args: any[]): Promise<number>;
11
11
  private listCommandsFiles;
12
+ private commandNotFound;
12
13
  }
@@ -29,6 +29,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.CommandRegistry = void 0;
30
30
  const path_1 = __importDefault(require("path"));
31
31
  const fs = __importStar(require("node:fs"));
32
+ const SS = __importStar(require("string-similarity"));
33
+ const chalk_1 = __importDefault(require("chalk"));
32
34
  class CommandRegistry {
33
35
  commands = {};
34
36
  get commandSuffix() {
@@ -73,7 +75,7 @@ class CommandRegistry {
73
75
  async runCommand(command, ...args) {
74
76
  const commandToRun = this.commands[command];
75
77
  if (!this.commands[command]) {
76
- throw new Error(`Command ${command} not found.`);
78
+ return this.commandNotFound(command);
77
79
  }
78
80
  return await commandToRun.run(...args);
79
81
  }
@@ -92,5 +94,21 @@ class CommandRegistry {
92
94
  }
93
95
  }
94
96
  }
97
+ commandNotFound(command) {
98
+ const log = console.log;
99
+ const similarCommands = this.getCommands().filter(cmd => cmd.command //
100
+ .split(':')
101
+ .filter(part => SS.compareTwoStrings(part, command) > 0.3).length);
102
+ if (similarCommands.length) {
103
+ log((0, chalk_1.default) ` {white.bgRed ERROR } Command "${command}" is not defined, Did you mean one of these?`);
104
+ for (const cmd of similarCommands) {
105
+ log((0, chalk_1.default) ` {gray ⇂ ${cmd.command}}`);
106
+ }
107
+ }
108
+ else {
109
+ log((0, chalk_1.default) ` {white.bgRed ERROR } Command "${command}" is not defined.`);
110
+ }
111
+ return 1;
112
+ }
95
113
  }
96
114
  exports.CommandRegistry = CommandRegistry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bob-core",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "BOB Core",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,11 +18,13 @@
18
18
  "@types/lodash": "^4.17.5",
19
19
  "@types/minimist": "^1.2.5",
20
20
  "@types/node": "^20.14.5",
21
+ "@types/string-similarity": "^4.0.2",
21
22
  "typescript": "^5.4.5"
22
23
  },
23
24
  "dependencies": {
24
25
  "chalk": "^4.1.2",
25
26
  "lodash": "^4.17.21",
26
- "minimist": "^1.2.8"
27
+ "minimist": "^1.2.8",
28
+ "string-similarity": "^4.0.4"
27
29
  }
28
30
  }