@nu-art/commando 0.203.117
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 +48 -0
- package/cli/basic.js +80 -0
- package/cli/cli-params.d.ts +51 -0
- package/cli/cli-params.js +115 -0
- package/cli/git.d.ts +53 -0
- package/cli/git.js +104 -0
- package/cli/nvm.d.ts +22 -0
- package/cli/nvm.js +120 -0
- package/cli/pnpm.d.ts +27 -0
- package/cli/pnpm.js +86 -0
- package/cli/programming.d.ts +34 -0
- package/cli/programming.js +75 -0
- package/core/CliError.d.ts +6 -0
- package/core/CliError.js +12 -0
- package/core/class-merger.d.ts +5 -0
- package/core/class-merger.js +24 -0
- package/core/cli.d.ts +98 -0
- package/core/cli.js +211 -0
- package/core/tools.d.ts +2 -0
- package/core/tools.js +22 -0
- package/package.json +39 -0
- package/test-scripts/test-params.d.ts +1 -0
- package/test-scripts/test-params.js +43 -0
package/cli/basic.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CliBlock, CliWrapper } from '../core/cli';
|
|
2
|
+
type Cli_EchoOptions = {
|
|
3
|
+
escape?: boolean;
|
|
4
|
+
toFile?: {
|
|
5
|
+
name: string;
|
|
6
|
+
append?: boolean;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Represents a Command Line Interface (CLI) to build and execute shell commands.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Cli_Basic extends CliWrapper {
|
|
13
|
+
/**
|
|
14
|
+
* Changes directory and optionally executes a block of commands in that directory.
|
|
15
|
+
* @param {string} folderName - Name of the directory to change to.
|
|
16
|
+
* @param {CliBlock} [toRun] - Optional block of commands to execute in the directory.
|
|
17
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
18
|
+
*/
|
|
19
|
+
cd(folderName: string, toRun?: CliBlock<this>): this;
|
|
20
|
+
custom(command: string): this;
|
|
21
|
+
/**
|
|
22
|
+
* Changes directory back to the previous directory.
|
|
23
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
24
|
+
*/
|
|
25
|
+
cd_(): this;
|
|
26
|
+
/**
|
|
27
|
+
* Appends an 'ls' command with optional parameters.
|
|
28
|
+
* @param {string} [params] - Optional parameters for the 'ls' command.
|
|
29
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
30
|
+
*/
|
|
31
|
+
ls(params?: string): this;
|
|
32
|
+
mkdir(dirName: string): this;
|
|
33
|
+
cat(fileName: string): this;
|
|
34
|
+
echo(log: string, options?: Cli_EchoOptions): this;
|
|
35
|
+
/**
|
|
36
|
+
* Appends a 'pwd' command to print the current directory.
|
|
37
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
38
|
+
*/
|
|
39
|
+
pwd(): this;
|
|
40
|
+
/**
|
|
41
|
+
* Assigns a value to a variable in the script.
|
|
42
|
+
* @param {string} varName - The name of the variable.
|
|
43
|
+
* @param {string | string[]} value - The value to assign to the variable.
|
|
44
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
45
|
+
*/
|
|
46
|
+
assignVar(varName: string, value: string | string[]): this;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
package/cli/basic.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Cli_Basic = void 0;
|
|
4
|
+
const cli_1 = require("../core/cli");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Command Line Interface (CLI) to build and execute shell commands.
|
|
7
|
+
*/
|
|
8
|
+
class Cli_Basic extends cli_1.CliWrapper {
|
|
9
|
+
/**
|
|
10
|
+
* Changes directory and optionally executes a block of commands in that directory.
|
|
11
|
+
* @param {string} folderName - Name of the directory to change to.
|
|
12
|
+
* @param {CliBlock} [toRun] - Optional block of commands to execute in the directory.
|
|
13
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
14
|
+
*/
|
|
15
|
+
cd(folderName, toRun) {
|
|
16
|
+
this.cli.append(`cd ${folderName}`);
|
|
17
|
+
this.cli.indentIn();
|
|
18
|
+
if (toRun) {
|
|
19
|
+
toRun(this);
|
|
20
|
+
this.cd_();
|
|
21
|
+
}
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
custom(command) {
|
|
25
|
+
this.cli.append(command);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Changes directory back to the previous directory.
|
|
30
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
31
|
+
*/
|
|
32
|
+
cd_() {
|
|
33
|
+
this.cli.indentOut();
|
|
34
|
+
this.cli.append(`cd -`);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Appends an 'ls' command with optional parameters.
|
|
39
|
+
* @param {string} [params] - Optional parameters for the 'ls' command.
|
|
40
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
41
|
+
*/
|
|
42
|
+
ls(params = '') {
|
|
43
|
+
this.cli.append(`ls ${params}`);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
mkdir(dirName) {
|
|
47
|
+
this.cli.append(`mkdir -p ${dirName}`);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
cat(fileName) {
|
|
51
|
+
this.cli.append(`cat ${fileName}`);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
echo(log, options) {
|
|
55
|
+
const _escape = (options === null || options === void 0 ? void 0 : options.escape) ? '-e' : '';
|
|
56
|
+
const _toFile = (options === null || options === void 0 ? void 0 : options.toFile) ? `>${options.toFile.append ? '>' : ''} ${options.toFile.name}` : '';
|
|
57
|
+
const escapedLog = log.replace(/\\/g, '\\\\').replace(/\n/g, '\\\\n').replace(/\t/g, '\\\t');
|
|
58
|
+
this.cli.append(`echo ${_escape} "${escapedLog}" ${_toFile}`);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Appends a 'pwd' command to print the current directory.
|
|
63
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
64
|
+
*/
|
|
65
|
+
pwd() {
|
|
66
|
+
this.cli.append('pwd');
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Assigns a value to a variable in the script.
|
|
71
|
+
* @param {string} varName - The name of the variable.
|
|
72
|
+
* @param {string | string[]} value - The value to assign to the variable.
|
|
73
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
74
|
+
*/
|
|
75
|
+
assignVar(varName, value) {
|
|
76
|
+
this.cli.append(`${varName}=(${Array.isArray(value) ? value : [value].join(' ')})`);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.Cli_Basic = Cli_Basic;
|
|
@@ -0,0 +1,51 @@
|
|
|
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 BaseCliParam<K extends string, V extends Primitive | Primitive[]> = {
|
|
11
|
+
keys: string[];
|
|
12
|
+
keyName: K;
|
|
13
|
+
type: TypeOfTypeAsString<V>;
|
|
14
|
+
description: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
options?: string[];
|
|
17
|
+
defaultValue?: V;
|
|
18
|
+
process?: (value?: string, defaultValue?: V) => V;
|
|
19
|
+
isArray?: true;
|
|
20
|
+
group?: string;
|
|
21
|
+
};
|
|
22
|
+
export type CliParam<K extends string, V extends Primitive | Primitive[]> = BaseCliParam<K, V> & {
|
|
23
|
+
name: string;
|
|
24
|
+
process: (value?: string, defaultValue?: V) => V;
|
|
25
|
+
};
|
|
26
|
+
export declare class CLIParams_Resolver<T extends BaseCliParam<string, any>[], Output extends CliParams<T> = CliParams<T>> {
|
|
27
|
+
private params;
|
|
28
|
+
static create<T extends BaseCliParam<string, any>[]>(...params: T): CLIParams_Resolver<T, CliParams<T>>;
|
|
29
|
+
constructor(params: BaseCliParam<string, any>[]);
|
|
30
|
+
/**
|
|
31
|
+
* Format current input params and return it structured by the app params type.
|
|
32
|
+
* @param inputParams current console input arguments
|
|
33
|
+
* @returns CliParamsObject
|
|
34
|
+
*/
|
|
35
|
+
resolveParamValue(inputParams?: string[]): Output;
|
|
36
|
+
/**
|
|
37
|
+
* Find the matching param by finding it's key in the current argument
|
|
38
|
+
* Go over the app params and find the CLIParam object representing it
|
|
39
|
+
* @param inputParam The current console argument being parsed
|
|
40
|
+
* @returns The CliParam or undefined if not found
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
private findMatchingParamToResolve;
|
|
44
|
+
/**
|
|
45
|
+
* Translate BaseCLIParams passed to the constructor to CLIParams
|
|
46
|
+
* @param params User input of CLI params being passed to the constructor
|
|
47
|
+
* @private
|
|
48
|
+
* @returns CLI Params filled with all mandatory data
|
|
49
|
+
*/
|
|
50
|
+
private translate;
|
|
51
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLIParams_Resolver = exports.DefaultProcessor_Number = exports.DefaultProcessor_String = exports.DefaultProcessor_Boolean = void 0;
|
|
4
|
+
const ts_common_1 = require("@nu-art/ts-common");
|
|
5
|
+
const DefaultProcessor_Boolean = (input, defaultValue) => {
|
|
6
|
+
return true;
|
|
7
|
+
};
|
|
8
|
+
exports.DefaultProcessor_Boolean = DefaultProcessor_Boolean;
|
|
9
|
+
const DefaultProcessor_String = (input, defaultValue) => {
|
|
10
|
+
if (!input || !input.length) {
|
|
11
|
+
if (!defaultValue)
|
|
12
|
+
throw new Error('expected string value');
|
|
13
|
+
return defaultValue;
|
|
14
|
+
}
|
|
15
|
+
return input;
|
|
16
|
+
};
|
|
17
|
+
exports.DefaultProcessor_String = DefaultProcessor_String;
|
|
18
|
+
const DefaultProcessor_Number = (input, defaultValue) => {
|
|
19
|
+
if (!input) {
|
|
20
|
+
if (!defaultValue)
|
|
21
|
+
throw new Error('expected number value');
|
|
22
|
+
return defaultValue;
|
|
23
|
+
}
|
|
24
|
+
if (isNaN(Number(input)))
|
|
25
|
+
throw new Error('expected number value');
|
|
26
|
+
return Number(input);
|
|
27
|
+
};
|
|
28
|
+
exports.DefaultProcessor_Number = DefaultProcessor_Number;
|
|
29
|
+
const DefaultProcessorsMapper = {
|
|
30
|
+
string: exports.DefaultProcessor_String,
|
|
31
|
+
boolean: exports.DefaultProcessor_Boolean,
|
|
32
|
+
number: exports.DefaultProcessor_Number,
|
|
33
|
+
};
|
|
34
|
+
class CLIParams_Resolver {
|
|
35
|
+
static create(...params) {
|
|
36
|
+
return new CLIParams_Resolver(params);
|
|
37
|
+
}
|
|
38
|
+
constructor(params) {
|
|
39
|
+
this.params = this.translate(params);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Format current input params and return it structured by the app params type.
|
|
43
|
+
* @param inputParams current console input arguments
|
|
44
|
+
* @returns CliParamsObject
|
|
45
|
+
*/
|
|
46
|
+
resolveParamValue(inputParams = process.argv.slice(2, process.argv.length)) {
|
|
47
|
+
return inputParams.reduce((output, inputParam) => {
|
|
48
|
+
const cliParamToResolve = this.findMatchingParamToResolve(inputParam);
|
|
49
|
+
if (!cliParamToResolve)
|
|
50
|
+
return output;
|
|
51
|
+
const value = inputParam.split('=')[1];
|
|
52
|
+
const finalValue = cliParamToResolve.process(value, cliParamToResolve.defaultValue);
|
|
53
|
+
// validate options if exits
|
|
54
|
+
if (cliParamToResolve.options && !cliParamToResolve.options.includes(value))
|
|
55
|
+
throw new Error('value not supported for this param');
|
|
56
|
+
//TODO: OPTIMIZE THIS IS PURE JS
|
|
57
|
+
const key = cliParamToResolve.keyName;
|
|
58
|
+
if (cliParamToResolve.isArray) {
|
|
59
|
+
let currentValues = output[key];
|
|
60
|
+
currentValues = (0, ts_common_1.filterDuplicates)([...currentValues !== null && currentValues !== void 0 ? currentValues : [], finalValue]);
|
|
61
|
+
output[key] = currentValues;
|
|
62
|
+
return output;
|
|
63
|
+
}
|
|
64
|
+
//if already exists and the value ain't an array warn that the value will be overridden
|
|
65
|
+
if (output[key])
|
|
66
|
+
ts_common_1.StaticLogger.logWarning(`this param does not accept multiple values, overriding prev value: ${output[key]}`);
|
|
67
|
+
//Apply single value to the object
|
|
68
|
+
output[key] = finalValue;
|
|
69
|
+
return output;
|
|
70
|
+
}, {});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Find the matching param by finding it's key in the current argument
|
|
74
|
+
* Go over the app params and find the CLIParam object representing it
|
|
75
|
+
* @param inputParam The current console argument being parsed
|
|
76
|
+
* @returns The CliParam or undefined if not found
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
findMatchingParamToResolve(inputParam) {
|
|
80
|
+
let maxKeyLength = 0;
|
|
81
|
+
let matchingParam;
|
|
82
|
+
// look for the longest fitting param in order to make sure we find the perfect match
|
|
83
|
+
this.params.forEach((param) => {
|
|
84
|
+
param.keys.forEach((key) => {
|
|
85
|
+
if (inputParam.startsWith(key) && key.length > maxKeyLength) {
|
|
86
|
+
maxKeyLength = key.length;
|
|
87
|
+
matchingParam = param;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return matchingParam;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Translate BaseCLIParams passed to the constructor to CLIParams
|
|
95
|
+
* @param params User input of CLI params being passed to the constructor
|
|
96
|
+
* @private
|
|
97
|
+
* @returns CLI Params filled with all mandatory data
|
|
98
|
+
*/
|
|
99
|
+
translate(params) {
|
|
100
|
+
return params.map(param => {
|
|
101
|
+
//If name is not defined apply key name as the param name
|
|
102
|
+
if (!param.name)
|
|
103
|
+
param.name = param.keyName;
|
|
104
|
+
//If no processor is passed apply default by type
|
|
105
|
+
if (!param.process) {
|
|
106
|
+
param.process = DefaultProcessorsMapper[param.type.split('[')[0].trim()];
|
|
107
|
+
}
|
|
108
|
+
//Determine if value is array by the param type TODO: improve this chunk of code, this is not strict enough
|
|
109
|
+
if (!(0, ts_common_1.exists)(param.isArray) && param.type.includes('[]'))
|
|
110
|
+
param.isArray = true;
|
|
111
|
+
return param;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.CLIParams_Resolver = CLIParams_Resolver;
|
package/cli/git.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Cli_Programming } from './programming';
|
|
2
|
+
import { Cli_Basic } from './basic';
|
|
3
|
+
declare const Super: new (...args: any[]) => Cli_Programming & Cli_Basic;
|
|
4
|
+
type GitCloneParams = {
|
|
5
|
+
outputFolder?: string;
|
|
6
|
+
branch?: string;
|
|
7
|
+
recursive?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type GitPushParams = {
|
|
10
|
+
remote: string;
|
|
11
|
+
branch: string;
|
|
12
|
+
tags?: boolean;
|
|
13
|
+
force?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare class Cli_Git extends Super {
|
|
16
|
+
git: {
|
|
17
|
+
clone: (url: string, options?: GitCloneParams) => Cli_Git;
|
|
18
|
+
checkout: (branch: string) => Cli_Git;
|
|
19
|
+
createTag: (tagName: string) => Cli_Git;
|
|
20
|
+
gitCommit: (commitMessage: string) => Cli_Git;
|
|
21
|
+
add: (file: string) => Cli_Git;
|
|
22
|
+
addAll: () => Cli_Git;
|
|
23
|
+
addAndCommit: (commitMessage: string) => Cli_Git;
|
|
24
|
+
push: (options?: GitPushParams) => Cli_Git;
|
|
25
|
+
pushTags: () => Cli_Git;
|
|
26
|
+
fetch: () => Cli_Git;
|
|
27
|
+
resetHard: (tag?: string) => Cli_Git;
|
|
28
|
+
getCurrentBranch: () => Cli_Git;
|
|
29
|
+
pull: (params: string) => Cli_Git;
|
|
30
|
+
merge: (mergeFrom: string) => Cli_Git;
|
|
31
|
+
createBranch: (branch: string) => Cli_Git;
|
|
32
|
+
gsui: (modules?: string) => Cli_Git;
|
|
33
|
+
status: () => Cli_Git;
|
|
34
|
+
};
|
|
35
|
+
private git_clone;
|
|
36
|
+
private git_checkout;
|
|
37
|
+
private git_createTag;
|
|
38
|
+
private git_gitCommit;
|
|
39
|
+
private git_add;
|
|
40
|
+
private git_addAll;
|
|
41
|
+
private git_addAndCommit;
|
|
42
|
+
private git_push;
|
|
43
|
+
private git_pushTags;
|
|
44
|
+
private git_fetch;
|
|
45
|
+
private git_resetHard;
|
|
46
|
+
private git_getCurrentBranch;
|
|
47
|
+
private git_pull;
|
|
48
|
+
private git_merge;
|
|
49
|
+
private git_createBranch;
|
|
50
|
+
private git_gsui;
|
|
51
|
+
private git_status;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
package/cli/git.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Cli_Git = void 0;
|
|
4
|
+
const programming_1 = require("./programming");
|
|
5
|
+
const class_merger_1 = require("../core/class-merger");
|
|
6
|
+
const basic_1 = require("./basic");
|
|
7
|
+
const Super = (0, class_merger_1.MergeClass)(programming_1.Cli_Programming, basic_1.Cli_Basic);
|
|
8
|
+
class Cli_Git extends Super {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.git = {
|
|
12
|
+
clone: this.git_clone,
|
|
13
|
+
checkout: this.git_checkout,
|
|
14
|
+
createTag: this.git_createTag,
|
|
15
|
+
gitCommit: this.git_gitCommit,
|
|
16
|
+
add: this.git_add,
|
|
17
|
+
addAll: this.git_addAll,
|
|
18
|
+
addAndCommit: this.git_addAndCommit,
|
|
19
|
+
push: this.git_push,
|
|
20
|
+
pushTags: this.git_pushTags,
|
|
21
|
+
fetch: this.git_fetch,
|
|
22
|
+
resetHard: this.git_resetHard,
|
|
23
|
+
getCurrentBranch: this.git_getCurrentBranch,
|
|
24
|
+
pull: this.git_pull,
|
|
25
|
+
merge: this.git_merge,
|
|
26
|
+
createBranch: this.git_createBranch,
|
|
27
|
+
gsui: this.git_gsui,
|
|
28
|
+
status: this.git_status,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
git_clone(url, options) {
|
|
32
|
+
const branch = `${(options === null || options === void 0 ? void 0 : options.branch) ? ` -b ${options === null || options === void 0 ? void 0 : options.branch}` : ''}`;
|
|
33
|
+
const recursive = `${(options === null || options === void 0 ? void 0 : options.recursive) ? ` --recursive` : ''}`;
|
|
34
|
+
const outputFolder = `${(options === null || options === void 0 ? void 0 : options.outputFolder) ? ` ${options.outputFolder}` : ''}`;
|
|
35
|
+
this.cli.append(`git clone${recursive}${branch} ${url}${outputFolder}`);
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
git_checkout(branch) {
|
|
39
|
+
this.cli.append(`git checkout ${branch}`);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
git_createTag(tagName) {
|
|
43
|
+
this.cli.append(`git tag -f ${tagName}`);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
git_gitCommit(commitMessage) {
|
|
47
|
+
this.cli.append(`git commit -m "${commitMessage}"`);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
git_add(file) {
|
|
51
|
+
this.cli.append(`git add "${file}"`);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
git_addAll() {
|
|
55
|
+
this.cli.append(`git add .`);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
git_addAndCommit(commitMessage) {
|
|
59
|
+
this.cli.append(`git commit -am "${commitMessage}"`);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
git_push(options) {
|
|
63
|
+
this.cli.append(`git push ${options === null || options === void 0 ? void 0 : options.remote} ${options === null || options === void 0 ? void 0 : options.branch}`);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
git_pushTags() {
|
|
67
|
+
this.cli.append('git push --tags --force');
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
git_fetch() {
|
|
71
|
+
this.cli.append('git fetch');
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
git_resetHard(tag = '') {
|
|
75
|
+
this.cli.append('git reset --hard ${tag}');
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
git_getCurrentBranch() {
|
|
79
|
+
this.cli.append('git status | grep "On branch" | sed -E "s');
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
git_pull(params) {
|
|
83
|
+
this.cli.append('git pull ${params}');
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
git_merge(mergeFrom) {
|
|
87
|
+
this.cli.append(`git merge ${mergeFrom}`);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
git_createBranch(branch) {
|
|
91
|
+
this.cli.append(`git checkout - b ${branch}`);
|
|
92
|
+
this.cli.append(`git push-- set -upstream origin ${branch}`);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
git_gsui(modules = '') {
|
|
96
|
+
this.cli.append('git submodule update --recursive --init ${modules}');
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
git_status() {
|
|
100
|
+
this.cli.append('git status');
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.Cli_Git = Cli_Git;
|
package/cli/nvm.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CliWrapper, Commando, CommandoInteractive } from '../core/cli';
|
|
2
|
+
import { Constructor, Logger } from '@nu-art/ts-common';
|
|
3
|
+
export declare class Cli_NVM extends Logger {
|
|
4
|
+
private _expectedVersion;
|
|
5
|
+
private _homeEnvVar;
|
|
6
|
+
constructor();
|
|
7
|
+
get homeEnvVar(): string;
|
|
8
|
+
set homeEnvVar(value: string);
|
|
9
|
+
get expectedVersion(): string;
|
|
10
|
+
set expectedVersion(value: string);
|
|
11
|
+
install: () => Promise<boolean | this | undefined>;
|
|
12
|
+
isInstalled: () => boolean;
|
|
13
|
+
getRequiredNode_Version: () => Promise<string>;
|
|
14
|
+
installRequiredVersionIfNeeded: () => Promise<boolean>;
|
|
15
|
+
getInstalledNode_Versions: () => Promise<(string | undefined)[]>;
|
|
16
|
+
private getVersion;
|
|
17
|
+
uninstall: () => Promise<void>;
|
|
18
|
+
private installVersion;
|
|
19
|
+
createInteractiveCommando<T extends Constructor<CliWrapper>[]>(...plugins: T): CommandoInteractive & Commando & import("../core/class-merger").MergeTypes<T>;
|
|
20
|
+
createCommando<T extends Constructor<CliWrapper>[]>(...plugins: T): Commando & import("../core/class-merger").MergeTypes<T>;
|
|
21
|
+
}
|
|
22
|
+
export declare const NVM: Cli_NVM;
|
package/cli/nvm.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NVM = exports.Cli_NVM = void 0;
|
|
4
|
+
const programming_1 = require("./programming");
|
|
5
|
+
const basic_1 = require("./basic");
|
|
6
|
+
const cli_1 = require("../core/cli");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const tools_1 = require("../core/tools");
|
|
11
|
+
const ts_common_1 = require("@nu-art/ts-common");
|
|
12
|
+
const CONST__FILE_NVMRC = '.nvmrc';
|
|
13
|
+
class Cli_NVM extends ts_common_1.Logger {
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this._expectedVersion = '0.35.3';
|
|
17
|
+
this._homeEnvVar = '$NVM_DIR';
|
|
18
|
+
this.install = async () => {
|
|
19
|
+
if (this.isInstalled()) {
|
|
20
|
+
const version = (await this.getVersion()).stdout.trim();
|
|
21
|
+
if (this._expectedVersion === version)
|
|
22
|
+
return;
|
|
23
|
+
await this.uninstall();
|
|
24
|
+
}
|
|
25
|
+
await cli_1.Commando.create()
|
|
26
|
+
.append(` curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/v${this._expectedVersion}/install.sh" | bash`)
|
|
27
|
+
.execute();
|
|
28
|
+
const rcFile = path.resolve(process.env['HOME'], '.bashrc');
|
|
29
|
+
let rcFileContent = '';
|
|
30
|
+
if (fs.existsSync(rcFile)) {
|
|
31
|
+
rcFileContent = await fs_1.promises.readFile(rcFile, { encoding: 'utf8' });
|
|
32
|
+
return rcFileContent.includes('NVM_DIR');
|
|
33
|
+
}
|
|
34
|
+
rcFileContent = `${rcFileContent}\n${rcFileContent.endsWith('\n') ? '' : '\n'}`;
|
|
35
|
+
rcFileContent += `# generated NVM - start\n`;
|
|
36
|
+
rcFileContent += `echo 'export NVM_DIR="$HOME/.nvm"'\n`;
|
|
37
|
+
rcFileContent += `echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm'\n`;
|
|
38
|
+
rcFileContent += `echo '[ -s "$NVM_DIR/bash_completion" ] && \\. "$NVM_DIR/bash_completion" # This loads nvm bash_completion'\n`;
|
|
39
|
+
rcFileContent += `# generated NVM - end\n`;
|
|
40
|
+
await fs_1.promises.writeFile(rcFile, rcFileContent, { encoding: 'utf8' });
|
|
41
|
+
return this;
|
|
42
|
+
};
|
|
43
|
+
this.isInstalled = () => !!process.env[this._homeEnvVar] && fs.existsSync(process.env[this._homeEnvVar]);
|
|
44
|
+
this.getRequiredNode_Version = async () => {
|
|
45
|
+
const absolutePathToNvmrcFile = path.resolve(CONST__FILE_NVMRC);
|
|
46
|
+
if (!fs.existsSync(absolutePathToNvmrcFile))
|
|
47
|
+
throw new Error(`couldn't find .nvmrc file at: ${absolutePathToNvmrcFile}`);
|
|
48
|
+
const content = await fs_1.promises.readFile(absolutePathToNvmrcFile, { encoding: 'utf-8' });
|
|
49
|
+
return content.trim();
|
|
50
|
+
};
|
|
51
|
+
this.installRequiredVersionIfNeeded = async () => {
|
|
52
|
+
const requiredVersion = await this.getRequiredNode_Version();
|
|
53
|
+
const installedVersions = await this.getInstalledNode_Versions();
|
|
54
|
+
this.logDebug('Found versions:', installedVersions);
|
|
55
|
+
if (installedVersions.includes(requiredVersion))
|
|
56
|
+
return false;
|
|
57
|
+
await this.installVersion(requiredVersion);
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
this.getInstalledNode_Versions = async () => {
|
|
61
|
+
function extractInstalledVersions(rawOutput) {
|
|
62
|
+
const cleanedOutput = (0, tools_1.removeAnsiCodes)(rawOutput);
|
|
63
|
+
const lines = cleanedOutput.split('\n');
|
|
64
|
+
const filteredVersionLines = lines
|
|
65
|
+
.filter(line => !!line && line.match(/v\d+\.\d+\.\d+/) && !line.includes('N/A'));
|
|
66
|
+
return (0, ts_common_1.filterDuplicates)(filteredVersionLines
|
|
67
|
+
.map(line => { var _a; return (_a = line.match(/v(\d+\.\d+\.\d+)/)) === null || _a === void 0 ? void 0 : _a[1]; }));
|
|
68
|
+
}
|
|
69
|
+
return extractInstalledVersions((await this.createCommando()
|
|
70
|
+
.append('nvm ls')
|
|
71
|
+
.execute()).stdout);
|
|
72
|
+
};
|
|
73
|
+
this.uninstall = async () => {
|
|
74
|
+
this.logDebug('Uninstalling PNPM');
|
|
75
|
+
const absolutePathToNVM_Home = process.env[this._homeEnvVar];
|
|
76
|
+
if (!absolutePathToNVM_Home)
|
|
77
|
+
return;
|
|
78
|
+
fs.rmSync(absolutePathToNVM_Home, { recursive: true, force: true });
|
|
79
|
+
};
|
|
80
|
+
this.installVersion = async (requiredVersion) => {
|
|
81
|
+
requiredVersion !== null && requiredVersion !== void 0 ? requiredVersion : (requiredVersion = await this.getRequiredNode_Version());
|
|
82
|
+
this.logDebug(`Installing version: ${requiredVersion}`);
|
|
83
|
+
return this.createCommando().append(`nvm install ${requiredVersion}`).execute();
|
|
84
|
+
};
|
|
85
|
+
this.setMinLevel(ts_common_1.LogLevel.Verbose);
|
|
86
|
+
}
|
|
87
|
+
get homeEnvVar() {
|
|
88
|
+
return this._homeEnvVar;
|
|
89
|
+
}
|
|
90
|
+
set homeEnvVar(value) {
|
|
91
|
+
this._homeEnvVar = value;
|
|
92
|
+
}
|
|
93
|
+
get expectedVersion() {
|
|
94
|
+
return this._expectedVersion;
|
|
95
|
+
}
|
|
96
|
+
set expectedVersion(value) {
|
|
97
|
+
this._expectedVersion = value;
|
|
98
|
+
}
|
|
99
|
+
async getVersion() {
|
|
100
|
+
const commando = cli_1.Commando.create(programming_1.Cli_Programming, basic_1.Cli_Basic);
|
|
101
|
+
return commando.if('[[ -x "$(command -v nvm)" ]]', (commando) => {
|
|
102
|
+
commando.cli.append('nvm --version');
|
|
103
|
+
}).execute();
|
|
104
|
+
}
|
|
105
|
+
createInteractiveCommando(...plugins) {
|
|
106
|
+
return cli_1.CommandoInteractive.create(...plugins).debug()
|
|
107
|
+
.append('export NVM_DIR="$HOME/.nvm"')
|
|
108
|
+
.append('[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm')
|
|
109
|
+
.append('[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion')
|
|
110
|
+
.append('nvm use');
|
|
111
|
+
}
|
|
112
|
+
createCommando(...plugins) {
|
|
113
|
+
return cli_1.Commando.create(...plugins)
|
|
114
|
+
.append('export NVM_DIR="$HOME/.nvm"')
|
|
115
|
+
.append('[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm')
|
|
116
|
+
.append('[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.Cli_NVM = Cli_NVM;
|
|
120
|
+
exports.NVM = new Cli_NVM();
|
package/cli/pnpm.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Commando } from '../core/cli';
|
|
2
|
+
import { Logger } from '@nu-art/ts-common';
|
|
3
|
+
export declare class Cli_PNPM extends Logger {
|
|
4
|
+
private _expectedVersion;
|
|
5
|
+
private _homeEnvVar;
|
|
6
|
+
constructor();
|
|
7
|
+
get homeEnvVar(): string;
|
|
8
|
+
set homeEnvVar(value: string);
|
|
9
|
+
get expectedVersion(): string;
|
|
10
|
+
set expectedVersion(value: string);
|
|
11
|
+
install: (commando?: Commando) => Promise<this | undefined>;
|
|
12
|
+
isInstalled: () => boolean;
|
|
13
|
+
installPackages: (commando?: Commando) => Promise<this>;
|
|
14
|
+
private getVersion;
|
|
15
|
+
uninstall: () => Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Asynchronously creates a workspace file with a list of packages.
|
|
18
|
+
* Each package is listed under the 'packages:' section in the file.
|
|
19
|
+
*
|
|
20
|
+
* @param listOfLibs An array of library names to include in the workspace.
|
|
21
|
+
* @param pathToWorkspaceFile The filesystem path where the workspace file will be written.
|
|
22
|
+
* @example
|
|
23
|
+
* await createWorkspace(['pack1', 'pack2'], './path/to/workspace.yaml');
|
|
24
|
+
*/
|
|
25
|
+
createWorkspace: (listOfLibs: string[], pathToWorkspaceFile?: string) => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare const PNPM: Cli_PNPM;
|
package/cli/pnpm.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PNPM = exports.Cli_PNPM = void 0;
|
|
4
|
+
const programming_1 = require("./programming");
|
|
5
|
+
const basic_1 = require("./basic");
|
|
6
|
+
const cli_1 = require("../core/cli");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const tools_1 = require("../core/tools");
|
|
9
|
+
const ts_common_1 = require("@nu-art/ts-common");
|
|
10
|
+
class Cli_PNPM extends ts_common_1.Logger {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this._expectedVersion = '8.15.5';
|
|
14
|
+
this._homeEnvVar = 'PNPM_HOME';
|
|
15
|
+
this.install = async (commando) => {
|
|
16
|
+
if (this.isInstalled()) {
|
|
17
|
+
const version = (await this.getVersion()).stdout.trim();
|
|
18
|
+
if (this._expectedVersion === version)
|
|
19
|
+
return;
|
|
20
|
+
await this.uninstall();
|
|
21
|
+
}
|
|
22
|
+
this.logDebug(`installing PNPM version ${this._expectedVersion}`);
|
|
23
|
+
await (commando !== null && commando !== void 0 ? commando : cli_1.Commando.create())
|
|
24
|
+
.append(`curl -fsSL "https://get.pnpm.io/install.sh" | env PNPM_VERSION=${this._expectedVersion} sh -`)
|
|
25
|
+
.execute();
|
|
26
|
+
return this;
|
|
27
|
+
};
|
|
28
|
+
this.isInstalled = () => !!process.env[this._homeEnvVar];
|
|
29
|
+
this.installPackages = async (commando) => {
|
|
30
|
+
await (commando !== null && commando !== void 0 ? commando : cli_1.Commando.create())
|
|
31
|
+
.append(`pnpm install -f --no-frozen-lockfile`)
|
|
32
|
+
.execute();
|
|
33
|
+
return this;
|
|
34
|
+
};
|
|
35
|
+
this.uninstall = async () => {
|
|
36
|
+
this.logDebug('Uninstalling PNPM');
|
|
37
|
+
const absolutePathToPNPM_Home = process.env[this._homeEnvVar];
|
|
38
|
+
if (!absolutePathToPNPM_Home)
|
|
39
|
+
return;
|
|
40
|
+
return fs_1.promises.rm(absolutePathToPNPM_Home, { recursive: true, force: true });
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Asynchronously creates a workspace file with a list of packages.
|
|
44
|
+
* Each package is listed under the 'packages:' section in the file.
|
|
45
|
+
*
|
|
46
|
+
* @param listOfLibs An array of library names to include in the workspace.
|
|
47
|
+
* @param pathToWorkspaceFile The filesystem path where the workspace file will be written.
|
|
48
|
+
* @example
|
|
49
|
+
* await createWorkspace(['pack1', 'pack2'], './path/to/workspace.yaml');
|
|
50
|
+
*/
|
|
51
|
+
this.createWorkspace = async (listOfLibs, pathToWorkspaceFile = (0, tools_1.convertToFullPath)('./pnpm-workspace.yaml')) => {
|
|
52
|
+
try {
|
|
53
|
+
let workspace = 'packages:\n';
|
|
54
|
+
listOfLibs.forEach(lib => {
|
|
55
|
+
workspace += ` - '${lib}'\n`;
|
|
56
|
+
});
|
|
57
|
+
await fs_1.promises.writeFile(pathToWorkspaceFile, workspace, 'utf8');
|
|
58
|
+
this.logDebug(`Workspace file created at ${pathToWorkspaceFile}`);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
this.logError('Failed to create workspace file:', error);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
this.setMinLevel(ts_common_1.LogLevel.Verbose);
|
|
65
|
+
}
|
|
66
|
+
get homeEnvVar() {
|
|
67
|
+
return this._homeEnvVar;
|
|
68
|
+
}
|
|
69
|
+
set homeEnvVar(value) {
|
|
70
|
+
this._homeEnvVar = value;
|
|
71
|
+
}
|
|
72
|
+
get expectedVersion() {
|
|
73
|
+
return this._expectedVersion;
|
|
74
|
+
}
|
|
75
|
+
set expectedVersion(value) {
|
|
76
|
+
this._expectedVersion = value;
|
|
77
|
+
}
|
|
78
|
+
async getVersion() {
|
|
79
|
+
const commando = cli_1.Commando.create(programming_1.Cli_Programming, basic_1.Cli_Basic);
|
|
80
|
+
return commando.if('[[ -x "$(command -v pnpm)" ]]', (commando) => {
|
|
81
|
+
commando.cli.append('pnpm --version');
|
|
82
|
+
}).execute();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.Cli_PNPM = Cli_PNPM;
|
|
86
|
+
exports.PNPM = new Cli_PNPM();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CliBlock, CliWrapper } from '../core/cli';
|
|
2
|
+
export declare class Cli_Programming extends CliWrapper {
|
|
3
|
+
/**
|
|
4
|
+
* Constructs an if-else conditional command structure.
|
|
5
|
+
* @param {string} condition - The condition for the if statement.
|
|
6
|
+
* @param {CliBlock} ifBlock - Block of commands to execute if the condition is true.
|
|
7
|
+
* @param {CliBlock} [elseBlock] - Optional block of commands to execute if the condition is false.
|
|
8
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
9
|
+
*/
|
|
10
|
+
if(condition: string, ifBlock: CliBlock<this>, elseBlock?: CliBlock<this>): this;
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a for loop command structure.
|
|
13
|
+
* @param {string} varName - The variable name used in the loop.
|
|
14
|
+
* @param {string | string[]} arrayNameOrValues - The array name or array of values to iterate over.
|
|
15
|
+
* @param {CliBlock} loop - Block of commands to execute in each iteration of the loop.
|
|
16
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
17
|
+
*/
|
|
18
|
+
for(varName: string, arrayNameOrValues: string | string[], loop: CliBlock<this>): this;
|
|
19
|
+
/**
|
|
20
|
+
* Appends a 'continue' command for loop control.
|
|
21
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
22
|
+
*/
|
|
23
|
+
continue(): this;
|
|
24
|
+
/**
|
|
25
|
+
* Appends a 'break' command for loop control.
|
|
26
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
27
|
+
*/
|
|
28
|
+
break(): this;
|
|
29
|
+
/**
|
|
30
|
+
* Appends a 'return' command for exiting a function or script.
|
|
31
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
32
|
+
*/
|
|
33
|
+
return(): this;
|
|
34
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Cli_Programming = void 0;
|
|
4
|
+
const cli_1 = require("../core/cli");
|
|
5
|
+
class Cli_Programming extends cli_1.CliWrapper {
|
|
6
|
+
/**
|
|
7
|
+
* Constructs an if-else conditional command structure.
|
|
8
|
+
* @param {string} condition - The condition for the if statement.
|
|
9
|
+
* @param {CliBlock} ifBlock - Block of commands to execute if the condition is true.
|
|
10
|
+
* @param {CliBlock} [elseBlock] - Optional block of commands to execute if the condition is false.
|
|
11
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
12
|
+
*/
|
|
13
|
+
if(condition, ifBlock, elseBlock) {
|
|
14
|
+
this.cli.append(`if ${condition}; then`);
|
|
15
|
+
this.cli.indentIn();
|
|
16
|
+
ifBlock(this);
|
|
17
|
+
if (elseBlock) {
|
|
18
|
+
this.cli.indentOut();
|
|
19
|
+
this.cli.append('else');
|
|
20
|
+
this.cli.indentIn();
|
|
21
|
+
elseBlock(this);
|
|
22
|
+
}
|
|
23
|
+
this.cli.indentOut();
|
|
24
|
+
this.cli.append('fi');
|
|
25
|
+
this.cli.emptyLine();
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Constructs a for loop command structure.
|
|
30
|
+
* @param {string} varName - The variable name used in the loop.
|
|
31
|
+
* @param {string | string[]} arrayNameOrValues - The array name or array of values to iterate over.
|
|
32
|
+
* @param {CliBlock} loop - Block of commands to execute in each iteration of the loop.
|
|
33
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
34
|
+
*/
|
|
35
|
+
for(varName, arrayNameOrValues, loop) {
|
|
36
|
+
if (typeof arrayNameOrValues === 'string') {
|
|
37
|
+
this.cli.append(`for ${varName} in "\${${arrayNameOrValues}[@]}"; do`);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const values = arrayNameOrValues.map(value => `"${value}"`).join(' ');
|
|
41
|
+
this.cli.append(`for ${varName} in ${values}; do`);
|
|
42
|
+
}
|
|
43
|
+
this.cli.indentIn();
|
|
44
|
+
loop(this);
|
|
45
|
+
this.cli.indentOut();
|
|
46
|
+
this.cli.append('done');
|
|
47
|
+
this.cli.emptyLine();
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Appends a 'continue' command for loop control.
|
|
52
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
53
|
+
*/
|
|
54
|
+
continue() {
|
|
55
|
+
this.cli.append('continue');
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Appends a 'break' command for loop control.
|
|
60
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
61
|
+
*/
|
|
62
|
+
break() {
|
|
63
|
+
this.cli.append('break');
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Appends a 'return' command for exiting a function or script.
|
|
68
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
69
|
+
*/
|
|
70
|
+
return() {
|
|
71
|
+
this.cli.append('return');
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.Cli_Programming = Cli_Programming;
|
package/core/CliError.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
@@ -0,0 +1,5 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateMergedInstance = exports.MergeClass = void 0;
|
|
4
|
+
function MergeClass(...plugins) {
|
|
5
|
+
class SuperClass {
|
|
6
|
+
constructor(...args) {
|
|
7
|
+
plugins.forEach(plugin => {
|
|
8
|
+
Object.getOwnPropertyNames(plugin.prototype).forEach(name => {
|
|
9
|
+
const prop = Object.getOwnPropertyDescriptor(plugin.prototype, name);
|
|
10
|
+
if (prop) {
|
|
11
|
+
Object.defineProperty(this, name, prop);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return SuperClass;
|
|
18
|
+
}
|
|
19
|
+
exports.MergeClass = MergeClass;
|
|
20
|
+
function CreateMergedInstance(...plugins) {
|
|
21
|
+
const SuperClass = MergeClass(...plugins);
|
|
22
|
+
return new SuperClass();
|
|
23
|
+
}
|
|
24
|
+
exports.CreateMergedInstance = CreateMergedInstance;
|
package/core/cli.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { ExecOptions } from 'child_process';
|
|
4
|
+
import { Constructor, Logger } from '@nu-art/ts-common';
|
|
5
|
+
export type CliBlock<Cli extends CliWrapper> = (cli: Cli) => void;
|
|
6
|
+
export type CliOptions = ExecOptions & {
|
|
7
|
+
encoding: BufferEncoding | string | null;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Type definition for options used in Cli class.
|
|
11
|
+
*/
|
|
12
|
+
type Options = {
|
|
13
|
+
newlineDelimiter: string;
|
|
14
|
+
indentation: number;
|
|
15
|
+
};
|
|
16
|
+
export declare class BaseCLI extends Logger {
|
|
17
|
+
protected commands: string[];
|
|
18
|
+
private indentation;
|
|
19
|
+
protected _debug: boolean;
|
|
20
|
+
protected option: Options;
|
|
21
|
+
/**
|
|
22
|
+
* Constructs a CLI instance with given options.
|
|
23
|
+
* @param {Options} options - Configuration options for the CLI instance.
|
|
24
|
+
*/
|
|
25
|
+
constructor(options?: Partial<Options>);
|
|
26
|
+
protected getIndentation: () => string;
|
|
27
|
+
readonly indentIn: () => void;
|
|
28
|
+
readonly indentOut: () => void;
|
|
29
|
+
debug(debug?: boolean): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Appends a command or a Cli instance to the command list with proper indentation.
|
|
32
|
+
* @param {string} command - The command or Cli instance to append.
|
|
33
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
34
|
+
*/
|
|
35
|
+
readonly append: (command: string) => this;
|
|
36
|
+
}
|
|
37
|
+
export declare class CliInteractive extends BaseCLI {
|
|
38
|
+
private shell;
|
|
39
|
+
constructor();
|
|
40
|
+
execute: () => Promise<void>;
|
|
41
|
+
endInteractive: () => void;
|
|
42
|
+
}
|
|
43
|
+
export declare class Cli extends BaseCLI {
|
|
44
|
+
private cliOptions;
|
|
45
|
+
/**
|
|
46
|
+
* Executes the accumulated commands in the command list.
|
|
47
|
+
* @returns {Promise<string>} A promise that resolves with the standard output of the executed command.
|
|
48
|
+
*/
|
|
49
|
+
execute: () => Promise<{
|
|
50
|
+
stdout: string;
|
|
51
|
+
stderr: string;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Appends an empty line to the script for readability.
|
|
55
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
56
|
+
*/
|
|
57
|
+
emptyLine(): this;
|
|
58
|
+
setShell(shell: string): void;
|
|
59
|
+
setOptions(options: Partial<CliOptions>): void;
|
|
60
|
+
}
|
|
61
|
+
export declare class CliWrapper {
|
|
62
|
+
cli: Cli;
|
|
63
|
+
}
|
|
64
|
+
export declare class Commando {
|
|
65
|
+
cli: Cli;
|
|
66
|
+
static create<T extends Constructor<CliWrapper>[]>(...plugins: T): Commando & import("./class-merger").MergeTypes<T>;
|
|
67
|
+
setShell: (shell: string) => this;
|
|
68
|
+
setOptions: (options: ExecOptions) => this;
|
|
69
|
+
debug: (debug?: boolean) => this;
|
|
70
|
+
append: (command: string) => this;
|
|
71
|
+
execute: () => Promise<{
|
|
72
|
+
stdout: string;
|
|
73
|
+
stderr: string;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* Executes a given file.
|
|
77
|
+
* @param {string} filePath - The path to the file to execute.
|
|
78
|
+
* @param {string} [interpreter] - Optional. The interpreter to use for executing the file (e.g., "python", "bash").
|
|
79
|
+
* If not provided, the file is executed directly.
|
|
80
|
+
*
|
|
81
|
+
* @returns {Cli} - The script execution output.
|
|
82
|
+
*/
|
|
83
|
+
executeFile: (filePath: string, interpreter?: string) => Promise<{
|
|
84
|
+
stdout: string;
|
|
85
|
+
stderr: string;
|
|
86
|
+
}>;
|
|
87
|
+
executeRemoteFile: (pathToFile: string, interpreter: string) => Promise<{
|
|
88
|
+
stdout: string;
|
|
89
|
+
stderr: string;
|
|
90
|
+
}>;
|
|
91
|
+
private constructor();
|
|
92
|
+
}
|
|
93
|
+
export declare class CommandoInteractive {
|
|
94
|
+
cli: CliInteractive;
|
|
95
|
+
static create<T extends Constructor<CliWrapper>[]>(...plugins: T): CommandoInteractive & Commando & import("./class-merger").MergeTypes<T>;
|
|
96
|
+
close: () => this;
|
|
97
|
+
}
|
|
98
|
+
export {};
|
package/core/cli.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandoInteractive = exports.Commando = exports.CliWrapper = exports.Cli = exports.CliInteractive = exports.BaseCLI = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const class_merger_1 = require("./class-merger");
|
|
6
|
+
const CliError_1 = require("./CliError");
|
|
7
|
+
const ts_common_1 = require("@nu-art/ts-common");
|
|
8
|
+
const node_child_process_1 = require("node:child_process");
|
|
9
|
+
/**
|
|
10
|
+
* Default options for Cli class instances.
|
|
11
|
+
*/
|
|
12
|
+
const defaultOptions = {
|
|
13
|
+
newlineDelimiter: '\n',
|
|
14
|
+
indentation: 2,
|
|
15
|
+
};
|
|
16
|
+
class BaseCLI extends ts_common_1.Logger {
|
|
17
|
+
/**
|
|
18
|
+
* Constructs a CLI instance with given options.
|
|
19
|
+
* @param {Options} options - Configuration options for the CLI instance.
|
|
20
|
+
*/
|
|
21
|
+
constructor(options = defaultOptions) {
|
|
22
|
+
super();
|
|
23
|
+
this.commands = [];
|
|
24
|
+
this.indentation = 0;
|
|
25
|
+
this._debug = false;
|
|
26
|
+
this.getIndentation = () => {
|
|
27
|
+
return ' '.repeat(this.option.indentation * this.indentation);
|
|
28
|
+
};
|
|
29
|
+
this.indentIn = () => {
|
|
30
|
+
this.indentation++;
|
|
31
|
+
};
|
|
32
|
+
this.indentOut = () => {
|
|
33
|
+
this.indentation++;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Appends a command or a Cli instance to the command list with proper indentation.
|
|
37
|
+
* @param {string} command - The command or Cli instance to append.
|
|
38
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
39
|
+
*/
|
|
40
|
+
this.append = (command) => {
|
|
41
|
+
this.commands.push(`${this.getIndentation()}${command}`);
|
|
42
|
+
return this;
|
|
43
|
+
};
|
|
44
|
+
this.setMinLevel(ts_common_1.LogLevel.Verbose);
|
|
45
|
+
this.option = options;
|
|
46
|
+
}
|
|
47
|
+
debug(debug) {
|
|
48
|
+
this._debug = debug !== null && debug !== void 0 ? debug : !this._debug;
|
|
49
|
+
return this._debug;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.BaseCLI = BaseCLI;
|
|
53
|
+
class CliInteractive extends BaseCLI {
|
|
54
|
+
constructor() {
|
|
55
|
+
super();
|
|
56
|
+
this.execute = async () => {
|
|
57
|
+
const command = this.commands.join(this.option.newlineDelimiter);
|
|
58
|
+
if (this._debug)
|
|
59
|
+
this.logDebug(`executing: `, `"""\n${command}\n"""`);
|
|
60
|
+
this.shell.stdin.write(command + this.option.newlineDelimiter, 'utf-8', (err) => {
|
|
61
|
+
console.log('GOT HERE');
|
|
62
|
+
if (err)
|
|
63
|
+
console.error(err);
|
|
64
|
+
});
|
|
65
|
+
this.commands = [];
|
|
66
|
+
};
|
|
67
|
+
this.endInteractive = () => {
|
|
68
|
+
this.shell.stdin.end();
|
|
69
|
+
};
|
|
70
|
+
this.shell = (0, node_child_process_1.spawn)('/bin/bash', {});
|
|
71
|
+
// Handle shell output (stdout)
|
|
72
|
+
const printer = (data) => {
|
|
73
|
+
const message = data.toString().trim();
|
|
74
|
+
if (!message.length)
|
|
75
|
+
return;
|
|
76
|
+
console.log(message);
|
|
77
|
+
};
|
|
78
|
+
this.shell.stdout.on('data', printer);
|
|
79
|
+
this.shell.stderr.on('data', printer);
|
|
80
|
+
// Handle shell errors (stderr)
|
|
81
|
+
this.shell.on('data', printer);
|
|
82
|
+
// Handle shell exit
|
|
83
|
+
this.shell.on('close', (code) => {
|
|
84
|
+
console.log(`child process exited with code ${code}`);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.CliInteractive = CliInteractive;
|
|
89
|
+
class Cli extends BaseCLI {
|
|
90
|
+
constructor() {
|
|
91
|
+
super(...arguments);
|
|
92
|
+
this.cliOptions = { shell: '/bin/bash' };
|
|
93
|
+
/**
|
|
94
|
+
* Executes the accumulated commands in the command list.
|
|
95
|
+
* @returns {Promise<string>} A promise that resolves with the standard output of the executed command.
|
|
96
|
+
*/
|
|
97
|
+
this.execute = async () => {
|
|
98
|
+
const command = this.commands.join(this.option.newlineDelimiter);
|
|
99
|
+
if (this._debug)
|
|
100
|
+
this.logDebug(`executing: `, `"""\n${command}\n"""`);
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
(0, child_process_1.exec)(command, this.cliOptions, (error, stdout, stderr) => {
|
|
103
|
+
this.commands = [];
|
|
104
|
+
if (error) {
|
|
105
|
+
reject(new CliError_1.CliError(`executing:\n${command}\n`, stdout, stderr, error));
|
|
106
|
+
}
|
|
107
|
+
if (stderr)
|
|
108
|
+
reject(stderr);
|
|
109
|
+
if (stdout) {
|
|
110
|
+
console.log(stdout);
|
|
111
|
+
this.logVerbose(stdout);
|
|
112
|
+
}
|
|
113
|
+
if (stderr)
|
|
114
|
+
this.logVerboseBold(stderr);
|
|
115
|
+
resolve({ stdout, stderr });
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Appends an empty line to the script for readability.
|
|
122
|
+
* @returns {this} - The Cli instance for method chaining.
|
|
123
|
+
*/
|
|
124
|
+
emptyLine() {
|
|
125
|
+
this.append('');
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
setShell(shell) {
|
|
129
|
+
(this.cliOptions || (this.cliOptions = {})).shell = shell;
|
|
130
|
+
}
|
|
131
|
+
setOptions(options) {
|
|
132
|
+
this.cliOptions = options;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.Cli = Cli;
|
|
136
|
+
class CliWrapper {
|
|
137
|
+
}
|
|
138
|
+
exports.CliWrapper = CliWrapper;
|
|
139
|
+
class Commando {
|
|
140
|
+
static create(...plugins) {
|
|
141
|
+
const _commando = (0, class_merger_1.CreateMergedInstance)(...plugins);
|
|
142
|
+
const commando = _commando;
|
|
143
|
+
const cli = new Cli();
|
|
144
|
+
cli.setMinLevel(ts_common_1.LogLevel.Verbose);
|
|
145
|
+
commando.cli = cli;
|
|
146
|
+
commando.execute = () => commando.cli.execute();
|
|
147
|
+
commando.debug = (debug) => {
|
|
148
|
+
commando.cli.debug(debug);
|
|
149
|
+
return commando;
|
|
150
|
+
};
|
|
151
|
+
commando.setOptions = (options) => {
|
|
152
|
+
commando.cli.setOptions(options);
|
|
153
|
+
return commando;
|
|
154
|
+
};
|
|
155
|
+
commando.setShell = (shell) => {
|
|
156
|
+
commando.cli.setShell(shell);
|
|
157
|
+
return commando;
|
|
158
|
+
};
|
|
159
|
+
commando.executeFile = (filePath, interpreter) => {
|
|
160
|
+
let command = filePath;
|
|
161
|
+
// If an interpreter is provided, prefix the command with it.
|
|
162
|
+
if (interpreter) {
|
|
163
|
+
command = `${interpreter} ${filePath}`;
|
|
164
|
+
}
|
|
165
|
+
return new Cli().append(command).execute();
|
|
166
|
+
};
|
|
167
|
+
commando.executeRemoteFile = (pathToFile, interpreter) => {
|
|
168
|
+
return new Cli().append(`curl -o- "${pathToFile}" | ${interpreter}`).execute();
|
|
169
|
+
};
|
|
170
|
+
commando.append = (command) => {
|
|
171
|
+
commando.cli.append(command);
|
|
172
|
+
return commando;
|
|
173
|
+
};
|
|
174
|
+
return commando;
|
|
175
|
+
}
|
|
176
|
+
constructor() {
|
|
177
|
+
this.setShell = (shell) => this;
|
|
178
|
+
this.setOptions = (options) => this;
|
|
179
|
+
this.debug = (debug) => this;
|
|
180
|
+
this.append = (command) => this;
|
|
181
|
+
this.execute = async () => ({ stdout: '', stderr: '', }); // placeholder
|
|
182
|
+
/**
|
|
183
|
+
* Executes a given file.
|
|
184
|
+
* @param {string} filePath - The path to the file to execute.
|
|
185
|
+
* @param {string} [interpreter] - Optional. The interpreter to use for executing the file (e.g., "python", "bash").
|
|
186
|
+
* If not provided, the file is executed directly.
|
|
187
|
+
*
|
|
188
|
+
* @returns {Cli} - The script execution output.
|
|
189
|
+
*/
|
|
190
|
+
this.executeFile = async (filePath, interpreter) => ({ stdout: '', stderr: '', });
|
|
191
|
+
this.executeRemoteFile = async (pathToFile, interpreter) => ({ stdout: '', stderr: '', });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.Commando = Commando;
|
|
195
|
+
class CommandoInteractive {
|
|
196
|
+
constructor() {
|
|
197
|
+
this.close = () => this;
|
|
198
|
+
}
|
|
199
|
+
static create(...plugins) {
|
|
200
|
+
const _commando = Commando.create(...plugins);
|
|
201
|
+
const commando = _commando;
|
|
202
|
+
const cli = new CliInteractive();
|
|
203
|
+
cli.setMinLevel(ts_common_1.LogLevel.Verbose);
|
|
204
|
+
commando.cli = cli;
|
|
205
|
+
commando.close = () => {
|
|
206
|
+
return commando;
|
|
207
|
+
};
|
|
208
|
+
return commando;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.CommandoInteractive = CommandoInteractive;
|
package/core/tools.d.ts
ADDED
package/core/tools.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToFullPath = exports.removeAnsiCodes = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
function removeAnsiCodes(text) {
|
|
6
|
+
// This regular expression matches the escape codes and removes them
|
|
7
|
+
return text.replace(/\x1B\[\d+;?\d*m/g, '');
|
|
8
|
+
}
|
|
9
|
+
exports.removeAnsiCodes = removeAnsiCodes;
|
|
10
|
+
function convertToFullPath(pathToFile, assetParentPath = process.cwd()) {
|
|
11
|
+
if (!pathToFile)
|
|
12
|
+
throw new Error('Path not provided');
|
|
13
|
+
if (pathToFile === '')
|
|
14
|
+
throw new Error('Empty path not allowed');
|
|
15
|
+
while (pathToFile.startsWith('/'))
|
|
16
|
+
pathToFile = pathToFile.substring(1);
|
|
17
|
+
const absolutePath = path.resolve(assetParentPath, pathToFile);
|
|
18
|
+
if (!absolutePath.startsWith(assetParentPath))
|
|
19
|
+
throw new Error(`Found path: '${absolutePath}' which is out of the scope of the assert directory: '${assetParentPath}'`);
|
|
20
|
+
return absolutePath;
|
|
21
|
+
}
|
|
22
|
+
exports.convertToFullPath = convertToFullPath;
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nu-art/commando",
|
|
3
|
+
"version": "0.203.117",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"TacB0sS",
|
|
7
|
+
"infra",
|
|
8
|
+
"nu-art",
|
|
9
|
+
"commando"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/nu-art-js/thunderstorm",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/nu-art-js/thunderstorm/issues"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"directory": "dist",
|
|
17
|
+
"linkDirectory": true
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+ssh://git@github.com:nu-art-js/thunderstorm.git"
|
|
22
|
+
},
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"author": "TacB0sS",
|
|
25
|
+
"main": "index.js",
|
|
26
|
+
"types": "index.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"**/*"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@nu-art/ts-common": "0.203.117"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^18.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cli_params_1 = require("../cli/cli-params");
|
|
4
|
+
const testParam1 = {
|
|
5
|
+
keys: ['--test1', '-t1'],
|
|
6
|
+
keyName: 'test1',
|
|
7
|
+
type: 'string',
|
|
8
|
+
description: '',
|
|
9
|
+
defaultValue: 'psulet'
|
|
10
|
+
};
|
|
11
|
+
const testParam2 = {
|
|
12
|
+
keys: ['--test2'],
|
|
13
|
+
keyName: 'test2',
|
|
14
|
+
type: 'string[]',
|
|
15
|
+
description: ''
|
|
16
|
+
};
|
|
17
|
+
const testParam3 = {
|
|
18
|
+
keys: ['--test3'],
|
|
19
|
+
keyName: 'test3',
|
|
20
|
+
type: 'number',
|
|
21
|
+
description: ''
|
|
22
|
+
};
|
|
23
|
+
const testParam4 = {
|
|
24
|
+
keys: ['--test4'],
|
|
25
|
+
keyName: 'test4',
|
|
26
|
+
type: 'number[]',
|
|
27
|
+
description: ''
|
|
28
|
+
};
|
|
29
|
+
const testParam5 = {
|
|
30
|
+
keys: ['--test5'],
|
|
31
|
+
keyName: 'test5',
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
description: ''
|
|
34
|
+
};
|
|
35
|
+
const testParam6 = {
|
|
36
|
+
keys: ['--test6'],
|
|
37
|
+
keyName: 'test6',
|
|
38
|
+
type: 'boolean[]',
|
|
39
|
+
description: ''
|
|
40
|
+
};
|
|
41
|
+
const params = [testParam1, testParam2, testParam3, testParam4, testParam5, testParam6];
|
|
42
|
+
const MyAppParamResolver = new cli_params_1.CLIParams_Resolver(params);
|
|
43
|
+
console.log(MyAppParamResolver.resolveParamValue());
|