@nu-art/commando 0.204.87 → 0.204.89

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.
Files changed (47) hide show
  1. package/cli/basic.d.ts +3 -2
  2. package/cli/basic.js +15 -15
  3. package/cli/git.d.ts +18 -17
  4. package/cli/git.js +43 -22
  5. package/cli/nvm.d.ts +4 -3
  6. package/cli/nvm.js +13 -10
  7. package/cli/pnpm.d.ts +1 -1
  8. package/cli/pnpm.js +8 -8
  9. package/cli/programming.d.ts +3 -2
  10. package/cli/programming.js +19 -19
  11. package/cli-params/CLIParamsResolver.d.ts +27 -0
  12. package/{cli/cli-params.js → cli-params/CLIParamsResolver.js} +6 -34
  13. package/cli-params/consts.d.ts +6 -0
  14. package/cli-params/consts.js +32 -0
  15. package/cli-params/types.d.ts +27 -0
  16. package/cli-params/types.js +2 -0
  17. package/package.json +1 -1
  18. package/shell/core/BaseCommando.d.ts +54 -0
  19. package/shell/core/BaseCommando.js +73 -0
  20. package/shell/core/CliError.d.ts +15 -0
  21. package/shell/core/CliError.js +22 -0
  22. package/shell/core/CommandBuilder.d.ts +52 -0
  23. package/shell/core/CommandBuilder.js +78 -0
  24. package/shell/core/class-merger.d.ts +20 -0
  25. package/{core → shell/core}/class-merger.js +16 -0
  26. package/shell/index.d.ts +2 -0
  27. package/shell/index.js +18 -0
  28. package/shell/interactive/CommandoInteractive.d.ts +83 -0
  29. package/shell/interactive/CommandoInteractive.js +180 -0
  30. package/shell/interactive/InteractiveShell.d.ts +63 -0
  31. package/shell/interactive/InteractiveShell.js +139 -0
  32. package/shell/simple/Commando.d.ts +17 -0
  33. package/shell/simple/Commando.js +51 -0
  34. package/shell/simple/SimpleShell.d.ts +23 -0
  35. package/shell/simple/SimpleShell.js +48 -0
  36. package/shell/types.d.ts +3 -0
  37. package/shell/types.js +2 -0
  38. package/cli/cli-params.d.ts +0 -56
  39. package/core/CliError.d.ts +0 -6
  40. package/core/CliError.js +0 -12
  41. package/core/class-merger.d.ts +0 -5
  42. package/core/cli.d.ts +0 -147
  43. package/core/cli.js +0 -404
  44. package/test-scripts/test-params.d.ts +0 -1
  45. package/test-scripts/test-params.js +0 -43
  46. /package/{core → shell}/tools.d.ts +0 -0
  47. /package/{core → shell}/tools.js +0 -0
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandoInteractive = void 0;
4
+ const ts_common_1 = require("@nu-art/ts-common");
5
+ const InteractiveShell_1 = require("./InteractiveShell");
6
+ const BaseCommando_1 = require("../core/BaseCommando");
7
+ class CommandoInteractive extends BaseCommando_1.BaseCommando {
8
+ /**
9
+ * Creates a new instance of CommandoInteractive merged with the provided plugins.
10
+ * @param {Constructor<any>[]} plugins - The plugins to merge with CommandoInteractive.
11
+ * @returns {CommandoInteractive} - The new instance of CommandoInteractive merged with the plugins.
12
+ */
13
+ static create(...plugins) {
14
+ const _commando = BaseCommando_1.BaseCommando._create(CommandoInteractive, ...plugins);
15
+ const commando = _commando;
16
+ commando.shell = new InteractiveShell_1.InteractiveShell();
17
+ commando.shell.setMinLevel(ts_common_1.LogLevel.Verbose);
18
+ return commando;
19
+ }
20
+ /**
21
+ * Constructs a CommandoInteractive instance.
22
+ */
23
+ constructor() {
24
+ super();
25
+ this.shell = new InteractiveShell_1.InteractiveShell();
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.shell.debug(debug);
34
+ return super.debug(debug);
35
+ }
36
+ /**
37
+ * Sets the UID for the shell.
38
+ * @param {string} uid - The UID to set.
39
+ * @returns {this} - The CommandoInteractive instance for method chaining.
40
+ */
41
+ setUID(uid) {
42
+ this.shell.setUID(uid);
43
+ return this;
44
+ }
45
+ /**
46
+ * Closes the shell, optionally with a callback function.
47
+ * @returns {this} - The CommandoInteractive instance for method chaining.
48
+ */
49
+ close() {
50
+ return this.shell.endInteractive();
51
+ }
52
+ /**
53
+ * Kills the shell process with a given signal.
54
+ * @param {NodeJS.Signals | number} [signal] - The signal to send to the process.
55
+ * @returns {boolean} - Whether the kill signal was successfully sent.
56
+ */
57
+ kill(signal) {
58
+ return this.shell.kill(signal);
59
+ }
60
+ /**
61
+ * Gracefully kills a process by its PID.
62
+ * @param {number} [pid] - The PID of the process to kill.
63
+ */
64
+ async gracefullyKill(pid) {
65
+ return this.shell.gracefullyKill(pid);
66
+ }
67
+ /**
68
+ * Waits for a log entry that matches a specified pattern, then executes a callback.
69
+ * @param {string | RegExp} filter - The pattern to match in log entries.
70
+ * @param {(match: RegExpMatchArray) => any} callback - The callback to execute when a match is found.
71
+ */
72
+ onLog(filter, callback) {
73
+ const regexp = typeof filter === 'string' ? new RegExp(filter) : filter;
74
+ const pidLogProcessor = (log) => {
75
+ const match = log.match(regexp);
76
+ if (!match)
77
+ return true;
78
+ callback(match);
79
+ return true;
80
+ };
81
+ this.addLogProcessor(pidLogProcessor);
82
+ }
83
+ /**
84
+ * Executes commands asynchronously and listens for the PID.
85
+ *
86
+ * @param {Function} pidListener - A listener function to handle the PID.
87
+ * @param {Function} [callback] - A callback function to handle the command output.
88
+ * @returns {Promise<T>} - The result of the callback function.
89
+ */
90
+ async executeAsync(pidListener, callback) {
91
+ const uniqueFunctionName = (0, ts_common_1.generateHex)(16);
92
+ const pidUniqueKey = (0, ts_common_1.generateHex)(16);
93
+ const regexp = new RegExp(`${pidUniqueKey}=(\\d+)`);
94
+ const functionContent = this.builder.reset();
95
+ const functionName = `${uniqueFunctionName}() {`;
96
+ const pidLogProcessor = (log) => {
97
+ const match = log.match(regexp);
98
+ if (!match)
99
+ return true;
100
+ const pid = +match[1];
101
+ pidListener(pid);
102
+ return false;
103
+ };
104
+ return await this
105
+ .append(functionName)
106
+ .append(functionContent)
107
+ .append('}')
108
+ .append(`${uniqueFunctionName} &`)
109
+ .append('pid=$!')
110
+ .append(`echo "${pidUniqueKey}=\${pid}"`)
111
+ .append(`wait \$pid`)
112
+ .addLogProcessor(pidLogProcessor)
113
+ .execute(callback);
114
+ }
115
+ /**
116
+ * Executes commands and processes logs to extract exit code.
117
+ * @param {Function} [callback] - A callback function to handle the command output.
118
+ * @returns {Promise<T>} - The result of the callback function.
119
+ */
120
+ async execute(callback) {
121
+ return await new Promise((resolve, reject) => {
122
+ const uniqueKey = (0, ts_common_1.generateHex)(16);
123
+ const regexp = new RegExp(`${uniqueKey}=(\\d+)`);
124
+ let _stderr = '';
125
+ let _stdout = '';
126
+ const logProcessor = (log, type) => {
127
+ if (type === 'err')
128
+ _stderr += `${log}\n`;
129
+ else
130
+ _stdout += `${log}\n`;
131
+ if (!log.includes(uniqueKey))
132
+ return true;
133
+ const match = log.match(regexp);
134
+ if (!match)
135
+ return true;
136
+ const exitCode = match === null || match === void 0 ? void 0 : match[1];
137
+ this.removeLogProcessor(logProcessor);
138
+ try {
139
+ resolve(callback === null || callback === void 0 ? void 0 : callback(_stdout, _stderr, +exitCode));
140
+ }
141
+ catch (err) {
142
+ reject(err);
143
+ }
144
+ return false;
145
+ };
146
+ this.builder.append(`echo ${uniqueKey}=$?`);
147
+ const command = this.builder.reset();
148
+ this.shell.addLogProcessor(logProcessor);
149
+ this.shell.execute(command);
150
+ });
151
+ }
152
+ /**
153
+ * Adds a log processor to the shell.
154
+ * @param {Function} processor - The log processor function to add.
155
+ * @returns {this} - The CommandoInteractive instance for method chaining.
156
+ */
157
+ addLogProcessor(processor) {
158
+ this.shell.addLogProcessor(processor);
159
+ return this;
160
+ }
161
+ /**
162
+ * Removes a log processor from the shell.
163
+ * @param {Function} processor - The log processor function to remove.
164
+ * @returns {this} - The CommandoInteractive instance for method chaining.
165
+ */
166
+ removeLogProcessor(processor) {
167
+ this.shell.removeLogProcessor(processor);
168
+ return this;
169
+ }
170
+ /**
171
+ * Appends a command to the command list.
172
+ * @param {string} command - The command to append.
173
+ * @returns {this} - The CommandoInteractive instance for method chaining.
174
+ */
175
+ append(command) {
176
+ this.builder.append(command);
177
+ return this;
178
+ }
179
+ }
180
+ exports.CommandoInteractive = CommandoInteractive;
@@ -0,0 +1,63 @@
1
+ /// <reference types="mocha" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ /// <reference types="node" />
6
+ /// <reference types="node" />
7
+ import { Logger } from '@nu-art/ts-common';
8
+ import { LogTypes } from '../types';
9
+ export declare class InteractiveShell extends Logger {
10
+ private _debug;
11
+ private logProcessors;
12
+ private shell;
13
+ private alive;
14
+ /**
15
+ * Constructs an InteractiveShell instance, initializes a detached shell session, and sets up log processors.
16
+ */
17
+ constructor();
18
+ /**
19
+ * Toggles or sets the debug mode.
20
+ * @param {boolean} [debug] - If provided, sets the debug mode to this value. Otherwise, toggles the current debug mode.
21
+ * @returns {boolean} - The current state of debug mode.
22
+ */
23
+ debug(debug?: boolean): this;
24
+ /**
25
+ * Executes a command in the interactive shell.
26
+ * @param {string} command - The command to execute.
27
+ */
28
+ execute: (command: string) => void;
29
+ /**
30
+ * Awaits for the end of the interactive shell session.
31
+ */
32
+ endInteractive: () => Promise<void>;
33
+ /**
34
+ * Sends a signal to terminate the shell process.
35
+ * @param {NodeJS.Signals | number} [signal] - The signal to send to the shell process.
36
+ * @returns {boolean | undefined} - The result of the kill operation.
37
+ */
38
+ kill: (signal?: NodeJS.Signals | number) => boolean | undefined;
39
+ /**
40
+ * Attempts to gracefully terminate the shell process.
41
+ * @param {number} [pid] - Process ID of the shell to terminate.
42
+ * @returns {Promise<void>} - Resolves when the shell process is gracefully killed.
43
+ */
44
+ gracefullyKill: (pid?: number) => Promise<void>;
45
+ /**
46
+ * Adds a log processor to handle log messages.
47
+ * @param {(log: string, std: LogTypes) => boolean} processor - The log processor function.
48
+ * @returns {this} - The InteractiveShell instance for method chaining.
49
+ */
50
+ addLogProcessor(processor: (log: string, std: LogTypes) => boolean): this;
51
+ /**
52
+ * Removes a log processor from handling log messages.
53
+ * @param {(log: string, std: LogTypes) => boolean} processor - The log processor function to remove.
54
+ * @returns {this} - The InteractiveShell instance for method chaining.
55
+ */
56
+ removeLogProcessor(processor: (log: string, std: LogTypes) => boolean): this;
57
+ /**
58
+ * Sets a unique identifier for the shell session.
59
+ * @param {string} uid - The unique identifier.
60
+ * @returns {this} - The InteractiveShell instance for method chaining.
61
+ */
62
+ setUID(uid: string): this;
63
+ }
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InteractiveShell = void 0;
4
+ const ts_common_1 = require("@nu-art/ts-common");
5
+ const node_child_process_1 = require("node:child_process");
6
+ class InteractiveShell extends ts_common_1.Logger {
7
+ /**
8
+ * Constructs an InteractiveShell instance, initializes a detached shell session, and sets up log processors.
9
+ */
10
+ constructor() {
11
+ var _a, _b;
12
+ super();
13
+ this._debug = false;
14
+ this.logProcessors = [];
15
+ /**
16
+ * Executes a command in the interactive shell.
17
+ * @param {string} command - The command to execute.
18
+ */
19
+ this.execute = (command) => {
20
+ var _a;
21
+ if (this._debug)
22
+ this.logDebug(`executing: `, `"""\n${command}\n"""`);
23
+ (_a = this.shell.stdin) === null || _a === void 0 ? void 0 : _a.write(command + '\n', 'utf-8', (err) => {
24
+ if (err)
25
+ this.logError(`error`, err);
26
+ });
27
+ };
28
+ /**
29
+ * Awaits for the end of the interactive shell session.
30
+ */
31
+ this.endInteractive = () => {
32
+ return new Promise(resolve => {
33
+ var _a;
34
+ (_a = this.shell.stdin) === null || _a === void 0 ? void 0 : _a.end(resolve);
35
+ });
36
+ };
37
+ /**
38
+ * Sends a signal to terminate the shell process.
39
+ * @param {NodeJS.Signals | number} [signal] - The signal to send to the shell process.
40
+ * @returns {boolean | undefined} - The result of the kill operation.
41
+ */
42
+ this.kill = (signal) => {
43
+ if (!this.alive)
44
+ return;
45
+ return this.shell.kill(signal);
46
+ };
47
+ /**
48
+ * Attempts to gracefully terminate the shell process.
49
+ * @param {number} [pid] - Process ID of the shell to terminate.
50
+ * @returns {Promise<void>} - Resolves when the shell process is gracefully killed.
51
+ */
52
+ this.gracefullyKill = async (pid) => {
53
+ if (!this.alive)
54
+ return;
55
+ return new Promise((resolve, reject) => {
56
+ console.log('Killing process');
57
+ this.shell.on('exit', async (code, signal) => {
58
+ console.log(`Process Killed ${signal}`);
59
+ resolve();
60
+ });
61
+ if (pid) {
62
+ console.log(`KILLING PID: ${pid}`);
63
+ process.kill(pid, 'SIGINT');
64
+ }
65
+ else {
66
+ console.log(`KILLING SHELL WITH SIGINT`);
67
+ this.shell.kill('SIGINT');
68
+ }
69
+ });
70
+ };
71
+ this.shell = (0, node_child_process_1.spawn)('/bin/bash', {
72
+ detached: true,
73
+ shell: true
74
+ });
75
+ this.alive = true;
76
+ const printer = (std) => (data) => {
77
+ const messages = data.toString().trim().split('\n');
78
+ if (!messages.length)
79
+ return;
80
+ for (const message of messages) {
81
+ try {
82
+ const toPrint = this.logProcessors.length === 0 || this.logProcessors.reduce((toPrint, processor) => {
83
+ const filter = processor(message, std);
84
+ return toPrint && filter;
85
+ }, true);
86
+ if (toPrint)
87
+ this.logInfo(`${message}`);
88
+ }
89
+ catch (e) {
90
+ this.logError(e);
91
+ }
92
+ }
93
+ };
94
+ (_a = this.shell.stdout) === null || _a === void 0 ? void 0 : _a.on('data', printer('out'));
95
+ (_b = this.shell.stderr) === null || _b === void 0 ? void 0 : _b.on('data', printer('err'));
96
+ // Handle shell exit
97
+ this.shell.on('close', (code) => {
98
+ this.alive = false;
99
+ this.logInfo(`child process exited with code ${code}`);
100
+ });
101
+ }
102
+ /**
103
+ * Toggles or sets the debug mode.
104
+ * @param {boolean} [debug] - If provided, sets the debug mode to this value. Otherwise, toggles the current debug mode.
105
+ * @returns {boolean} - The current state of debug mode.
106
+ */
107
+ debug(debug) {
108
+ this._debug = debug !== null && debug !== void 0 ? debug : !this._debug;
109
+ return this;
110
+ }
111
+ /**
112
+ * Adds a log processor to handle log messages.
113
+ * @param {(log: string, std: LogTypes) => boolean} processor - The log processor function.
114
+ * @returns {this} - The InteractiveShell instance for method chaining.
115
+ */
116
+ addLogProcessor(processor) {
117
+ this.logProcessors.push(processor);
118
+ return this;
119
+ }
120
+ /**
121
+ * Removes a log processor from handling log messages.
122
+ * @param {(log: string, std: LogTypes) => boolean} processor - The log processor function to remove.
123
+ * @returns {this} - The InteractiveShell instance for method chaining.
124
+ */
125
+ removeLogProcessor(processor) {
126
+ (0, ts_common_1.removeItemFromArray)(this.logProcessors, processor);
127
+ return this;
128
+ }
129
+ /**
130
+ * Sets a unique identifier for the shell session.
131
+ * @param {string} uid - The unique identifier.
132
+ * @returns {this} - The InteractiveShell instance for method chaining.
133
+ */
134
+ setUID(uid) {
135
+ this.setTag(uid);
136
+ return this;
137
+ }
138
+ }
139
+ exports.InteractiveShell = InteractiveShell;
@@ -0,0 +1,17 @@
1
+ import { Constructor } from '@nu-art/ts-common';
2
+ import { BaseCommando } from '../core/BaseCommando';
3
+ export declare class Commando extends BaseCommando {
4
+ private uid?;
5
+ static create<T extends Constructor<any>[]>(...plugins: T): import("../core/class-merger").MergeTypes<[typeof BaseCommando, typeof Commando, ...T]> & BaseCommando & Commando;
6
+ constructor();
7
+ setUID(uid: string): this;
8
+ executeFile(filePath: string, interpreter?: string): Promise<{
9
+ stdout: string;
10
+ stderr: string;
11
+ }>;
12
+ executeRemoteFile(pathToFile: string, interpreter: string): Promise<{
13
+ stdout: string;
14
+ stderr: string;
15
+ }>;
16
+ execute<T>(callback?: (stdout: string, stderr: string, exitCode: number) => T): Promise<T | void>;
17
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Commando = void 0;
4
+ const ts_common_1 = require("@nu-art/ts-common");
5
+ const SimpleShell_1 = require("./SimpleShell");
6
+ const BaseCommando_1 = require("../core/BaseCommando");
7
+ const CliError_1 = require("../core/CliError");
8
+ class Commando extends BaseCommando_1.BaseCommando {
9
+ static create(...plugins) {
10
+ const _commando = BaseCommando_1.BaseCommando._create(Commando, ...plugins);
11
+ return _commando;
12
+ }
13
+ constructor() {
14
+ super();
15
+ }
16
+ setUID(uid) {
17
+ this.uid = uid;
18
+ return this;
19
+ }
20
+ executeFile(filePath, interpreter) {
21
+ let command = filePath;
22
+ // If an interpreter is provided, prefix the command with it.
23
+ if (interpreter) {
24
+ command = `${interpreter} ${filePath}`;
25
+ }
26
+ return new SimpleShell_1.SimpleShell().execute(command);
27
+ }
28
+ executeRemoteFile(pathToFile, interpreter) {
29
+ const command = `curl -o- "${pathToFile}" | ${interpreter}`;
30
+ return new SimpleShell_1.SimpleShell().execute(command);
31
+ }
32
+ async execute(callback) {
33
+ var _a;
34
+ const command = this.builder.reset();
35
+ const simpleShell = new SimpleShell_1.SimpleShell().debug(this._debug);
36
+ try {
37
+ if (this.uid)
38
+ simpleShell.setUID(this.uid);
39
+ const { stdout, stderr } = await simpleShell.execute(command);
40
+ return callback === null || callback === void 0 ? void 0 : callback(stdout, stderr, 0);
41
+ }
42
+ catch (_error) {
43
+ simpleShell.logError(_error);
44
+ const cliError = _error;
45
+ if ('isInstanceOf' in cliError && cliError.isInstanceOf(CliError_1.CliError))
46
+ return callback === null || callback === void 0 ? void 0 : callback(cliError.stdout, cliError.stderr, (_a = cliError.cause.code) !== null && _a !== void 0 ? _a : -1);
47
+ throw new ts_common_1.ThisShouldNotHappenException('Unhandled error', _error);
48
+ }
49
+ }
50
+ }
51
+ exports.Commando = Commando;
@@ -0,0 +1,23 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { ExecOptions } from 'child_process';
4
+ import { Logger } from '@nu-art/ts-common';
5
+ export type CliOptions = ExecOptions & {
6
+ encoding: BufferEncoding | string | null;
7
+ };
8
+ export declare class SimpleShell extends Logger {
9
+ private _debug;
10
+ private cliOptions;
11
+ /**
12
+ * Executes the accumulated commands in the command list.
13
+ * @returns {Promise<string>} A promise that resolves with the standard output of the executed command.
14
+ */
15
+ execute: (command: string) => Promise<{
16
+ stdout: string;
17
+ stderr: string;
18
+ }>;
19
+ debug(debug?: boolean): this;
20
+ setShell(shell: string): void;
21
+ setOptions(options: Partial<CliOptions>): void;
22
+ setUID(uid: string): this;
23
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SimpleShell = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const ts_common_1 = require("@nu-art/ts-common");
6
+ const CliError_1 = require("../core/CliError");
7
+ class SimpleShell extends ts_common_1.Logger {
8
+ constructor() {
9
+ super(...arguments);
10
+ this._debug = false;
11
+ this.cliOptions = { shell: '/bin/bash' };
12
+ /**
13
+ * Executes the accumulated commands in the command list.
14
+ * @returns {Promise<string>} A promise that resolves with the standard output of the executed command.
15
+ */
16
+ this.execute = async (command) => {
17
+ if (this._debug)
18
+ this.logDebug(`executing: `, `"""\n${command}\n"""`);
19
+ return new Promise((resolve, reject) => {
20
+ (0, child_process_1.exec)(command, this.cliOptions, (error, stdout, stderr) => {
21
+ if (error) {
22
+ return reject(new CliError_1.CliError(`executing:\n${command}\n`, stdout, stderr, error));
23
+ }
24
+ if (stdout)
25
+ this.logInfo(stdout);
26
+ if (stderr)
27
+ this.logError(stderr);
28
+ resolve({ stdout, stderr });
29
+ });
30
+ });
31
+ };
32
+ }
33
+ debug(debug) {
34
+ this._debug = debug !== null && debug !== void 0 ? debug : !this._debug;
35
+ return this;
36
+ }
37
+ setShell(shell) {
38
+ (this.cliOptions || (this.cliOptions = {})).shell = shell;
39
+ }
40
+ setOptions(options) {
41
+ this.cliOptions = options;
42
+ }
43
+ setUID(uid) {
44
+ this.setTag(uid);
45
+ return this;
46
+ }
47
+ }
48
+ exports.SimpleShell = SimpleShell;
@@ -0,0 +1,3 @@
1
+ import { BaseCommando } from './core/BaseCommando';
2
+ export type LogTypes = 'out' | 'err';
3
+ export type CliBlock<Commando extends BaseCommando> = (cli: Commando) => void;
package/shell/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,56 +0,0 @@
1
- import { Primitive, TypeOfTypeAsString } from '@nu-art/ts-common';
2
- export declare const DefaultProcessor_Boolean: CliParam<any, boolean>['process'];
3
- export declare const DefaultProcessor_String: CliParam<any, string>['process'];
4
- export declare const DefaultProcessor_Number: CliParam<any, number>['process'];
5
- export type CliParams<T extends BaseCliParam<string, any>[]> = {
6
- [K in T[number]['keyName']]: NonNullable<Extract<T[number], {
7
- keyName: K;
8
- }>['defaultValue']>;
9
- };
10
- export type DependencyParam<T extends Primitive | Primitive[]> = {
11
- param: BaseCliParam<string, T>;
12
- value: T;
13
- };
14
- export type BaseCliParam<K extends string, V extends Primitive | Primitive[]> = {
15
- keys: string[];
16
- keyName: K;
17
- type: TypeOfTypeAsString<V>;
18
- description: string;
19
- name?: string;
20
- options?: string[];
21
- defaultValue?: V;
22
- process?: (value?: string, defaultValue?: V) => V;
23
- isArray?: true;
24
- group?: string;
25
- dependencies?: DependencyParam<any>[];
26
- };
27
- export type CliParam<K extends string, V extends Primitive | Primitive[]> = BaseCliParam<K, V> & {
28
- name: string;
29
- process: (value?: string, defaultValue?: V) => V;
30
- };
31
- export declare class CLIParams_Resolver<T extends BaseCliParam<string, any>[], Output extends CliParams<T> = CliParams<T>> {
32
- private params;
33
- static create<T extends BaseCliParam<string, any>[]>(...params: T): CLIParams_Resolver<T, CliParams<T>>;
34
- constructor(params: BaseCliParam<string, any>[]);
35
- /**
36
- * Format current input params and return it structured by the app params type.
37
- * @param inputParams current console input arguments
38
- * @returns CliParamsObject
39
- */
40
- resolveParamValue(inputParams?: string[]): Output;
41
- /**
42
- * Find the matching param by finding it's key in the current argument
43
- * Go over the app params and find the CLIParam object representing it
44
- * @param inputParam The current console argument being parsed
45
- * @returns The CliParam or undefined if not found
46
- * @private
47
- */
48
- private findMatchingParamToResolve;
49
- /**
50
- * Translate BaseCLIParams passed to the constructor to CLIParams
51
- * @param params User input of CLI params being passed to the constructor
52
- * @private
53
- * @returns CLI Params filled with all mandatory data
54
- */
55
- private translate;
56
- }
@@ -1,6 +0,0 @@
1
- export declare class CliError extends Error {
2
- stdout: string;
3
- stderr: string;
4
- cause?: Error;
5
- constructor(message: string, stdout: string, stderr: string, cause?: Error);
6
- }
package/core/CliError.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CliError = void 0;
4
- class CliError extends Error {
5
- constructor(message, stdout, stderr, cause) {
6
- super(message);
7
- this.stdout = stdout;
8
- this.stderr = stderr;
9
- this.cause = cause;
10
- }
11
- }
12
- exports.CliError = CliError;
@@ -1,5 +0,0 @@
1
- type Constructor<T = {}> = new (...args: any[]) => T;
2
- export type MergeTypes<T extends Constructor<any>[]> = T extends [a: Constructor<infer A>, ...rest: infer R] ? R extends Constructor<any>[] ? A & MergeTypes<R> : {} : {};
3
- export declare function MergeClass<T extends Constructor<any>[]>(...plugins: T): Constructor<MergeTypes<T>>;
4
- export declare function CreateMergedInstance<T extends Constructor<any>[]>(...plugins: T): MergeTypes<T>;
5
- export {};