bob-core 0.1.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/README.md +5 -0
- package/dist/Cli.d.ts +12 -0
- package/dist/Cli.js +31 -0
- package/dist/Command.d.ts +14 -0
- package/dist/Command.js +29 -0
- package/dist/CommandHelper.d.ts +3 -0
- package/dist/CommandHelper.js +43 -0
- package/dist/CommandRegistry.d.ts +12 -0
- package/dist/CommandRegistry.js +96 -0
- package/dist/Parser.d.ts +23 -0
- package/dist/Parser.js +98 -0
- package/dist/commands/HelpCommand.d.ts +9 -0
- package/dist/commands/HelpCommand.js +54 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/lib/string.d.ts +1 -0
- package/dist/lib/string.js +7 -0
- package/package.json +28 -0
package/README.md
ADDED
package/dist/Cli.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CommandRegistry } from "./CommandRegistry";
|
|
2
|
+
import { Command } from "./Command";
|
|
3
|
+
import HelpCommand from "./commands/HelpCommand";
|
|
4
|
+
export declare class Cli {
|
|
5
|
+
readonly commandRegistry: CommandRegistry;
|
|
6
|
+
get CommandRegistryClass(): typeof CommandRegistry;
|
|
7
|
+
get HelpCommandClass(): typeof HelpCommand;
|
|
8
|
+
constructor();
|
|
9
|
+
loadCommandsPath(commandsPath: string): Promise<void>;
|
|
10
|
+
registerCommand(command: Command): void;
|
|
11
|
+
runCommand(command: string, ...args: any[]): Promise<void>;
|
|
12
|
+
}
|
package/dist/Cli.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Cli = void 0;
|
|
7
|
+
const CommandRegistry_1 = require("./CommandRegistry");
|
|
8
|
+
const HelpCommand_1 = __importDefault(require("./commands/HelpCommand"));
|
|
9
|
+
class Cli {
|
|
10
|
+
commandRegistry;
|
|
11
|
+
get CommandRegistryClass() {
|
|
12
|
+
return CommandRegistry_1.CommandRegistry;
|
|
13
|
+
}
|
|
14
|
+
get HelpCommandClass() {
|
|
15
|
+
return HelpCommand_1.default;
|
|
16
|
+
}
|
|
17
|
+
constructor() {
|
|
18
|
+
this.commandRegistry = new this.CommandRegistryClass();
|
|
19
|
+
this.registerCommand(new this.HelpCommandClass(this.commandRegistry));
|
|
20
|
+
}
|
|
21
|
+
async loadCommandsPath(commandsPath) {
|
|
22
|
+
await this.commandRegistry.loadCommandsPath(commandsPath);
|
|
23
|
+
}
|
|
24
|
+
registerCommand(command) {
|
|
25
|
+
this.commandRegistry.registerCommand(command);
|
|
26
|
+
}
|
|
27
|
+
async runCommand(command, ...args) {
|
|
28
|
+
await this.commandRegistry.runCommand(command, ...args);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Cli = Cli;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CommandHelper } from "./CommandHelper";
|
|
2
|
+
export declare abstract class Command extends CommandHelper {
|
|
3
|
+
abstract signature: string;
|
|
4
|
+
abstract description: string;
|
|
5
|
+
private parser;
|
|
6
|
+
get command(): string;
|
|
7
|
+
protected abstract handle(): Promise<void | number>;
|
|
8
|
+
run(...args: any[]): Promise<number>;
|
|
9
|
+
protected option(key: string, defaultValue?: any): string | null;
|
|
10
|
+
protected argument(key: string, defaultValue?: any): string | null;
|
|
11
|
+
signatures(): {
|
|
12
|
+
[argument: string]: import("./Parser").ParamSignature;
|
|
13
|
+
};
|
|
14
|
+
}
|
package/dist/Command.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Command = void 0;
|
|
4
|
+
const CommandHelper_1 = require("./CommandHelper");
|
|
5
|
+
const Parser_1 = require("./Parser");
|
|
6
|
+
class Command extends CommandHelper_1.CommandHelper {
|
|
7
|
+
parser;
|
|
8
|
+
get command() {
|
|
9
|
+
return this.signature.split(' ')[0];
|
|
10
|
+
}
|
|
11
|
+
async run(...args) {
|
|
12
|
+
this.parser = new Parser_1.Parser(this.signature, ...args);
|
|
13
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
14
|
+
return this.help();
|
|
15
|
+
}
|
|
16
|
+
this.parser.validate();
|
|
17
|
+
return await this.handle() ?? 0;
|
|
18
|
+
}
|
|
19
|
+
option(key, defaultValue = null) {
|
|
20
|
+
return this.parser.option(key) ?? defaultValue;
|
|
21
|
+
}
|
|
22
|
+
argument(key, defaultValue) {
|
|
23
|
+
return this.parser.argument(key) ?? defaultValue;
|
|
24
|
+
}
|
|
25
|
+
signatures() {
|
|
26
|
+
return this.parser.signatures();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.Command = Command;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CommandHelper = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const string_1 = require("./lib/string");
|
|
10
|
+
class CommandHelper {
|
|
11
|
+
help() {
|
|
12
|
+
const command = this;
|
|
13
|
+
const log = console.log;
|
|
14
|
+
const signatures = command.signatures();
|
|
15
|
+
const availableArguments = Object.entries(signatures).filter(([_, signature]) => !signature.isOption);
|
|
16
|
+
const availableOptions = Object.entries(signatures).filter(([_, signature]) => signature.isOption);
|
|
17
|
+
const requiredArguments = availableArguments.filter(([_, signature]) => !signature.optional);
|
|
18
|
+
log((0, chalk_1.default) `{yellow Description}:`);
|
|
19
|
+
log((0, chalk_1.default) ` ${command.description}\n`);
|
|
20
|
+
log((0, chalk_1.default) `{yellow Usage}:`);
|
|
21
|
+
log((0, chalk_1.default) ` ${command.command} ${requiredArguments.length > 0 ? requiredArguments.map(([arg]) => `<${arg}>`).join(' ') : '\b'} [options]`);
|
|
22
|
+
const maxOptionLength = (0, lodash_1.max)(availableOptions.map(([option]) => option.length)) ?? 0;
|
|
23
|
+
const maxArgumentLength = (0, lodash_1.max)(availableArguments.map(([arg]) => arg.length)) ?? 0;
|
|
24
|
+
const maxLength = maxArgumentLength > maxOptionLength ? maxArgumentLength : maxOptionLength;
|
|
25
|
+
if (availableArguments.length > 0) {
|
|
26
|
+
log((0, chalk_1.default) `{yellow Arguments}:`);
|
|
27
|
+
for (const [argument, signature] of availableArguments) {
|
|
28
|
+
const spaces = (0, string_1.generateSpace)(maxLength - argument.length);
|
|
29
|
+
log((0, chalk_1.default) ` {green ${argument}} ${spaces} ${signature.help ?? '\b'} ${signature.optional ? (0, chalk_1.default) `{gray (optional)}` : ''}`);
|
|
30
|
+
}
|
|
31
|
+
log((0, chalk_1.default) ``);
|
|
32
|
+
}
|
|
33
|
+
if (availableOptions.length > 0) {
|
|
34
|
+
log((0, chalk_1.default) `{yellow Options}:`);
|
|
35
|
+
for (const [option, signature] of availableOptions) {
|
|
36
|
+
const spaces = (0, string_1.generateSpace)(maxLength - option.length);
|
|
37
|
+
log((0, chalk_1.default) ` {green ${option}} ${spaces} ${signature.help ?? '\b'} `);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return -1;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.CommandHelper = CommandHelper;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from "./Command";
|
|
2
|
+
export declare class CommandRegistry {
|
|
3
|
+
private readonly commands;
|
|
4
|
+
get commandSuffix(): string;
|
|
5
|
+
constructor();
|
|
6
|
+
getAvailableCommands(): string[];
|
|
7
|
+
getCommands(): Command[];
|
|
8
|
+
registerCommand(command: Command, force?: boolean): void;
|
|
9
|
+
loadCommandsPath(commandsPath: string): Promise<void>;
|
|
10
|
+
runCommand(command: string, ...args: any[]): Promise<number>;
|
|
11
|
+
private listCommandsFiles;
|
|
12
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.CommandRegistry = void 0;
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const fs = __importStar(require("node:fs"));
|
|
32
|
+
class CommandRegistry {
|
|
33
|
+
commands = {};
|
|
34
|
+
get commandSuffix() {
|
|
35
|
+
return "Command.ts";
|
|
36
|
+
}
|
|
37
|
+
constructor() { }
|
|
38
|
+
getAvailableCommands() {
|
|
39
|
+
return Object.keys(this.commands);
|
|
40
|
+
}
|
|
41
|
+
getCommands() {
|
|
42
|
+
return Object.values(this.commands);
|
|
43
|
+
}
|
|
44
|
+
registerCommand(command, force = false) {
|
|
45
|
+
const commandName = command.signature.split(' ')[0];
|
|
46
|
+
if (!commandName) {
|
|
47
|
+
throw new Error('Command signature is invalid, it must have a command name.');
|
|
48
|
+
}
|
|
49
|
+
if (!force && this.commands[commandName]) {
|
|
50
|
+
throw new Error(`Command ${commandName} already registered.`);
|
|
51
|
+
}
|
|
52
|
+
this.commands[commandName] = command;
|
|
53
|
+
}
|
|
54
|
+
async loadCommandsPath(commandsPath) {
|
|
55
|
+
for await (const file of this.listCommandsFiles(commandsPath)) {
|
|
56
|
+
let CommandClass;
|
|
57
|
+
try {
|
|
58
|
+
CommandClass = (await require(file)).default;
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
// Ignore files that are not commands
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const command = new CommandClass();
|
|
66
|
+
this.registerCommand(command);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
throw new Error(`Command ${file} failed to launch.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async runCommand(command, ...args) {
|
|
74
|
+
const commandToRun = this.commands[command];
|
|
75
|
+
if (!this.commands[command]) {
|
|
76
|
+
throw new Error(`Command ${command} not found.`);
|
|
77
|
+
}
|
|
78
|
+
return await commandToRun.run(...args);
|
|
79
|
+
}
|
|
80
|
+
async *listCommandsFiles(basePath) {
|
|
81
|
+
const dirEntry = fs.readdirSync(basePath, { withFileTypes: true });
|
|
82
|
+
for (const dirent of dirEntry) {
|
|
83
|
+
const direntPath = path_1.default.resolve(basePath, dirent.name);
|
|
84
|
+
if (dirent.isDirectory()) {
|
|
85
|
+
yield* this.listCommandsFiles(path_1.default.resolve(basePath, dirent.name));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (!direntPath.endsWith(this.commandSuffix)) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
yield direntPath;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.CommandRegistry = CommandRegistry;
|
package/dist/Parser.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ParamSignature = {
|
|
2
|
+
name: string;
|
|
3
|
+
optional: boolean;
|
|
4
|
+
alias?: string;
|
|
5
|
+
help?: string;
|
|
6
|
+
defaultValue?: string | boolean | null;
|
|
7
|
+
isOption: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare class Parser {
|
|
10
|
+
command: string;
|
|
11
|
+
private arguments;
|
|
12
|
+
private options;
|
|
13
|
+
private argumentsSignature;
|
|
14
|
+
option(name: string): any;
|
|
15
|
+
argument(name: string): any;
|
|
16
|
+
signatures(): {
|
|
17
|
+
[argument: string]: ParamSignature;
|
|
18
|
+
};
|
|
19
|
+
constructor(signature: string, ...args: any[]);
|
|
20
|
+
private parseSignature;
|
|
21
|
+
private parseParamSignature;
|
|
22
|
+
validate(): void;
|
|
23
|
+
}
|
package/dist/Parser.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Parser = void 0;
|
|
7
|
+
const minimist_1 = __importDefault(require("minimist"));
|
|
8
|
+
class Parser {
|
|
9
|
+
command;
|
|
10
|
+
arguments = {};
|
|
11
|
+
options = {};
|
|
12
|
+
argumentsSignature = {};
|
|
13
|
+
option(name) {
|
|
14
|
+
return this.options[name];
|
|
15
|
+
}
|
|
16
|
+
argument(name) {
|
|
17
|
+
return this.arguments[name];
|
|
18
|
+
}
|
|
19
|
+
signatures() {
|
|
20
|
+
return this.argumentsSignature;
|
|
21
|
+
}
|
|
22
|
+
constructor(signature, ...args) {
|
|
23
|
+
const [command, ...params] = signature.split(/\{(.*?)\}/g).map(param => param.trim()).filter(Boolean);
|
|
24
|
+
const { _: paramValues, ...optionValues } = (0, minimist_1.default)(args);
|
|
25
|
+
this.command = command;
|
|
26
|
+
this.parseSignature(params, optionValues, paramValues);
|
|
27
|
+
}
|
|
28
|
+
parseSignature(params, optionValues, paramValues) {
|
|
29
|
+
for (const paramSignature of params) {
|
|
30
|
+
const param = this.parseParamSignature(paramSignature);
|
|
31
|
+
if (param.isOption) {
|
|
32
|
+
const optionValue = optionValues[param.name];
|
|
33
|
+
this.options[param.name] = optionValue ?? param.defaultValue ?? null;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const paramValue = paramValues.shift();
|
|
37
|
+
this.arguments[param.name] = paramValue ?? param.defaultValue ?? null;
|
|
38
|
+
}
|
|
39
|
+
this.argumentsSignature[param.name] = param;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
parseParamSignature(argument) {
|
|
43
|
+
let cleanedArgs = argument;
|
|
44
|
+
let isOptional = false;
|
|
45
|
+
if (argument.endsWith('?')) {
|
|
46
|
+
cleanedArgs = cleanedArgs.slice(0, -1);
|
|
47
|
+
isOptional = true;
|
|
48
|
+
}
|
|
49
|
+
const arg = {
|
|
50
|
+
name: cleanedArgs,
|
|
51
|
+
optional: isOptional,
|
|
52
|
+
help: undefined,
|
|
53
|
+
defaultValue: null,
|
|
54
|
+
isOption: false
|
|
55
|
+
};
|
|
56
|
+
if (arg.name.includes(':')) {
|
|
57
|
+
const [name, help] = arg.name.split(':');
|
|
58
|
+
arg.name = name.trim();
|
|
59
|
+
arg.help = help.trim();
|
|
60
|
+
}
|
|
61
|
+
if (arg.name.includes('=')) {
|
|
62
|
+
const [name, defaultValue] = arg.name.split('=');
|
|
63
|
+
arg.name = name.trim();
|
|
64
|
+
arg.defaultValue = defaultValue.trim();
|
|
65
|
+
arg.optional = true;
|
|
66
|
+
if (!arg.defaultValue.length) {
|
|
67
|
+
arg.defaultValue = null;
|
|
68
|
+
}
|
|
69
|
+
else if (arg.defaultValue === 'true') {
|
|
70
|
+
arg.defaultValue = true;
|
|
71
|
+
}
|
|
72
|
+
else if (arg.defaultValue === 'false') {
|
|
73
|
+
arg.defaultValue = false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if (arg.name.startsWith('--')) {
|
|
78
|
+
arg.defaultValue = false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (arg.name.startsWith('--')) {
|
|
82
|
+
arg.isOption = true;
|
|
83
|
+
arg.name = arg.name.slice(2);
|
|
84
|
+
}
|
|
85
|
+
return arg;
|
|
86
|
+
}
|
|
87
|
+
validate() {
|
|
88
|
+
// validate arguments
|
|
89
|
+
for (const [argument, value] of Object.entries(this.arguments)) {
|
|
90
|
+
const signature = this.argumentsSignature[argument];
|
|
91
|
+
if (!value && !signature.optional) {
|
|
92
|
+
const argumentHelp = signature.help ?? 'no help available';
|
|
93
|
+
throw new Error(`Argument ${argument} is required. (help: ${argumentHelp})`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.Parser = Parser;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "../Command";
|
|
2
|
+
import { CommandRegistry } from "../CommandRegistry";
|
|
3
|
+
export default class HelpCommand extends Command {
|
|
4
|
+
private commandRegistry;
|
|
5
|
+
signature: string;
|
|
6
|
+
description: string;
|
|
7
|
+
constructor(commandRegistry: CommandRegistry);
|
|
8
|
+
protected handle(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Command_1 = require("../Command");
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const string_1 = require("../lib/string");
|
|
10
|
+
class HelpCommand extends Command_1.Command {
|
|
11
|
+
commandRegistry;
|
|
12
|
+
signature = 'help';
|
|
13
|
+
description = 'Show help';
|
|
14
|
+
constructor(commandRegistry) {
|
|
15
|
+
super();
|
|
16
|
+
this.commandRegistry = commandRegistry;
|
|
17
|
+
}
|
|
18
|
+
async handle() {
|
|
19
|
+
const commands = this.commandRegistry.getCommands();
|
|
20
|
+
const version = require('../../package.json').version;
|
|
21
|
+
console.log((0, chalk_1.default) `Bob CLI {green ${version}} 💪
|
|
22
|
+
|
|
23
|
+
{yellow Usage}:
|
|
24
|
+
command [options] [arguments]
|
|
25
|
+
|
|
26
|
+
{yellow Available commands}:
|
|
27
|
+
`);
|
|
28
|
+
const maxCommandLength = (0, lodash_1.max)(commands.map(command => command.command.length)) ?? 0;
|
|
29
|
+
const commandByGroups = {};
|
|
30
|
+
for (const command of commands) {
|
|
31
|
+
const commandGroup = command.command.split(':')[0];
|
|
32
|
+
if (!commandByGroups[commandGroup]) {
|
|
33
|
+
commandByGroups[commandGroup] = [];
|
|
34
|
+
}
|
|
35
|
+
commandByGroups[commandGroup].push(command);
|
|
36
|
+
}
|
|
37
|
+
const sortedCommandsByGroups = (0, lodash_1.orderBy)((0, lodash_1.orderBy)(Object.entries(commandByGroups), [([group]) => group.toLowerCase()], ['asc']), [([_, commands]) => commands.length], ['asc']);
|
|
38
|
+
for (const [group, groupCommands] of sortedCommandsByGroups) {
|
|
39
|
+
const isGrouped = groupCommands.length > 1;
|
|
40
|
+
if (isGrouped) {
|
|
41
|
+
console.log((0, chalk_1.default) `{yellow ${group}}:`);
|
|
42
|
+
}
|
|
43
|
+
const sortedGroupCommands = (0, lodash_1.orderBy)(groupCommands, [command => command.command.toLowerCase()], ['asc']);
|
|
44
|
+
for (const command of sortedGroupCommands) {
|
|
45
|
+
let spaces = (0, string_1.generateSpace)(maxCommandLength - command.command.length);
|
|
46
|
+
if (isGrouped) {
|
|
47
|
+
spaces = spaces.slice(2);
|
|
48
|
+
}
|
|
49
|
+
console.log((0, chalk_1.default) `${isGrouped ? ' ' : ''}{green ${command.command}} ${spaces} ${command.description}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.default = HelpCommand;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Command"), exports);
|
|
18
|
+
__exportStar(require("./Cli"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateSpace(nb: number): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bob-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "BOB Core",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "ts-node ./tests/main.ts",
|
|
12
|
+
"build": "tsc"
|
|
13
|
+
},
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/lodash": "^4.17.5",
|
|
18
|
+
"@types/minimist": "^1.2.5",
|
|
19
|
+
"@types/node": "^20.14.5",
|
|
20
|
+
"ts-node": "^10.9.2",
|
|
21
|
+
"typescript": "^5.4.5"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"chalk": "^4.1.2",
|
|
25
|
+
"lodash": "^4.17.21",
|
|
26
|
+
"minimist": "^1.2.8"
|
|
27
|
+
}
|
|
28
|
+
}
|