@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
package/cli/basic.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseCommando } from '../shell/core/BaseCommando';
|
|
2
|
+
import { CliBlock } from '../shell/types';
|
|
2
3
|
type Cli_EchoOptions = {
|
|
3
4
|
escape?: boolean;
|
|
4
5
|
toFile?: {
|
|
@@ -16,7 +17,7 @@ type Cli_CpdirOptions = {
|
|
|
16
17
|
/**
|
|
17
18
|
* Represents a Command Line Interface (CLI) to build and execute shell commands.
|
|
18
19
|
*/
|
|
19
|
-
export declare class Cli_Basic extends
|
|
20
|
+
export declare class Cli_Basic extends BaseCommando {
|
|
20
21
|
/**
|
|
21
22
|
* Changes directory and optionally executes a block of commands in that directory.
|
|
22
23
|
* @param {string} folderName - Name of the directory to change to.
|
package/cli/basic.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Cli_Basic = void 0;
|
|
4
|
-
const
|
|
4
|
+
const BaseCommando_1 = require("../shell/core/BaseCommando");
|
|
5
5
|
/**
|
|
6
6
|
* Represents a Command Line Interface (CLI) to build and execute shell commands.
|
|
7
7
|
*/
|
|
8
|
-
class Cli_Basic extends
|
|
8
|
+
class Cli_Basic extends BaseCommando_1.BaseCommando {
|
|
9
9
|
/**
|
|
10
10
|
* Changes directory and optionally executes a block of commands in that directory.
|
|
11
11
|
* @param {string} folderName - Name of the directory to change to.
|
|
@@ -13,8 +13,8 @@ class Cli_Basic extends cli_1.CliWrapper {
|
|
|
13
13
|
* @returns {this} - The Cli instance for method chaining.
|
|
14
14
|
*/
|
|
15
15
|
cd(folderName, toRun) {
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
16
|
+
this.append(`cd ${folderName}`);
|
|
17
|
+
this.indentIn();
|
|
18
18
|
if (toRun) {
|
|
19
19
|
toRun(this);
|
|
20
20
|
this.cd_();
|
|
@@ -22,7 +22,7 @@ class Cli_Basic extends cli_1.CliWrapper {
|
|
|
22
22
|
return this;
|
|
23
23
|
}
|
|
24
24
|
custom(command) {
|
|
25
|
-
this.
|
|
25
|
+
this.append(command);
|
|
26
26
|
return this;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -30,8 +30,8 @@ class Cli_Basic extends cli_1.CliWrapper {
|
|
|
30
30
|
* @returns {this} - The Cli instance for method chaining.
|
|
31
31
|
*/
|
|
32
32
|
cd_() {
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
33
|
+
this.indentOut();
|
|
34
|
+
this.append(`cd -`);
|
|
35
35
|
return this;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
@@ -40,11 +40,11 @@ class Cli_Basic extends cli_1.CliWrapper {
|
|
|
40
40
|
* @returns {this} - The Cli instance for method chaining.
|
|
41
41
|
*/
|
|
42
42
|
ls(params = '') {
|
|
43
|
-
this.
|
|
43
|
+
this.append(`ls ${params}`);
|
|
44
44
|
return this;
|
|
45
45
|
}
|
|
46
46
|
mkdir(dirName) {
|
|
47
|
-
this.
|
|
47
|
+
this.append(`mkdir -p ${dirName}`);
|
|
48
48
|
return this;
|
|
49
49
|
}
|
|
50
50
|
rmdir(dirPath, options) {
|
|
@@ -53,7 +53,7 @@ class Cli_Basic extends cli_1.CliWrapper {
|
|
|
53
53
|
command += ' -rf';
|
|
54
54
|
if (options === null || options === void 0 ? void 0 : options.recursive)
|
|
55
55
|
command += ' -r';
|
|
56
|
-
this.
|
|
56
|
+
this.append(`${command} ${dirPath}`);
|
|
57
57
|
return this;
|
|
58
58
|
}
|
|
59
59
|
cpdir(srcPath, destPath, options) {
|
|
@@ -61,18 +61,18 @@ class Cli_Basic extends cli_1.CliWrapper {
|
|
|
61
61
|
if (options === null || options === void 0 ? void 0 : options.contentOnly)
|
|
62
62
|
command += '/*';
|
|
63
63
|
command += ` ${destPath}`;
|
|
64
|
-
this.
|
|
64
|
+
this.append(command);
|
|
65
65
|
return this;
|
|
66
66
|
}
|
|
67
67
|
cat(fileName) {
|
|
68
|
-
this.
|
|
68
|
+
this.append(`cat ${fileName}`);
|
|
69
69
|
return this;
|
|
70
70
|
}
|
|
71
71
|
echo(log, options) {
|
|
72
72
|
const _escape = (options === null || options === void 0 ? void 0 : options.escape) ? '-e' : '';
|
|
73
73
|
const _toFile = (options === null || options === void 0 ? void 0 : options.toFile) ? `>${options.toFile.append ? '>' : ''} ${options.toFile.name}` : '';
|
|
74
74
|
const escapedLog = log.replace(/\\/g, '\\\\').replace(/\n/g, '\\\\n').replace(/\t/g, '\\\t');
|
|
75
|
-
this.
|
|
75
|
+
this.append(`echo ${_escape} "${escapedLog}" ${_toFile}`);
|
|
76
76
|
return this;
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
@@ -80,7 +80,7 @@ class Cli_Basic extends cli_1.CliWrapper {
|
|
|
80
80
|
* @returns {this} - The Cli instance for method chaining.
|
|
81
81
|
*/
|
|
82
82
|
pwd() {
|
|
83
|
-
this.
|
|
83
|
+
this.append('pwd');
|
|
84
84
|
return this;
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
@@ -90,7 +90,7 @@ class Cli_Basic extends cli_1.CliWrapper {
|
|
|
90
90
|
* @returns {this} - The Cli instance for method chaining.
|
|
91
91
|
*/
|
|
92
92
|
assignVar(varName, value) {
|
|
93
|
-
this.
|
|
93
|
+
this.append(`${varName}=(${Array.isArray(value) ? value : [value].join(' ')})`);
|
|
94
94
|
return this;
|
|
95
95
|
}
|
|
96
96
|
}
|
package/cli/git.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Cli_Programming } from './programming';
|
|
2
2
|
import { Cli_Basic } from './basic';
|
|
3
|
-
|
|
3
|
+
import { BaseCommando } from '../shell/core/BaseCommando';
|
|
4
|
+
declare const Super: import("@nu-art/ts-common").Constructor<BaseCommando & Cli_Programming & Cli_Basic>;
|
|
4
5
|
type GitCloneParams = {
|
|
5
6
|
outputFolder?: string;
|
|
6
7
|
branch?: string;
|
|
@@ -15,22 +16,22 @@ type GitPushParams = {
|
|
|
15
16
|
export declare class Cli_Git extends Super {
|
|
16
17
|
git: {
|
|
17
18
|
clone: (url: string, options?: GitCloneParams) => this;
|
|
18
|
-
checkout: (branch: string) =>
|
|
19
|
-
createTag: (tagName: string) =>
|
|
20
|
-
gitCommit: (commitMessage: string) =>
|
|
21
|
-
add: (file: string) =>
|
|
22
|
-
addAll: () =>
|
|
23
|
-
addAndCommit: (commitMessage: string) =>
|
|
24
|
-
push: (options?: GitPushParams) =>
|
|
25
|
-
pushTags: () =>
|
|
26
|
-
fetch: () =>
|
|
27
|
-
resetHard: (tag?: string) =>
|
|
28
|
-
getCurrentBranch: () =>
|
|
29
|
-
pull: (params: string) =>
|
|
30
|
-
merge: (mergeFrom: string) =>
|
|
31
|
-
createBranch: (branch: string) =>
|
|
32
|
-
gsui: (modules?: string) =>
|
|
33
|
-
status: () =>
|
|
19
|
+
checkout: (branch: string) => this;
|
|
20
|
+
createTag: (tagName: string) => this;
|
|
21
|
+
gitCommit: (commitMessage: string) => this;
|
|
22
|
+
add: (file: string) => this;
|
|
23
|
+
addAll: () => this;
|
|
24
|
+
addAndCommit: (commitMessage: string) => this;
|
|
25
|
+
push: (options?: GitPushParams) => this;
|
|
26
|
+
pushTags: () => this;
|
|
27
|
+
fetch: () => this;
|
|
28
|
+
resetHard: (tag?: string) => this;
|
|
29
|
+
getCurrentBranch: () => this;
|
|
30
|
+
pull: (params: string) => this;
|
|
31
|
+
merge: (mergeFrom: string) => this;
|
|
32
|
+
createBranch: (branch: string) => this;
|
|
33
|
+
gsui: (modules?: string) => this;
|
|
34
|
+
status: () => this;
|
|
34
35
|
};
|
|
35
36
|
git_clone(url: string, options?: GitCloneParams): this;
|
|
36
37
|
private git_checkout;
|
package/cli/git.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Cli_Git = void 0;
|
|
4
4
|
const programming_1 = require("./programming");
|
|
5
|
-
const class_merger_1 = require("../core/class-merger");
|
|
6
5
|
const basic_1 = require("./basic");
|
|
7
|
-
const
|
|
6
|
+
const class_merger_1 = require("../shell/core/class-merger");
|
|
7
|
+
const BaseCommando_1 = require("../shell/core/BaseCommando");
|
|
8
|
+
const Super = (0, class_merger_1.MergeClass)(BaseCommando_1.BaseCommando, programming_1.Cli_Programming, basic_1.Cli_Basic);
|
|
8
9
|
class Cli_Git extends Super {
|
|
9
10
|
constructor() {
|
|
10
11
|
super(...arguments);
|
|
@@ -32,72 +33,92 @@ class Cli_Git extends Super {
|
|
|
32
33
|
const branch = `${(options === null || options === void 0 ? void 0 : options.branch) ? ` -b ${options === null || options === void 0 ? void 0 : options.branch}` : ''}`;
|
|
33
34
|
const recursive = `${(options === null || options === void 0 ? void 0 : options.recursive) ? ` --recursive` : ''}`;
|
|
34
35
|
const outputFolder = `${(options === null || options === void 0 ? void 0 : options.outputFolder) ? ` ${options.outputFolder}` : ''}`;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const command = `git clone${recursive}${branch} ${url}${outputFolder}`;
|
|
37
|
+
this.append(command);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
// git_cloneAssert(url: string, options?: GitCloneParams) {
|
|
41
|
+
// return new Promise<void>((resolve, reject) => {
|
|
42
|
+
// const branch = `${options?.branch ? ` -b ${options?.branch}` : ''}`;
|
|
43
|
+
// const recursive = `${options?.recursive ? ` --recursive` : ''}`;
|
|
44
|
+
// const outputFolder = `${options?.outputFolder ? ` ${options.outputFolder}` : ''}`;
|
|
45
|
+
// const command = `git clone${recursive}${branch} ${url}${outputFolder}`;
|
|
46
|
+
// this.echo(command);
|
|
47
|
+
// this.append(command)
|
|
48
|
+
// .execute((stdout: string, stderr: string, exitCode: number) => {
|
|
49
|
+
// if (exitCode === 0)
|
|
50
|
+
// return resolve();
|
|
51
|
+
//
|
|
52
|
+
// if (exitCode === 128)
|
|
53
|
+
// return reject(new Error(`No access to repo: ${url}`));
|
|
54
|
+
//
|
|
55
|
+
// return reject(new Error(`Got unexpected exit code(${exitCode}) while cloning: ${url}`));
|
|
56
|
+
// });
|
|
57
|
+
// });
|
|
58
|
+
// }
|
|
38
59
|
git_checkout(branch) {
|
|
39
|
-
this.
|
|
60
|
+
this.append(`git checkout ${branch}`);
|
|
40
61
|
return this;
|
|
41
62
|
}
|
|
42
63
|
git_createTag(tagName) {
|
|
43
|
-
this.
|
|
64
|
+
this.append(`git tag -f ${tagName}`);
|
|
44
65
|
return this;
|
|
45
66
|
}
|
|
46
67
|
git_gitCommit(commitMessage) {
|
|
47
|
-
this.
|
|
68
|
+
this.append(`git commit -m "${commitMessage}"`);
|
|
48
69
|
return this;
|
|
49
70
|
}
|
|
50
71
|
git_add(file) {
|
|
51
|
-
this.
|
|
72
|
+
this.append(`git add "${file}"`);
|
|
52
73
|
return this;
|
|
53
74
|
}
|
|
54
75
|
git_addAll() {
|
|
55
|
-
this.
|
|
76
|
+
this.append(`git add .`);
|
|
56
77
|
return this;
|
|
57
78
|
}
|
|
58
79
|
git_addAndCommit(commitMessage) {
|
|
59
|
-
this.
|
|
80
|
+
this.append(`git commit -am "${commitMessage}"`);
|
|
60
81
|
return this;
|
|
61
82
|
}
|
|
62
83
|
git_push(options) {
|
|
63
|
-
this.
|
|
84
|
+
this.append(`git push ${options === null || options === void 0 ? void 0 : options.remote} ${options === null || options === void 0 ? void 0 : options.branch}`);
|
|
64
85
|
return this;
|
|
65
86
|
}
|
|
66
87
|
git_pushTags() {
|
|
67
|
-
this.
|
|
88
|
+
this.append('git push --tags --force');
|
|
68
89
|
return this;
|
|
69
90
|
}
|
|
70
91
|
git_fetch() {
|
|
71
|
-
this.
|
|
92
|
+
this.append('git fetch');
|
|
72
93
|
return this;
|
|
73
94
|
}
|
|
74
95
|
git_resetHard(tag = '') {
|
|
75
|
-
this.
|
|
96
|
+
this.append('git reset --hard ${tag}');
|
|
76
97
|
return this;
|
|
77
98
|
}
|
|
78
99
|
git_getCurrentBranch() {
|
|
79
|
-
this.
|
|
100
|
+
this.append('git status | grep "On branch" | sed -E "s');
|
|
80
101
|
return this;
|
|
81
102
|
}
|
|
82
103
|
git_pull(params) {
|
|
83
|
-
this.
|
|
104
|
+
this.append('git pull ${params}');
|
|
84
105
|
return this;
|
|
85
106
|
}
|
|
86
107
|
git_merge(mergeFrom) {
|
|
87
|
-
this.
|
|
108
|
+
this.append(`git merge ${mergeFrom}`);
|
|
88
109
|
return this;
|
|
89
110
|
}
|
|
90
111
|
git_createBranch(branch) {
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
112
|
+
this.append(`git checkout - b ${branch}`);
|
|
113
|
+
this.append(`git push-- set -upstream origin ${branch}`);
|
|
93
114
|
return this;
|
|
94
115
|
}
|
|
95
116
|
git_gsui(modules = '') {
|
|
96
|
-
this.
|
|
117
|
+
this.append('git submodule update --recursive --init ${modules}');
|
|
97
118
|
return this;
|
|
98
119
|
}
|
|
99
120
|
git_status() {
|
|
100
|
-
this.
|
|
121
|
+
this.append('git status');
|
|
101
122
|
return this;
|
|
102
123
|
}
|
|
103
124
|
}
|
package/cli/nvm.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { CliWrapper, Commando, CommandoInteractive } from '../core/cli';
|
|
2
1
|
import { Constructor, Logger } from '@nu-art/ts-common';
|
|
2
|
+
import { Commando } from '../shell/simple/Commando';
|
|
3
|
+
import { CommandoInteractive } from '../shell/interactive/CommandoInteractive';
|
|
3
4
|
export declare class Cli_NVM extends Logger {
|
|
4
5
|
private _expectedVersion;
|
|
5
6
|
private _homeEnvVar;
|
|
@@ -16,7 +17,7 @@ export declare class Cli_NVM extends Logger {
|
|
|
16
17
|
private getVersion;
|
|
17
18
|
uninstall: () => Promise<void>;
|
|
18
19
|
private installVersion;
|
|
19
|
-
createInteractiveCommando<T extends Constructor<
|
|
20
|
-
createCommando<T extends Constructor<
|
|
20
|
+
createInteractiveCommando<T extends Constructor<any>[]>(...plugins: T): import("../shell/core/class-merger").MergeTypes<[typeof import("../shell/core/BaseCommando").BaseCommando, typeof CommandoInteractive, ...T]> & import("../shell/core/BaseCommando").BaseCommando & CommandoInteractive;
|
|
21
|
+
createCommando<T extends Constructor<any>[]>(...plugins: T): import("../shell/core/class-merger").MergeTypes<[typeof import("../shell/core/BaseCommando").BaseCommando, typeof Commando, ...T]> & import("../shell/core/BaseCommando").BaseCommando & Commando;
|
|
21
22
|
}
|
|
22
23
|
export declare const NVM: Cli_NVM;
|
package/cli/nvm.js
CHANGED
|
@@ -26,12 +26,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.NVM = exports.Cli_NVM = void 0;
|
|
27
27
|
const programming_1 = require("./programming");
|
|
28
28
|
const basic_1 = require("./basic");
|
|
29
|
-
const cli_1 = require("../core/cli");
|
|
30
29
|
const fs = __importStar(require("fs"));
|
|
31
30
|
const fs_1 = require("fs");
|
|
32
31
|
const path = __importStar(require("path"));
|
|
33
|
-
const tools_1 = require("../core/tools");
|
|
34
32
|
const ts_common_1 = require("@nu-art/ts-common");
|
|
33
|
+
const Commando_1 = require("../shell/simple/Commando");
|
|
34
|
+
const tools_1 = require("../shell/tools");
|
|
35
|
+
const CommandoInteractive_1 = require("../shell/interactive/CommandoInteractive");
|
|
35
36
|
const CONST__FILE_NVMRC = '.nvmrc';
|
|
36
37
|
class Cli_NVM extends ts_common_1.Logger {
|
|
37
38
|
constructor() {
|
|
@@ -40,12 +41,12 @@ class Cli_NVM extends ts_common_1.Logger {
|
|
|
40
41
|
this._homeEnvVar = '$NVM_DIR';
|
|
41
42
|
this.install = async () => {
|
|
42
43
|
if (this.isInstalled()) {
|
|
43
|
-
const version = (await this.getVersion()).
|
|
44
|
+
const version = (await this.getVersion()).trim();
|
|
44
45
|
if (this._expectedVersion === version)
|
|
45
46
|
return;
|
|
46
47
|
await this.uninstall();
|
|
47
48
|
}
|
|
48
|
-
await
|
|
49
|
+
await Commando_1.Commando.create()
|
|
49
50
|
.append(` curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/v${this._expectedVersion}/install.sh" | bash`)
|
|
50
51
|
.execute();
|
|
51
52
|
const rcFile = path.resolve(process.env['HOME'], '.bashrc');
|
|
@@ -91,7 +92,7 @@ class Cli_NVM extends ts_common_1.Logger {
|
|
|
91
92
|
}
|
|
92
93
|
return extractInstalledVersions((await this.createCommando()
|
|
93
94
|
.append('nvm ls')
|
|
94
|
-
.execute()
|
|
95
|
+
.execute((stdout) => stdout)));
|
|
95
96
|
};
|
|
96
97
|
this.uninstall = async () => {
|
|
97
98
|
this.logDebug('Uninstalling PNPM');
|
|
@@ -120,22 +121,24 @@ class Cli_NVM extends ts_common_1.Logger {
|
|
|
120
121
|
this._expectedVersion = value;
|
|
121
122
|
}
|
|
122
123
|
async getVersion() {
|
|
123
|
-
const commando =
|
|
124
|
+
const commando = Commando_1.Commando.create(programming_1.Cli_Programming, basic_1.Cli_Basic);
|
|
124
125
|
return commando.if('[[ -x "$(command -v nvm)" ]]', (commando) => {
|
|
125
|
-
commando.
|
|
126
|
-
}).execute();
|
|
126
|
+
commando.append('nvm --version');
|
|
127
|
+
}).execute((stdout) => stdout);
|
|
127
128
|
}
|
|
128
129
|
createInteractiveCommando(...plugins) {
|
|
129
|
-
return
|
|
130
|
+
return CommandoInteractive_1.CommandoInteractive.create(...plugins)
|
|
130
131
|
.append('export NVM_DIR="$HOME/.nvm"')
|
|
131
132
|
.append('[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm')
|
|
132
133
|
.append('nvm use');
|
|
133
134
|
}
|
|
134
135
|
createCommando(...plugins) {
|
|
135
|
-
|
|
136
|
+
const commando = Commando_1.Commando.create(...plugins);
|
|
137
|
+
commando
|
|
136
138
|
.append('export NVM_DIR="$HOME/.nvm"')
|
|
137
139
|
.append('[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm')
|
|
138
140
|
.append('nvm use');
|
|
141
|
+
return commando;
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
exports.Cli_NVM = Cli_NVM;
|
package/cli/pnpm.d.ts
CHANGED
package/cli/pnpm.js
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PNPM = exports.Cli_PNPM = void 0;
|
|
4
4
|
const programming_1 = require("./programming");
|
|
5
5
|
const basic_1 = require("./basic");
|
|
6
|
-
const cli_1 = require("../core/cli");
|
|
7
6
|
const fs_1 = require("fs");
|
|
8
|
-
const tools_1 = require("../core/tools");
|
|
9
7
|
const ts_common_1 = require("@nu-art/ts-common");
|
|
8
|
+
const Commando_1 = require("../shell/simple/Commando");
|
|
9
|
+
const tools_1 = require("../shell/tools");
|
|
10
10
|
class Cli_PNPM extends ts_common_1.Logger {
|
|
11
11
|
constructor() {
|
|
12
12
|
super();
|
|
@@ -14,20 +14,20 @@ class Cli_PNPM extends ts_common_1.Logger {
|
|
|
14
14
|
this._homeEnvVar = 'PNPM_HOME';
|
|
15
15
|
this.install = async (commando) => {
|
|
16
16
|
if (this.isInstalled()) {
|
|
17
|
-
const version = (await this.getVersion()).
|
|
17
|
+
const version = (await this.getVersion()).trim();
|
|
18
18
|
if (this._expectedVersion === version)
|
|
19
19
|
return;
|
|
20
20
|
await this.uninstall();
|
|
21
21
|
}
|
|
22
22
|
this.logDebug(`installing PNPM version ${this._expectedVersion}`);
|
|
23
|
-
await (commando !== null && commando !== void 0 ? commando :
|
|
23
|
+
await (commando !== null && commando !== void 0 ? commando : Commando_1.Commando.create())
|
|
24
24
|
.append(`curl -fsSL "https://get.pnpm.io/install.sh" | env PNPM_VERSION=${this._expectedVersion} bash -`)
|
|
25
25
|
.execute();
|
|
26
26
|
return this;
|
|
27
27
|
};
|
|
28
28
|
this.isInstalled = () => !!process.env[this._homeEnvVar];
|
|
29
29
|
this.installPackages = async (commando) => {
|
|
30
|
-
await (commando !== null && commando !== void 0 ? commando :
|
|
30
|
+
await (commando !== null && commando !== void 0 ? commando : Commando_1.Commando.create())
|
|
31
31
|
.append(`pnpm store prune`)
|
|
32
32
|
.append(`pnpm install -f --no-frozen-lockfile --prefer-offline false`)
|
|
33
33
|
.execute();
|
|
@@ -77,10 +77,10 @@ class Cli_PNPM extends ts_common_1.Logger {
|
|
|
77
77
|
this._expectedVersion = value;
|
|
78
78
|
}
|
|
79
79
|
async getVersion() {
|
|
80
|
-
const commando =
|
|
80
|
+
const commando = Commando_1.Commando.create(programming_1.Cli_Programming, basic_1.Cli_Basic);
|
|
81
81
|
return commando.if('[[ -x "$(command -v pnpm)" ]]', (commando) => {
|
|
82
|
-
commando.
|
|
83
|
-
}).execute();
|
|
82
|
+
commando.append('pnpm --version');
|
|
83
|
+
}).execute(stdout => stdout);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
exports.Cli_PNPM = Cli_PNPM;
|
package/cli/programming.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BaseCommando } from '../shell/core/BaseCommando';
|
|
2
|
+
import { CliBlock } from '../shell/types';
|
|
3
|
+
export declare class Cli_Programming extends BaseCommando {
|
|
3
4
|
/**
|
|
4
5
|
* Constructs an if-else conditional command structure.
|
|
5
6
|
* @param {string} condition - The condition for the if statement.
|
package/cli/programming.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Cli_Programming = void 0;
|
|
4
|
-
const
|
|
5
|
-
class Cli_Programming extends
|
|
4
|
+
const BaseCommando_1 = require("../shell/core/BaseCommando");
|
|
5
|
+
class Cli_Programming extends BaseCommando_1.BaseCommando {
|
|
6
6
|
/**
|
|
7
7
|
* Constructs an if-else conditional command structure.
|
|
8
8
|
* @param {string} condition - The condition for the if statement.
|
|
@@ -11,18 +11,18 @@ class Cli_Programming extends cli_1.CliWrapper {
|
|
|
11
11
|
* @returns {this} - The Cli instance for method chaining.
|
|
12
12
|
*/
|
|
13
13
|
if(condition, ifBlock, elseBlock) {
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
14
|
+
this.append(`if ${condition}; then`);
|
|
15
|
+
this.indentIn();
|
|
16
16
|
ifBlock(this);
|
|
17
17
|
if (elseBlock) {
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
18
|
+
this.indentOut();
|
|
19
|
+
this.append('else');
|
|
20
|
+
this.indentIn();
|
|
21
21
|
elseBlock(this);
|
|
22
22
|
}
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
23
|
+
this.indentOut();
|
|
24
|
+
this.append('fi');
|
|
25
|
+
this.emptyLine();
|
|
26
26
|
return this;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -34,17 +34,17 @@ class Cli_Programming extends cli_1.CliWrapper {
|
|
|
34
34
|
*/
|
|
35
35
|
for(varName, arrayNameOrValues, loop) {
|
|
36
36
|
if (typeof arrayNameOrValues === 'string') {
|
|
37
|
-
this.
|
|
37
|
+
this.append(`for ${varName} in "\${${arrayNameOrValues}[@]}"; do`);
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
40
|
const values = arrayNameOrValues.map(value => `"${value}"`).join(' ');
|
|
41
|
-
this.
|
|
41
|
+
this.append(`for ${varName} in ${values}; do`);
|
|
42
42
|
}
|
|
43
|
-
this.
|
|
43
|
+
this.indentIn();
|
|
44
44
|
loop(this);
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
45
|
+
this.indentOut();
|
|
46
|
+
this.append('done');
|
|
47
|
+
this.emptyLine();
|
|
48
48
|
return this;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
@@ -52,7 +52,7 @@ class Cli_Programming extends cli_1.CliWrapper {
|
|
|
52
52
|
* @returns {this} - The Cli instance for method chaining.
|
|
53
53
|
*/
|
|
54
54
|
continue() {
|
|
55
|
-
this.
|
|
55
|
+
this.append('continue');
|
|
56
56
|
return this;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
@@ -60,7 +60,7 @@ class Cli_Programming extends cli_1.CliWrapper {
|
|
|
60
60
|
* @returns {this} - The Cli instance for method chaining.
|
|
61
61
|
*/
|
|
62
62
|
break() {
|
|
63
|
-
this.
|
|
63
|
+
this.append('break');
|
|
64
64
|
return this;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
@@ -68,7 +68,7 @@ class Cli_Programming extends cli_1.CliWrapper {
|
|
|
68
68
|
* @returns {this} - The Cli instance for method chaining.
|
|
69
69
|
*/
|
|
70
70
|
return() {
|
|
71
|
-
this.
|
|
71
|
+
this.append('return');
|
|
72
72
|
return this;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BaseCliParam, CliParams } from './types';
|
|
2
|
+
export declare class CLIParamsResolver<T extends BaseCliParam<string, any>[], Output extends CliParams<T> = CliParams<T>> {
|
|
3
|
+
private params;
|
|
4
|
+
static create<T extends BaseCliParam<string, any>[]>(...params: T): CLIParamsResolver<T, CliParams<T>>;
|
|
5
|
+
constructor(params: BaseCliParam<string, any>[]);
|
|
6
|
+
/**
|
|
7
|
+
* Format current input params and return it structured by the app params type.
|
|
8
|
+
* @param inputParams current console input arguments
|
|
9
|
+
* @returns CliParamsObject
|
|
10
|
+
*/
|
|
11
|
+
resolveParamValue(inputParams?: string[]): Output;
|
|
12
|
+
/**
|
|
13
|
+
* Find the matching param by finding it's key in the current argument
|
|
14
|
+
* Go over the app params and find the CLIParam object representing it
|
|
15
|
+
* @param inputParam The current console argument being parsed
|
|
16
|
+
* @returns The CliParam or undefined if not found
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
private findMatchingParamToResolve;
|
|
20
|
+
/**
|
|
21
|
+
* Translate BaseCLIParams passed to the constructor to CLIParams
|
|
22
|
+
* @param params User input of CLI params being passed to the constructor
|
|
23
|
+
* @private
|
|
24
|
+
* @returns CLI Params filled with all mandatory data
|
|
25
|
+
*/
|
|
26
|
+
private translate;
|
|
27
|
+
}
|
|
@@ -1,39 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CLIParamsResolver = void 0;
|
|
4
4
|
const ts_common_1 = require("@nu-art/ts-common");
|
|
5
|
-
const
|
|
6
|
-
|
|
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 {
|
|
5
|
+
const consts_1 = require("./consts");
|
|
6
|
+
class CLIParamsResolver {
|
|
35
7
|
static create(...params) {
|
|
36
|
-
return new
|
|
8
|
+
return new CLIParamsResolver(params);
|
|
37
9
|
}
|
|
38
10
|
constructor(params) {
|
|
39
11
|
this.params = this.translate(params);
|
|
@@ -111,7 +83,7 @@ class CLIParams_Resolver {
|
|
|
111
83
|
param.name = param.keyName;
|
|
112
84
|
//If no processor is passed apply default by type
|
|
113
85
|
if (!param.process) {
|
|
114
|
-
param.process = DefaultProcessorsMapper[param.type.split('[')[0].trim()];
|
|
86
|
+
param.process = consts_1.DefaultProcessorsMapper[param.type.split('[')[0].trim()];
|
|
115
87
|
}
|
|
116
88
|
//Determine if value is array by the param type TODO: improve this chunk of code, this is not strict enough
|
|
117
89
|
if (!(0, ts_common_1.exists)(param.isArray) && param.type.includes('[]'))
|
|
@@ -120,4 +92,4 @@ class CLIParams_Resolver {
|
|
|
120
92
|
});
|
|
121
93
|
}
|
|
122
94
|
}
|
|
123
|
-
exports.
|
|
95
|
+
exports.CLIParamsResolver = CLIParamsResolver;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TypedMap } from '@nu-art/ts-common';
|
|
2
|
+
import { CliParam } from './types';
|
|
3
|
+
export declare const DefaultProcessor_Boolean: CliParam<any, boolean>['process'];
|
|
4
|
+
export declare const DefaultProcessor_String: CliParam<any, string>['process'];
|
|
5
|
+
export declare const DefaultProcessor_Number: CliParam<any, number>['process'];
|
|
6
|
+
export declare const DefaultProcessorsMapper: TypedMap<CliParam<any, any>['process']>;
|