@nu-art/commando 0.204.86 → 0.204.88
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/cli/basic.d.ts +3 -2
- package/cli/basic.js +15 -15
- package/cli/git.d.ts +18 -17
- package/cli/git.js +43 -22
- package/cli/nvm.d.ts +4 -3
- package/cli/nvm.js +13 -10
- package/cli/pnpm.d.ts +1 -1
- package/cli/pnpm.js +8 -8
- package/cli/programming.d.ts +3 -2
- package/cli/programming.js +19 -19
- package/cli-params/CLIParamsResolver.d.ts +27 -0
- package/{cli/cli-params.js → cli-params/CLIParamsResolver.js} +6 -34
- package/cli-params/consts.d.ts +6 -0
- package/cli-params/consts.js +32 -0
- package/cli-params/types.d.ts +27 -0
- package/cli-params/types.js +2 -0
- package/package.json +1 -1
- package/shell/core/BaseCommando.d.ts +54 -0
- package/shell/core/BaseCommando.js +73 -0
- package/shell/core/CliError.d.ts +15 -0
- package/shell/core/CliError.js +22 -0
- package/shell/core/CommandBuilder.d.ts +52 -0
- package/shell/core/CommandBuilder.js +78 -0
- package/shell/core/class-merger.d.ts +20 -0
- package/{core → shell/core}/class-merger.js +16 -0
- package/shell/index.d.ts +2 -0
- package/shell/index.js +18 -0
- package/shell/interactive/CommandoInteractive.d.ts +83 -0
- package/shell/interactive/CommandoInteractive.js +180 -0
- package/shell/interactive/InteractiveShell.d.ts +63 -0
- package/shell/interactive/InteractiveShell.js +139 -0
- package/shell/simple/Commando.d.ts +17 -0
- package/shell/simple/Commando.js +51 -0
- package/shell/simple/SimpleShell.d.ts +23 -0
- package/shell/simple/SimpleShell.js +48 -0
- package/shell/types.d.ts +3 -0
- package/shell/types.js +2 -0
- package/cli/cli-params.d.ts +0 -56
- package/core/CliError.d.ts +0 -6
- package/core/CliError.js +0 -12
- package/core/class-merger.d.ts +0 -5
- package/core/cli.d.ts +0 -147
- package/core/cli.js +0 -404
- package/test-scripts/test-params.d.ts +0 -1
- package/test-scripts/test-params.js +0 -43
- /package/{core → shell}/tools.d.ts +0 -0
- /package/{core → shell}/tools.js +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultProcessorsMapper = exports.DefaultProcessor_Number = exports.DefaultProcessor_String = exports.DefaultProcessor_Boolean = void 0;
|
|
4
|
+
const DefaultProcessor_Boolean = (input, defaultValue) => {
|
|
5
|
+
return true;
|
|
6
|
+
};
|
|
7
|
+
exports.DefaultProcessor_Boolean = DefaultProcessor_Boolean;
|
|
8
|
+
const DefaultProcessor_String = (input, defaultValue) => {
|
|
9
|
+
if (!input || !input.length) {
|
|
10
|
+
if (!defaultValue)
|
|
11
|
+
throw new Error('expected string value');
|
|
12
|
+
return defaultValue;
|
|
13
|
+
}
|
|
14
|
+
return input;
|
|
15
|
+
};
|
|
16
|
+
exports.DefaultProcessor_String = DefaultProcessor_String;
|
|
17
|
+
const DefaultProcessor_Number = (input, defaultValue) => {
|
|
18
|
+
if (!input) {
|
|
19
|
+
if (!defaultValue)
|
|
20
|
+
throw new Error('expected number value');
|
|
21
|
+
return defaultValue;
|
|
22
|
+
}
|
|
23
|
+
if (isNaN(Number(input)))
|
|
24
|
+
throw new Error('expected number value');
|
|
25
|
+
return Number(input);
|
|
26
|
+
};
|
|
27
|
+
exports.DefaultProcessor_Number = DefaultProcessor_Number;
|
|
28
|
+
exports.DefaultProcessorsMapper = {
|
|
29
|
+
string: exports.DefaultProcessor_String,
|
|
30
|
+
boolean: exports.DefaultProcessor_Boolean,
|
|
31
|
+
number: exports.DefaultProcessor_Number,
|
|
32
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Primitive, TypeOfTypeAsString } from '@nu-art/ts-common';
|
|
2
|
+
export type CliParams<T extends BaseCliParam<string, any>[]> = {
|
|
3
|
+
[K in T[number]['keyName']]: NonNullable<Extract<T[number], {
|
|
4
|
+
keyName: K;
|
|
5
|
+
}>['defaultValue']>;
|
|
6
|
+
};
|
|
7
|
+
export type DependencyParam<T extends Primitive | Primitive[]> = {
|
|
8
|
+
param: BaseCliParam<string, T>;
|
|
9
|
+
value: T;
|
|
10
|
+
};
|
|
11
|
+
export type BaseCliParam<K extends string, V extends Primitive | Primitive[]> = {
|
|
12
|
+
keys: string[];
|
|
13
|
+
keyName: K;
|
|
14
|
+
type: TypeOfTypeAsString<V>;
|
|
15
|
+
description: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
options?: string[];
|
|
18
|
+
defaultValue?: V;
|
|
19
|
+
process?: (value?: string, defaultValue?: V) => V;
|
|
20
|
+
isArray?: true;
|
|
21
|
+
group?: string;
|
|
22
|
+
dependencies?: DependencyParam<any>[];
|
|
23
|
+
};
|
|
24
|
+
export type CliParam<K extends string, V extends Primitive | Primitive[]> = BaseCliParam<K, V> & {
|
|
25
|
+
name: string;
|
|
26
|
+
process: (value?: string, defaultValue?: V) => V;
|
|
27
|
+
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Constructor } from '@nu-art/ts-common';
|
|
2
|
+
import { CommandBuilder } from './CommandBuilder';
|
|
3
|
+
export declare class BaseCommando {
|
|
4
|
+
protected readonly builder: CommandBuilder;
|
|
5
|
+
protected _debug: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new instance of BaseCommando merged with the provided plugins.
|
|
8
|
+
* @param {Constructor<any>[]} plugins - The plugins to merge with BaseCommando.
|
|
9
|
+
* @returns The Super type merged of BaseCommando and all the plugins provided new instance of BaseCommando merged with the plugins.
|
|
10
|
+
*/
|
|
11
|
+
static _create<T extends Constructor<any>[]>(...plugins: T): import("./class-merger").MergeTypes<[typeof BaseCommando, ...T]> & BaseCommando;
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a BaseCommando instance.
|
|
14
|
+
*/
|
|
15
|
+
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Toggles or sets the debug mode.
|
|
18
|
+
* @param {boolean} [debug] - If provided, sets the debug mode to this value. Otherwise, toggles the current debug mode.
|
|
19
|
+
* @returns {boolean} - The current state of debug mode.
|
|
20
|
+
*/
|
|
21
|
+
debug(debug?: boolean): this;
|
|
22
|
+
/**
|
|
23
|
+
* Appends a command to the command list.
|
|
24
|
+
* @param {string} command - The command to append.
|
|
25
|
+
* @returns {this} - The BaseCommando instance for method chaining.
|
|
26
|
+
*/
|
|
27
|
+
append(command: string): this;
|
|
28
|
+
/**
|
|
29
|
+
* Increases the current indentation level by one.
|
|
30
|
+
* @returns {this} - The BaseCommando instance for method chaining.
|
|
31
|
+
*/
|
|
32
|
+
indentIn(): this;
|
|
33
|
+
/**
|
|
34
|
+
* Decreases the current indentation level by one.
|
|
35
|
+
* @returns {this} - The BaseCommando instance for method chaining.
|
|
36
|
+
*/
|
|
37
|
+
indentOut(): this;
|
|
38
|
+
/**
|
|
39
|
+
* Appends an empty line to the script for readability.
|
|
40
|
+
* @returns {this} - The BaseCommando instance for method chaining.
|
|
41
|
+
*/
|
|
42
|
+
emptyLine(): this;
|
|
43
|
+
/**
|
|
44
|
+
* Executes the commands. Must be overridden in a subclass.
|
|
45
|
+
* @throws {ImplementationMissingException} - Always throws this exception.
|
|
46
|
+
*/
|
|
47
|
+
execute(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Executes the commands with a callback. Must be overridden in a subclass.
|
|
50
|
+
* @param {Function} callback - A callback function to handle the command output.
|
|
51
|
+
* @throws {ImplementationMissingException} - Always throws this exception.
|
|
52
|
+
*/
|
|
53
|
+
execute<T>(callback: (stdout: string, stderr: string, exitCode: number) => T): Promise<T>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseCommando = void 0;
|
|
4
|
+
const ts_common_1 = require("@nu-art/ts-common");
|
|
5
|
+
const CommandBuilder_1 = require("./CommandBuilder");
|
|
6
|
+
const class_merger_1 = require("./class-merger");
|
|
7
|
+
class BaseCommando {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new instance of BaseCommando merged with the provided plugins.
|
|
10
|
+
* @param {Constructor<any>[]} plugins - The plugins to merge with BaseCommando.
|
|
11
|
+
* @returns The Super type merged of BaseCommando and all the plugins provided new instance of BaseCommando merged with the plugins.
|
|
12
|
+
*/
|
|
13
|
+
static _create(...plugins) {
|
|
14
|
+
const _commando = (0, class_merger_1.CreateMergedInstance)(BaseCommando, ...plugins);
|
|
15
|
+
const commando = _commando;
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
commando.builder = new CommandBuilder_1.CommandBuilder();
|
|
18
|
+
return commando;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Constructs a BaseCommando instance.
|
|
22
|
+
*/
|
|
23
|
+
constructor() {
|
|
24
|
+
this._debug = false;
|
|
25
|
+
this.builder = new CommandBuilder_1.CommandBuilder();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Toggles or sets the debug mode.
|
|
29
|
+
* @param {boolean} [debug] - If provided, sets the debug mode to this value. Otherwise, toggles the current debug mode.
|
|
30
|
+
* @returns {boolean} - The current state of debug mode.
|
|
31
|
+
*/
|
|
32
|
+
debug(debug) {
|
|
33
|
+
this._debug = debug !== null && debug !== void 0 ? debug : !this._debug;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Appends a command to the command list.
|
|
38
|
+
* @param {string} command - The command to append.
|
|
39
|
+
* @returns {this} - The BaseCommando instance for method chaining.
|
|
40
|
+
*/
|
|
41
|
+
append(command) {
|
|
42
|
+
this.builder.append(command);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Increases the current indentation level by one.
|
|
47
|
+
* @returns {this} - The BaseCommando instance for method chaining.
|
|
48
|
+
*/
|
|
49
|
+
indentIn() {
|
|
50
|
+
this.builder.indentIn();
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Decreases the current indentation level by one.
|
|
55
|
+
* @returns {this} - The BaseCommando instance for method chaining.
|
|
56
|
+
*/
|
|
57
|
+
indentOut() {
|
|
58
|
+
this.builder.indentOut();
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Appends an empty line to the script for readability.
|
|
63
|
+
* @returns {this} - The BaseCommando instance for method chaining.
|
|
64
|
+
*/
|
|
65
|
+
emptyLine() {
|
|
66
|
+
this.builder.emptyLine();
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
async execute(callback) {
|
|
70
|
+
throw new ts_common_1.ImplementationMissingException('need to override this method in your class');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.BaseCommando = BaseCommando;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { CustomException } from '@nu-art/ts-common';
|
|
3
|
+
import { ExecException } from 'child_process';
|
|
4
|
+
export declare class CliError extends CustomException {
|
|
5
|
+
stdout: string;
|
|
6
|
+
stderr: string;
|
|
7
|
+
cause: ExecException;
|
|
8
|
+
constructor(message: string, stdout: string, stderr: string, cause: ExecException);
|
|
9
|
+
}
|
|
10
|
+
export declare class CommandoException extends CustomException {
|
|
11
|
+
stdout: string;
|
|
12
|
+
stderr: string;
|
|
13
|
+
exitCode: number;
|
|
14
|
+
constructor(message: string, stdout: string, stderr: string, exitCode: number);
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandoException = exports.CliError = void 0;
|
|
4
|
+
const ts_common_1 = require("@nu-art/ts-common");
|
|
5
|
+
class CliError extends ts_common_1.CustomException {
|
|
6
|
+
constructor(message, stdout, stderr, cause) {
|
|
7
|
+
super(CliError, message, cause);
|
|
8
|
+
this.stdout = stdout;
|
|
9
|
+
this.stderr = stderr;
|
|
10
|
+
this.cause = cause;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.CliError = CliError;
|
|
14
|
+
class CommandoException extends ts_common_1.CustomException {
|
|
15
|
+
constructor(message, stdout, stderr, exitCode) {
|
|
16
|
+
super(CliError, message);
|
|
17
|
+
this.stdout = stdout;
|
|
18
|
+
this.stderr = stderr;
|
|
19
|
+
this.exitCode = exitCode;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.CommandoException = CommandoException;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definition for options used in the CommandBuilder class.
|
|
3
|
+
*/
|
|
4
|
+
type Options = {
|
|
5
|
+
newlineDelimiter: string;
|
|
6
|
+
indentation: number;
|
|
7
|
+
};
|
|
8
|
+
export declare class CommandBuilder {
|
|
9
|
+
commands: string[];
|
|
10
|
+
private indentation;
|
|
11
|
+
private option;
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a CommandBuilder instance with given options.
|
|
14
|
+
* @param {Partial<Options>} [options=defaultOptions] - Configuration options for the CommandBuilder instance.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options?: Partial<Options>);
|
|
17
|
+
/**
|
|
18
|
+
* Generates a string of spaces for indentation based on the current indentation level.
|
|
19
|
+
* @returns {string} - A string containing spaces for the current indentation level.
|
|
20
|
+
*/
|
|
21
|
+
protected getIndentation: () => string;
|
|
22
|
+
/**
|
|
23
|
+
* Increases the current indentation level by one.
|
|
24
|
+
*/
|
|
25
|
+
readonly indentIn: () => void;
|
|
26
|
+
/**
|
|
27
|
+
* Decreases the current indentation level by one.
|
|
28
|
+
*/
|
|
29
|
+
readonly indentOut: () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Appends an empty line to the command list for readability.
|
|
32
|
+
* @returns {this} - The CommandBuilder instance for method chaining.
|
|
33
|
+
*/
|
|
34
|
+
emptyLine(): this;
|
|
35
|
+
/**
|
|
36
|
+
* Appends a command to the command list with proper indentation.
|
|
37
|
+
* @param {string} command - The command to append.
|
|
38
|
+
* @returns {this} - The CommandBuilder instance for method chaining.
|
|
39
|
+
*/
|
|
40
|
+
readonly append: (command: string) => this;
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves the full command list as a single string.
|
|
43
|
+
* @returns {string} - The full command list.
|
|
44
|
+
*/
|
|
45
|
+
getCommand(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Resets the command list and returns the previously accumulated commands.
|
|
48
|
+
* @returns {string} - The previously accumulated commands.
|
|
49
|
+
*/
|
|
50
|
+
reset(): string;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandBuilder = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Default options for CommandBuilder class instances.
|
|
6
|
+
*/
|
|
7
|
+
const defaultOptions = {
|
|
8
|
+
newlineDelimiter: '\n ',
|
|
9
|
+
indentation: 2,
|
|
10
|
+
};
|
|
11
|
+
class CommandBuilder {
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a CommandBuilder instance with given options.
|
|
14
|
+
* @param {Partial<Options>} [options=defaultOptions] - Configuration options for the CommandBuilder instance.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options = defaultOptions) {
|
|
17
|
+
this.commands = [];
|
|
18
|
+
this.indentation = 0;
|
|
19
|
+
this.option = defaultOptions;
|
|
20
|
+
/**
|
|
21
|
+
* Generates a string of spaces for indentation based on the current indentation level.
|
|
22
|
+
* @returns {string} - A string containing spaces for the current indentation level.
|
|
23
|
+
*/
|
|
24
|
+
this.getIndentation = () => {
|
|
25
|
+
return ' '.repeat(this.option.indentation * this.indentation);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Increases the current indentation level by one.
|
|
29
|
+
*/
|
|
30
|
+
this.indentIn = () => {
|
|
31
|
+
this.indentation++;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Decreases the current indentation level by one.
|
|
35
|
+
*/
|
|
36
|
+
this.indentOut = () => {
|
|
37
|
+
this.indentation--;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Appends a command to the command list with proper indentation.
|
|
41
|
+
* @param {string} command - The command to append.
|
|
42
|
+
* @returns {this} - The CommandBuilder instance for method chaining.
|
|
43
|
+
*/
|
|
44
|
+
this.append = (command) => {
|
|
45
|
+
const commands = command.split(this.option.newlineDelimiter);
|
|
46
|
+
for (const _command of commands) {
|
|
47
|
+
this.commands.push(`${this.getIndentation()}${_command.trim()}`);
|
|
48
|
+
}
|
|
49
|
+
return this;
|
|
50
|
+
};
|
|
51
|
+
this.option = options;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Appends an empty line to the command list for readability.
|
|
55
|
+
* @returns {this} - The CommandBuilder instance for method chaining.
|
|
56
|
+
*/
|
|
57
|
+
emptyLine() {
|
|
58
|
+
this.append('');
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Retrieves the full command list as a single string.
|
|
63
|
+
* @returns {string} - The full command list.
|
|
64
|
+
*/
|
|
65
|
+
getCommand() {
|
|
66
|
+
return this.commands.join(this.option.newlineDelimiter);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resets the command list and returns the previously accumulated commands.
|
|
70
|
+
* @returns {string} - The previously accumulated commands.
|
|
71
|
+
*/
|
|
72
|
+
reset() {
|
|
73
|
+
const command = this.getCommand();
|
|
74
|
+
this.commands.length = 0;
|
|
75
|
+
return command;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.CommandBuilder = CommandBuilder;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Constructor } from '@nu-art/ts-common';
|
|
2
|
+
/**
|
|
3
|
+
* Type utility to recursively merge the types of constructors in an array.
|
|
4
|
+
* @template T - An array of constructors.
|
|
5
|
+
*/
|
|
6
|
+
export type MergeTypes<T extends Constructor<any>[]> = T extends [a: Constructor<infer A>, ...rest: infer R] ? R extends Constructor<any>[] ? A & MergeTypes<R> : {} : {};
|
|
7
|
+
/**
|
|
8
|
+
* Function to merge multiple classes into a single class.
|
|
9
|
+
* @template T - An array of constructors.
|
|
10
|
+
* @param {...T} plugins - The constructors to merge.
|
|
11
|
+
* @returns {Constructor<MergeTypes<T>>} - A new constructor that merges all the provided constructors.
|
|
12
|
+
*/
|
|
13
|
+
export declare function MergeClass<T extends Constructor<any>[]>(...plugins: T): Constructor<MergeTypes<T>>;
|
|
14
|
+
/**
|
|
15
|
+
* Function to create an instance of a class that merges multiple classes.
|
|
16
|
+
* @template T - An array of constructors.
|
|
17
|
+
* @param {...T} plugins - The constructors to merge.
|
|
18
|
+
* @returns {MergeTypes<T>} - An instance of the merged class.
|
|
19
|
+
*/
|
|
20
|
+
export declare function CreateMergedInstance<T extends Constructor<any>[]>(...plugins: T): MergeTypes<T>;
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreateMergedInstance = exports.MergeClass = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Function to merge multiple classes into a single class.
|
|
6
|
+
* @template T - An array of constructors.
|
|
7
|
+
* @param {...T} plugins - The constructors to merge.
|
|
8
|
+
* @returns {Constructor<MergeTypes<T>>} - A new constructor that merges all the provided constructors.
|
|
9
|
+
*/
|
|
4
10
|
function MergeClass(...plugins) {
|
|
5
11
|
class SuperClass {
|
|
12
|
+
/**
|
|
13
|
+
* Constructs an instance of SuperClass, merging properties from all plugins.
|
|
14
|
+
* @param {...any[]} args - The arguments to pass to the constructors.
|
|
15
|
+
*/
|
|
6
16
|
constructor(...args) {
|
|
7
17
|
plugins.forEach(plugin => {
|
|
8
18
|
Object.getOwnPropertyNames(plugin.prototype).forEach(name => {
|
|
@@ -17,6 +27,12 @@ function MergeClass(...plugins) {
|
|
|
17
27
|
return SuperClass;
|
|
18
28
|
}
|
|
19
29
|
exports.MergeClass = MergeClass;
|
|
30
|
+
/**
|
|
31
|
+
* Function to create an instance of a class that merges multiple classes.
|
|
32
|
+
* @template T - An array of constructors.
|
|
33
|
+
* @param {...T} plugins - The constructors to merge.
|
|
34
|
+
* @returns {MergeTypes<T>} - An instance of the merged class.
|
|
35
|
+
*/
|
|
20
36
|
function CreateMergedInstance(...plugins) {
|
|
21
37
|
const SuperClass = MergeClass(...plugins);
|
|
22
38
|
return new SuperClass();
|
package/shell/index.d.ts
ADDED
package/shell/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("./interactive/CommandoInteractive"), exports);
|
|
18
|
+
__exportStar(require("./simple/Commando"), exports);
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Constructor } from '@nu-art/ts-common';
|
|
3
|
+
import { LogTypes } from '../types';
|
|
4
|
+
import { BaseCommando } from '../core/BaseCommando';
|
|
5
|
+
export declare class CommandoInteractive extends BaseCommando {
|
|
6
|
+
private shell;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new instance of CommandoInteractive merged with the provided plugins.
|
|
9
|
+
* @param {Constructor<any>[]} plugins - The plugins to merge with CommandoInteractive.
|
|
10
|
+
* @returns {CommandoInteractive} - The new instance of CommandoInteractive merged with the plugins.
|
|
11
|
+
*/
|
|
12
|
+
static create<T extends Constructor<any>[]>(...plugins: T): import("../core/class-merger").MergeTypes<[typeof BaseCommando, typeof CommandoInteractive, ...T]> & BaseCommando & CommandoInteractive;
|
|
13
|
+
/**
|
|
14
|
+
* Constructs a CommandoInteractive instance.
|
|
15
|
+
*/
|
|
16
|
+
constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Toggles or sets the debug mode.
|
|
19
|
+
* @param {boolean} [debug] - If provided, sets the debug mode to this value. Otherwise, toggles the current debug mode.
|
|
20
|
+
* @returns {boolean} - The current state of debug mode.
|
|
21
|
+
*/
|
|
22
|
+
debug(debug?: boolean): this;
|
|
23
|
+
/**
|
|
24
|
+
* Sets the UID for the shell.
|
|
25
|
+
* @param {string} uid - The UID to set.
|
|
26
|
+
* @returns {this} - The CommandoInteractive instance for method chaining.
|
|
27
|
+
*/
|
|
28
|
+
setUID(uid: string): this;
|
|
29
|
+
/**
|
|
30
|
+
* Closes the shell, optionally with a callback function.
|
|
31
|
+
* @returns {this} - The CommandoInteractive instance for method chaining.
|
|
32
|
+
*/
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Kills the shell process with a given signal.
|
|
36
|
+
* @param {NodeJS.Signals | number} [signal] - The signal to send to the process.
|
|
37
|
+
* @returns {boolean} - Whether the kill signal was successfully sent.
|
|
38
|
+
*/
|
|
39
|
+
kill(signal?: NodeJS.Signals | number): boolean | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Gracefully kills a process by its PID.
|
|
42
|
+
* @param {number} [pid] - The PID of the process to kill.
|
|
43
|
+
*/
|
|
44
|
+
gracefullyKill(pid?: number): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Waits for a log entry that matches a specified pattern, then executes a callback.
|
|
47
|
+
* @param {string | RegExp} filter - The pattern to match in log entries.
|
|
48
|
+
* @param {(match: RegExpMatchArray) => any} callback - The callback to execute when a match is found.
|
|
49
|
+
*/
|
|
50
|
+
onLog(filter: string | RegExp, callback: (match: RegExpMatchArray) => any): void;
|
|
51
|
+
/**
|
|
52
|
+
* Executes commands asynchronously and listens for the PID.
|
|
53
|
+
*
|
|
54
|
+
* @param {Function} pidListener - A listener function to handle the PID.
|
|
55
|
+
* @param {Function} [callback] - A callback function to handle the command output.
|
|
56
|
+
* @returns {Promise<T>} - The result of the callback function.
|
|
57
|
+
*/
|
|
58
|
+
executeAsync<T>(pidListener: (pid: number) => void, callback?: (stdout: string, stderr: string, exitCode: number) => T): Promise<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Executes commands and processes logs to extract exit code.
|
|
61
|
+
* @param {Function} [callback] - A callback function to handle the command output.
|
|
62
|
+
* @returns {Promise<T>} - The result of the callback function.
|
|
63
|
+
*/
|
|
64
|
+
execute<T>(callback?: (stdout: string, stderr: string, exitCode: number) => T): Promise<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Adds a log processor to the shell.
|
|
67
|
+
* @param {Function} processor - The log processor function to add.
|
|
68
|
+
* @returns {this} - The CommandoInteractive instance for method chaining.
|
|
69
|
+
*/
|
|
70
|
+
addLogProcessor(processor: (log: string, std: LogTypes) => boolean): this;
|
|
71
|
+
/**
|
|
72
|
+
* Removes a log processor from the shell.
|
|
73
|
+
* @param {Function} processor - The log processor function to remove.
|
|
74
|
+
* @returns {this} - The CommandoInteractive instance for method chaining.
|
|
75
|
+
*/
|
|
76
|
+
removeLogProcessor(processor: (log: string, std: LogTypes) => boolean): this;
|
|
77
|
+
/**
|
|
78
|
+
* Appends a command to the command list.
|
|
79
|
+
* @param {string} command - The command to append.
|
|
80
|
+
* @returns {this} - The CommandoInteractive instance for method chaining.
|
|
81
|
+
*/
|
|
82
|
+
append(command: string): this;
|
|
83
|
+
}
|