@nu-art/commando 0.401.0 → 0.401.2
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/{shell/core → core}/BaseCommando.d.ts +37 -6
- package/{shell/core → core}/BaseCommando.js +40 -6
- package/core/CliError.d.ts +49 -0
- package/core/CliError.js +58 -0
- package/{shell/core → core}/CommandBuilder.d.ts +27 -2
- package/{shell/core → core}/CommandBuilder.js +32 -3
- package/core/CommandoPool.d.ts +42 -0
- package/core/CommandoPool.js +48 -0
- package/core/class-merger.d.ts +39 -0
- package/core/class-merger.js +50 -0
- package/index.d.ts +11 -0
- package/index.js +16 -0
- package/{shell/interactive → interactive}/CommandoInteractive.d.ts +67 -7
- package/{shell/interactive → interactive}/CommandoInteractive.js +69 -6
- package/{shell/interactive → interactive}/InteractiveShell.d.ts +38 -0
- package/{shell/interactive → interactive}/InteractiveShell.js +25 -0
- package/package.json +24 -15
- package/plugins/basic.d.ts +140 -0
- package/plugins/basic.js +179 -0
- package/plugins/git.d.ts +169 -0
- package/plugins/git.js +219 -0
- package/plugins/nvm.d.ts +59 -0
- package/{shell/plugins → plugins}/nvm.js +47 -0
- package/plugins/pnpm.d.ts +42 -0
- package/{shell/plugins → plugins}/pnpm.js +31 -0
- package/{shell/plugins → plugins}/programming.d.ts +23 -3
- package/{shell/plugins → plugins}/programming.js +23 -3
- package/plugins/python.d.ts +41 -0
- package/plugins/python.js +58 -0
- package/services/nvm.d.ts +76 -0
- package/{shell/services → services}/nvm.js +67 -6
- package/services/pnpm.d.ts +67 -0
- package/{shell/services → services}/pnpm.js +41 -0
- package/simple/Commando.d.ts +92 -0
- package/simple/Commando.js +122 -0
- package/simple/SimpleShell.d.ts +48 -0
- package/{shell/simple → simple}/SimpleShell.js +32 -2
- package/tools.d.ts +33 -0
- package/tools.js +47 -0
- package/types.d.ts +17 -0
- package/cli-params/CLIParamsResolver.d.ts +0 -27
- package/cli-params/CLIParamsResolver.js +0 -97
- package/cli-params/consts.d.ts +0 -6
- package/cli-params/consts.js +0 -27
- package/cli-params/types.d.ts +0 -28
- package/shell/core/CliError.d.ts +0 -14
- package/shell/core/CliError.js +0 -23
- package/shell/core/CommandoPool.d.ts +0 -9
- package/shell/core/CommandoPool.js +0 -14
- package/shell/core/class-merger.d.ts +0 -20
- package/shell/core/class-merger.js +0 -35
- package/shell/index.d.ts +0 -2
- package/shell/index.js +0 -2
- package/shell/plugins/basic.d.ts +0 -59
- package/shell/plugins/basic.js +0 -98
- package/shell/plugins/git.d.ts +0 -54
- package/shell/plugins/git.js +0 -104
- package/shell/plugins/nvm.d.ts +0 -12
- package/shell/plugins/pnpm.d.ts +0 -11
- package/shell/plugins/python.d.ts +0 -10
- package/shell/plugins/python.js +0 -26
- package/shell/services/nvm.d.ts +0 -18
- package/shell/services/pnpm.d.ts +0 -26
- package/shell/simple/Commando.d.ts +0 -17
- package/shell/simple/Commando.js +0 -47
- package/shell/simple/SimpleShell.d.ts +0 -21
- package/shell/tools.d.ts +0 -3
- package/shell/tools.js +0 -17
- package/shell/types.d.ts +0 -3
- package/shell/types.js +0 -1
- /package/{cli-params/types.js → types.js} +0 -0
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { BaseCommando } from '../core/BaseCommando.js';
|
|
2
|
+
/**
|
|
3
|
+
* Programming constructs plugin for Commando.
|
|
4
|
+
*
|
|
5
|
+
* Provides control flow structures for building shell scripts:
|
|
6
|
+
* - Conditionals (`if`/`else`)
|
|
7
|
+
* - Loops (`for`, `while`)
|
|
8
|
+
* - Functions
|
|
9
|
+
*
|
|
10
|
+
* These methods build shell script structures with proper indentation
|
|
11
|
+
* and syntax, allowing programmatic construction of complex shell scripts.
|
|
12
|
+
*/
|
|
2
13
|
export class Commando_Programming extends BaseCommando {
|
|
3
14
|
/**
|
|
4
15
|
* Constructs an if-else conditional command structure.
|
|
@@ -46,7 +57,10 @@ export class Commando_Programming extends BaseCommando {
|
|
|
46
57
|
}
|
|
47
58
|
/**
|
|
48
59
|
* Appends a 'continue' command for loop control.
|
|
49
|
-
*
|
|
60
|
+
*
|
|
61
|
+
* Skips to the next iteration of the innermost loop.
|
|
62
|
+
*
|
|
63
|
+
* @returns This instance for method chaining
|
|
50
64
|
*/
|
|
51
65
|
continue() {
|
|
52
66
|
this.append('continue');
|
|
@@ -54,7 +68,10 @@ export class Commando_Programming extends BaseCommando {
|
|
|
54
68
|
}
|
|
55
69
|
/**
|
|
56
70
|
* Appends a 'break' command for loop control.
|
|
57
|
-
*
|
|
71
|
+
*
|
|
72
|
+
* Exits the innermost loop.
|
|
73
|
+
*
|
|
74
|
+
* @returns This instance for method chaining
|
|
58
75
|
*/
|
|
59
76
|
break() {
|
|
60
77
|
this.append('break');
|
|
@@ -62,7 +79,10 @@ export class Commando_Programming extends BaseCommando {
|
|
|
62
79
|
}
|
|
63
80
|
/**
|
|
64
81
|
* Appends a 'return' command for exiting a function or script.
|
|
65
|
-
*
|
|
82
|
+
*
|
|
83
|
+
* Exits the current function or script with optional exit code.
|
|
84
|
+
*
|
|
85
|
+
* @returns This instance for method chaining
|
|
66
86
|
*/
|
|
67
87
|
return() {
|
|
68
88
|
this.append('return');
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BaseCommando } from '../core/BaseCommando.js';
|
|
2
|
+
import { Commando_Programming } from './programming.js';
|
|
3
|
+
import { Commando_Basic } from './basic.js';
|
|
4
|
+
declare const Super: import("@nu-art/ts-common").Constructor<BaseCommando & Commando_Programming & Commando_Basic>;
|
|
5
|
+
/**
|
|
6
|
+
* Python 3 plugin for Commando.
|
|
7
|
+
*
|
|
8
|
+
* Provides Python virtual environment operations:
|
|
9
|
+
* - Create virtual environments
|
|
10
|
+
* - Activate virtual environments
|
|
11
|
+
* - Install requirements from requirements.txt
|
|
12
|
+
*
|
|
13
|
+
* Extends Commando_Programming and Commando_Basic (merged).
|
|
14
|
+
*/
|
|
15
|
+
export declare class Commando_Python3 extends Super {
|
|
16
|
+
/**
|
|
17
|
+
* Activates a Python virtual environment.
|
|
18
|
+
*
|
|
19
|
+
* Sources the activation script for the virtual environment.
|
|
20
|
+
*
|
|
21
|
+
* @param venvFolder - Virtual environment folder path (default: '.venv')
|
|
22
|
+
* @returns This instance for method chaining
|
|
23
|
+
*/
|
|
24
|
+
sourceVenv(venvFolder?: string): this;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a Python virtual environment.
|
|
27
|
+
*
|
|
28
|
+
* @param venvFolder - Virtual environment folder path (default: '.venv')
|
|
29
|
+
* @returns This instance for method chaining
|
|
30
|
+
* @throws Exception if virtual environment creation fails
|
|
31
|
+
*/
|
|
32
|
+
installVenv(venvFolder?: string): Promise<this>;
|
|
33
|
+
/**
|
|
34
|
+
* Installs Python packages from a requirements file.
|
|
35
|
+
*
|
|
36
|
+
* @param pathToRequirementsFile - Path to requirements.txt file (default: './requirements.txt')
|
|
37
|
+
* @returns This instance for method chaining
|
|
38
|
+
*/
|
|
39
|
+
installRequirements(pathToRequirementsFile?: string): Promise<this>;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { BaseCommando } from '../core/BaseCommando.js';
|
|
2
|
+
import { Commando_Programming } from './programming.js';
|
|
3
|
+
import { MergeClass } from '../core/class-merger.js';
|
|
4
|
+
import { Commando_Basic } from './basic.js';
|
|
5
|
+
import { Exception } from '@nu-art/ts-common';
|
|
6
|
+
const Super = MergeClass(BaseCommando, Commando_Programming, Commando_Basic);
|
|
7
|
+
/** Default virtual environment folder name */
|
|
8
|
+
const DefaultVenvFolder = '.venv';
|
|
9
|
+
/**
|
|
10
|
+
* Python 3 plugin for Commando.
|
|
11
|
+
*
|
|
12
|
+
* Provides Python virtual environment operations:
|
|
13
|
+
* - Create virtual environments
|
|
14
|
+
* - Activate virtual environments
|
|
15
|
+
* - Install requirements from requirements.txt
|
|
16
|
+
*
|
|
17
|
+
* Extends Commando_Programming and Commando_Basic (merged).
|
|
18
|
+
*/
|
|
19
|
+
export class Commando_Python3 extends Super {
|
|
20
|
+
/**
|
|
21
|
+
* Activates a Python virtual environment.
|
|
22
|
+
*
|
|
23
|
+
* Sources the activation script for the virtual environment.
|
|
24
|
+
*
|
|
25
|
+
* @param venvFolder - Virtual environment folder path (default: '.venv')
|
|
26
|
+
* @returns This instance for method chaining
|
|
27
|
+
*/
|
|
28
|
+
sourceVenv(venvFolder = DefaultVenvFolder) {
|
|
29
|
+
this.append(`source ${venvFolder}/bin/activate`);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a Python virtual environment.
|
|
34
|
+
*
|
|
35
|
+
* @param venvFolder - Virtual environment folder path (default: '.venv')
|
|
36
|
+
* @returns This instance for method chaining
|
|
37
|
+
* @throws Exception if virtual environment creation fails
|
|
38
|
+
*/
|
|
39
|
+
async installVenv(venvFolder = DefaultVenvFolder) {
|
|
40
|
+
this.append(`python3 -m venv ${venvFolder}`);
|
|
41
|
+
await this.execute((stdout, stderr, exitCode) => {
|
|
42
|
+
if (exitCode !== 0)
|
|
43
|
+
throw new Exception(`Error installing VENV - exit code (${exitCode})`);
|
|
44
|
+
});
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Installs Python packages from a requirements file.
|
|
49
|
+
*
|
|
50
|
+
* @param pathToRequirementsFile - Path to requirements.txt file (default: './requirements.txt')
|
|
51
|
+
* @returns This instance for method chaining
|
|
52
|
+
*/
|
|
53
|
+
async installRequirements(pathToRequirementsFile = './requirements.txt') {
|
|
54
|
+
await this.append(`pip3 install -r ${pathToRequirementsFile}`)
|
|
55
|
+
.execute();
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Logger } from '@nu-art/ts-common';
|
|
2
|
+
import { Commando_NVM } from '../plugins/nvm.js';
|
|
3
|
+
/**
|
|
4
|
+
* NVM (Node Version Manager) service for managing Node.js installations.
|
|
5
|
+
*
|
|
6
|
+
* Handles installation, version management, and configuration of NVM.
|
|
7
|
+
* Works with Commando_NVM plugin to execute NVM commands.
|
|
8
|
+
*
|
|
9
|
+
* **Features**:
|
|
10
|
+
* - Install/uninstall NVM
|
|
11
|
+
* - Configure shell RC files (.bashrc, .zshrc)
|
|
12
|
+
* - Version management
|
|
13
|
+
* - Integration with .nvmrc files
|
|
14
|
+
*/
|
|
15
|
+
export declare class Cli_NVM extends Logger {
|
|
16
|
+
private _expectedVersion;
|
|
17
|
+
private _homeEnvVar;
|
|
18
|
+
constructor();
|
|
19
|
+
get homeEnvVar(): string;
|
|
20
|
+
set homeEnvVar(value: string);
|
|
21
|
+
get expectedVersion(): string;
|
|
22
|
+
set expectedVersion(value: string);
|
|
23
|
+
/**
|
|
24
|
+
* Installs NVM and configures shell RC files.
|
|
25
|
+
*
|
|
26
|
+
* **Behavior**:
|
|
27
|
+
* - Checks if NVM is already installed with expected version
|
|
28
|
+
* - Uninstalls if version mismatch
|
|
29
|
+
* - Installs NVM via Commando_NVM
|
|
30
|
+
* - Configures .bashrc with NVM initialization (if not already present)
|
|
31
|
+
*
|
|
32
|
+
*
|
|
33
|
+
* @param commando - Commando_NVM instance to use for installation
|
|
34
|
+
* @returns This instance for method chaining
|
|
35
|
+
*/
|
|
36
|
+
install: (commando: Commando_NVM) => Promise<this | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if NVM is installed.
|
|
39
|
+
*
|
|
40
|
+
* Verifies both environment variable and directory existence.
|
|
41
|
+
*
|
|
42
|
+
* @returns True if NVM is installed
|
|
43
|
+
*/
|
|
44
|
+
isInstalled: () => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Reads the required Node.js version from .nvmrc file.
|
|
47
|
+
*
|
|
48
|
+
* @returns Promise resolving to version string from .nvmrc
|
|
49
|
+
* @throws Error if .nvmrc file doesn't exist
|
|
50
|
+
*/
|
|
51
|
+
getRequiredNode_Version: () => Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Installs required Node.js version if not already installed.
|
|
54
|
+
*
|
|
55
|
+
* Reads .nvmrc, checks installed versions, and installs if missing.
|
|
56
|
+
*
|
|
57
|
+
* @param commando - Commando_NVM instance to use
|
|
58
|
+
* @returns True if version was installed, false if already present
|
|
59
|
+
*/
|
|
60
|
+
installRequiredVersionIfNeeded: (commando: Commando_NVM) => Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Uninstalls NVM by removing its directory.
|
|
63
|
+
*
|
|
64
|
+
* @returns Promise that resolves when uninstall completes
|
|
65
|
+
*/
|
|
66
|
+
uninstall: () => Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Installs a specific Node.js version via NVM.
|
|
69
|
+
*
|
|
70
|
+
* @param commando - Commando_NVM instance to use
|
|
71
|
+
* @param requiredVersion - Optional version (defaults to .nvmrc value)
|
|
72
|
+
* @returns Promise that resolves when installation completes
|
|
73
|
+
*/
|
|
74
|
+
private installVersion;
|
|
75
|
+
}
|
|
76
|
+
export declare const NVM: Cli_NVM;
|
|
@@ -3,6 +3,18 @@ import { promises as _fs } from 'fs';
|
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import { Logger, LogLevel } from '@nu-art/ts-common';
|
|
5
5
|
const CONST__FILE_NVMRC = '.nvmrc';
|
|
6
|
+
/**
|
|
7
|
+
* NVM (Node Version Manager) service for managing Node.js installations.
|
|
8
|
+
*
|
|
9
|
+
* Handles installation, version management, and configuration of NVM.
|
|
10
|
+
* Works with Commando_NVM plugin to execute NVM commands.
|
|
11
|
+
*
|
|
12
|
+
* **Features**:
|
|
13
|
+
* - Install/uninstall NVM
|
|
14
|
+
* - Configure shell RC files (.bashrc, .zshrc)
|
|
15
|
+
* - Version management
|
|
16
|
+
* - Integration with .nvmrc files
|
|
17
|
+
*/
|
|
6
18
|
export class Cli_NVM extends Logger {
|
|
7
19
|
_expectedVersion = '0.39.7';
|
|
8
20
|
_homeEnvVar = '$NVM_DIR';
|
|
@@ -22,6 +34,19 @@ export class Cli_NVM extends Logger {
|
|
|
22
34
|
set expectedVersion(value) {
|
|
23
35
|
this._expectedVersion = value;
|
|
24
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Installs NVM and configures shell RC files.
|
|
39
|
+
*
|
|
40
|
+
* **Behavior**:
|
|
41
|
+
* - Checks if NVM is already installed with expected version
|
|
42
|
+
* - Uninstalls if version mismatch
|
|
43
|
+
* - Installs NVM via Commando_NVM
|
|
44
|
+
* - Configures .bashrc with NVM initialization (if not already present)
|
|
45
|
+
*
|
|
46
|
+
*
|
|
47
|
+
* @param commando - Commando_NVM instance to use for installation
|
|
48
|
+
* @returns This instance for method chaining
|
|
49
|
+
*/
|
|
25
50
|
install = async (commando) => {
|
|
26
51
|
if (this.isInstalled()) {
|
|
27
52
|
const version = (await commando.getVersion()).trim();
|
|
@@ -34,18 +59,34 @@ export class Cli_NVM extends Logger {
|
|
|
34
59
|
let rcFileContent = '';
|
|
35
60
|
if (fs.existsSync(rcFile)) {
|
|
36
61
|
rcFileContent = await _fs.readFile(rcFile, { encoding: 'utf8' });
|
|
37
|
-
|
|
62
|
+
// If NVM is already configured, don't add it again
|
|
63
|
+
if (rcFileContent.includes('NVM_DIR'))
|
|
64
|
+
return this;
|
|
38
65
|
}
|
|
39
|
-
|
|
66
|
+
// Append NVM initialization to the end of the file
|
|
67
|
+
rcFileContent = `${rcFileContent}${rcFileContent.endsWith('\n') ? '' : '\n'}`;
|
|
40
68
|
rcFileContent += `# generated NVM - start\n`;
|
|
41
|
-
rcFileContent += `
|
|
42
|
-
rcFileContent += `
|
|
43
|
-
rcFileContent += `
|
|
69
|
+
rcFileContent += `export NVM_DIR="$HOME/.nvm"\n`;
|
|
70
|
+
rcFileContent += `[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm\n`;
|
|
71
|
+
rcFileContent += `[ -s "$NVM_DIR/bash_completion" ] && \\. "$NVM_DIR/bash_completion" # This loads nvm bash_completion\n`;
|
|
44
72
|
rcFileContent += `# generated NVM - end\n`;
|
|
45
73
|
await _fs.writeFile(rcFile, rcFileContent, { encoding: 'utf8' });
|
|
46
74
|
return this;
|
|
47
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Checks if NVM is installed.
|
|
78
|
+
*
|
|
79
|
+
* Verifies both environment variable and directory existence.
|
|
80
|
+
*
|
|
81
|
+
* @returns True if NVM is installed
|
|
82
|
+
*/
|
|
48
83
|
isInstalled = () => !!process.env[this._homeEnvVar] && fs.existsSync(process.env[this._homeEnvVar]);
|
|
84
|
+
/**
|
|
85
|
+
* Reads the required Node.js version from .nvmrc file.
|
|
86
|
+
*
|
|
87
|
+
* @returns Promise resolving to version string from .nvmrc
|
|
88
|
+
* @throws Error if .nvmrc file doesn't exist
|
|
89
|
+
*/
|
|
49
90
|
getRequiredNode_Version = async () => {
|
|
50
91
|
const absolutePathToNvmrcFile = path.resolve(CONST__FILE_NVMRC);
|
|
51
92
|
if (!fs.existsSync(absolutePathToNvmrcFile))
|
|
@@ -53,6 +94,14 @@ export class Cli_NVM extends Logger {
|
|
|
53
94
|
const content = await _fs.readFile(absolutePathToNvmrcFile, { encoding: 'utf-8' });
|
|
54
95
|
return content.trim();
|
|
55
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* Installs required Node.js version if not already installed.
|
|
99
|
+
*
|
|
100
|
+
* Reads .nvmrc, checks installed versions, and installs if missing.
|
|
101
|
+
*
|
|
102
|
+
* @param commando - Commando_NVM instance to use
|
|
103
|
+
* @returns True if version was installed, false if already present
|
|
104
|
+
*/
|
|
56
105
|
installRequiredVersionIfNeeded = async (commando) => {
|
|
57
106
|
const requiredVersion = await this.getRequiredNode_Version();
|
|
58
107
|
const installedVersions = await commando.getInstalledNodeVersions();
|
|
@@ -62,13 +111,25 @@ export class Cli_NVM extends Logger {
|
|
|
62
111
|
await this.installVersion(commando, requiredVersion);
|
|
63
112
|
return true;
|
|
64
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* Uninstalls NVM by removing its directory.
|
|
116
|
+
*
|
|
117
|
+
* @returns Promise that resolves when uninstall completes
|
|
118
|
+
*/
|
|
65
119
|
uninstall = async () => {
|
|
66
|
-
this.logDebug('Uninstalling
|
|
120
|
+
this.logDebug('Uninstalling NVM');
|
|
67
121
|
const absolutePathToNVM_Home = process.env[this._homeEnvVar];
|
|
68
122
|
if (!absolutePathToNVM_Home)
|
|
69
123
|
return;
|
|
70
124
|
fs.rmSync(absolutePathToNVM_Home, { recursive: true, force: true });
|
|
71
125
|
};
|
|
126
|
+
/**
|
|
127
|
+
* Installs a specific Node.js version via NVM.
|
|
128
|
+
*
|
|
129
|
+
* @param commando - Commando_NVM instance to use
|
|
130
|
+
* @param requiredVersion - Optional version (defaults to .nvmrc value)
|
|
131
|
+
* @returns Promise that resolves when installation completes
|
|
132
|
+
*/
|
|
72
133
|
installVersion = async (commando, requiredVersion) => {
|
|
73
134
|
requiredVersion ??= await this.getRequiredNode_Version();
|
|
74
135
|
this.logDebug(`Installing version: ${requiredVersion}`);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Logger } from '@nu-art/ts-common';
|
|
2
|
+
import { Commando_PNPM } from '../plugins/pnpm.js';
|
|
3
|
+
/**
|
|
4
|
+
* PNPM package manager service for managing PNPM installations.
|
|
5
|
+
*
|
|
6
|
+
* Handles installation, version management, and package operations.
|
|
7
|
+
* Works with Commando_PNPM plugin to execute PNPM commands.
|
|
8
|
+
*
|
|
9
|
+
* **Features**:
|
|
10
|
+
* - Install/uninstall PNPM
|
|
11
|
+
* - Version management
|
|
12
|
+
* - Package installation
|
|
13
|
+
* - Environment variable configuration
|
|
14
|
+
*/
|
|
15
|
+
export declare class Cli_PNPM extends Logger {
|
|
16
|
+
private _expectedVersion;
|
|
17
|
+
private _homeEnvVar;
|
|
18
|
+
constructor();
|
|
19
|
+
get homeEnvVar(): string;
|
|
20
|
+
set homeEnvVar(value: string);
|
|
21
|
+
get expectedVersion(): string;
|
|
22
|
+
set expectedVersion(value: string);
|
|
23
|
+
/**
|
|
24
|
+
* Installs PNPM with the expected version.
|
|
25
|
+
*
|
|
26
|
+
* Checks if PNPM is already installed with the expected version.
|
|
27
|
+
* Uninstalls and reinstalls if version mismatch.
|
|
28
|
+
*
|
|
29
|
+
* @param commando - Commando_PNPM instance to use for installation
|
|
30
|
+
* @returns This instance for method chaining
|
|
31
|
+
*/
|
|
32
|
+
install: (commando: Commando_PNPM) => Promise<this | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if PNPM is installed.
|
|
35
|
+
*
|
|
36
|
+
* Verifies environment variable is set.
|
|
37
|
+
*
|
|
38
|
+
* @returns True if PNPM_HOME environment variable is set
|
|
39
|
+
*/
|
|
40
|
+
isInstalled: () => boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Installs packages using PNPM.
|
|
43
|
+
*
|
|
44
|
+
* Delegates to Commando_PNPM.installPackages().
|
|
45
|
+
*
|
|
46
|
+
* @param commando - Commando_PNPM instance to use
|
|
47
|
+
* @returns Promise that resolves when packages are installed
|
|
48
|
+
*/
|
|
49
|
+
installPackages: (commando: Commando_PNPM) => Promise<Commando_PNPM>;
|
|
50
|
+
/**
|
|
51
|
+
* Uninstalls PNPM by removing its home directory.
|
|
52
|
+
*
|
|
53
|
+
* @returns Promise that resolves when uninstall completes
|
|
54
|
+
*/
|
|
55
|
+
uninstall: () => Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Asynchronously creates a workspace file with a list of packages.
|
|
58
|
+
* Each package is listed under the 'packages:' section in the file.
|
|
59
|
+
*
|
|
60
|
+
* @param listOfLibs An array of library names to include in the workspace.
|
|
61
|
+
* @param pathToWorkspaceFolder The filesystem path where the workspace file will be written.
|
|
62
|
+
* @example
|
|
63
|
+
* await createWorkspace(['pack1', 'pack2'], './path/to/workspace.yaml');
|
|
64
|
+
*/
|
|
65
|
+
createWorkspace: (listOfLibs: string[], pathToWorkspaceFolder?: string) => Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
export declare const PNPM: Cli_PNPM;
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { promises as fs } from 'fs';
|
|
2
2
|
import { Logger, LogLevel } from '@nu-art/ts-common';
|
|
3
3
|
import { convertToFullPath } from '../tools.js';
|
|
4
|
+
/**
|
|
5
|
+
* PNPM package manager service for managing PNPM installations.
|
|
6
|
+
*
|
|
7
|
+
* Handles installation, version management, and package operations.
|
|
8
|
+
* Works with Commando_PNPM plugin to execute PNPM commands.
|
|
9
|
+
*
|
|
10
|
+
* **Features**:
|
|
11
|
+
* - Install/uninstall PNPM
|
|
12
|
+
* - Version management
|
|
13
|
+
* - Package installation
|
|
14
|
+
* - Environment variable configuration
|
|
15
|
+
*/
|
|
4
16
|
export class Cli_PNPM extends Logger {
|
|
5
17
|
_expectedVersion = '10.7.0';
|
|
6
18
|
_homeEnvVar = 'PNPM_HOME';
|
|
@@ -20,6 +32,15 @@ export class Cli_PNPM extends Logger {
|
|
|
20
32
|
set expectedVersion(value) {
|
|
21
33
|
this._expectedVersion = value;
|
|
22
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Installs PNPM with the expected version.
|
|
37
|
+
*
|
|
38
|
+
* Checks if PNPM is already installed with the expected version.
|
|
39
|
+
* Uninstalls and reinstalls if version mismatch.
|
|
40
|
+
*
|
|
41
|
+
* @param commando - Commando_PNPM instance to use for installation
|
|
42
|
+
* @returns This instance for method chaining
|
|
43
|
+
*/
|
|
23
44
|
install = async (commando) => {
|
|
24
45
|
if (this.isInstalled()) {
|
|
25
46
|
const version = (await commando.getVersion());
|
|
@@ -31,10 +52,30 @@ export class Cli_PNPM extends Logger {
|
|
|
31
52
|
await commando.install(this._expectedVersion);
|
|
32
53
|
return this;
|
|
33
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Checks if PNPM is installed.
|
|
57
|
+
*
|
|
58
|
+
* Verifies environment variable is set.
|
|
59
|
+
*
|
|
60
|
+
* @returns True if PNPM_HOME environment variable is set
|
|
61
|
+
*/
|
|
34
62
|
isInstalled = () => !!process.env[this._homeEnvVar];
|
|
63
|
+
/**
|
|
64
|
+
* Installs packages using PNPM.
|
|
65
|
+
*
|
|
66
|
+
* Delegates to Commando_PNPM.installPackages().
|
|
67
|
+
*
|
|
68
|
+
* @param commando - Commando_PNPM instance to use
|
|
69
|
+
* @returns Promise that resolves when packages are installed
|
|
70
|
+
*/
|
|
35
71
|
installPackages = async (commando) => {
|
|
36
72
|
return await commando.installPackages();
|
|
37
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* Uninstalls PNPM by removing its home directory.
|
|
76
|
+
*
|
|
77
|
+
* @returns Promise that resolves when uninstall completes
|
|
78
|
+
*/
|
|
38
79
|
uninstall = async () => {
|
|
39
80
|
this.logDebug('Uninstalling PNPM');
|
|
40
81
|
const absolutePathToPNPM_Home = process.env[this._homeEnvVar];
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Constructor } from '@nu-art/ts-common';
|
|
2
|
+
import { BaseCommando } from '../core/BaseCommando.js';
|
|
3
|
+
/**
|
|
4
|
+
* Simple shell command executor extending BaseCommando.
|
|
5
|
+
*
|
|
6
|
+
* Provides a straightforward way to build and execute shell commands
|
|
7
|
+
* using SimpleShell. Supports file execution and remote file execution.
|
|
8
|
+
*
|
|
9
|
+
* **Features**:
|
|
10
|
+
* - Command building via BaseCommando fluent API
|
|
11
|
+
* - File execution with optional interpreter
|
|
12
|
+
* - Remote file execution via curl
|
|
13
|
+
* - Error handling with CliError
|
|
14
|
+
* - UID tagging for log identification
|
|
15
|
+
*
|
|
16
|
+
* **Error Handling**:
|
|
17
|
+
* - Catches CliError and calls callback with error details
|
|
18
|
+
* - Throws ThisShouldNotHappenException for unexpected errors
|
|
19
|
+
* - Always calls callback (even on error) if provided
|
|
20
|
+
*/
|
|
21
|
+
export declare class Commando extends BaseCommando {
|
|
22
|
+
/** Optional unique identifier for log tagging */
|
|
23
|
+
private uid?;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a Commando instance with plugins.
|
|
26
|
+
*
|
|
27
|
+
* @template T - Array of plugin constructor types
|
|
28
|
+
* @param plugins - Plugin classes to merge
|
|
29
|
+
* @returns Merged Commando instance with plugins
|
|
30
|
+
*/
|
|
31
|
+
static create<T extends Constructor<any>[]>(...plugins: T): (import("../index.js").MergeTypes<[typeof BaseCommando, typeof Commando, ...T]> & BaseCommando) & Commando;
|
|
32
|
+
constructor();
|
|
33
|
+
/**
|
|
34
|
+
* Sets a unique identifier for this commando instance.
|
|
35
|
+
*
|
|
36
|
+
* Used for log tagging to identify which commando instance
|
|
37
|
+
* generated log messages.
|
|
38
|
+
*
|
|
39
|
+
* @param uid - Unique identifier string
|
|
40
|
+
* @returns This instance for method chaining
|
|
41
|
+
*/
|
|
42
|
+
setUID(uid: string): this;
|
|
43
|
+
/**
|
|
44
|
+
* Executes a local file with an optional interpreter.
|
|
45
|
+
*
|
|
46
|
+
* If an interpreter is provided, prefixes the file path with it.
|
|
47
|
+
* Otherwise executes the file directly (must be executable).
|
|
48
|
+
*
|
|
49
|
+
* @param filePath - Path to file to execute
|
|
50
|
+
* @param interpreter - Optional interpreter (e.g., 'node', 'python3')
|
|
51
|
+
* @returns Promise resolving to command output
|
|
52
|
+
*/
|
|
53
|
+
executeFile(filePath: string, interpreter?: string): Promise<{
|
|
54
|
+
stdout: string;
|
|
55
|
+
stderr: string;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Executes a remote file by downloading and piping to interpreter.
|
|
59
|
+
*
|
|
60
|
+
* Uses curl to download the file and pipes it directly to the interpreter.
|
|
61
|
+
* Does not save the file locally.
|
|
62
|
+
*
|
|
63
|
+
* **Security Note**: Executes remote code without verification.
|
|
64
|
+
*
|
|
65
|
+
* @param pathToFile - URL to remote file
|
|
66
|
+
* @param interpreter - Interpreter to execute the file (e.g., 'bash', 'node')
|
|
67
|
+
* @returns Promise resolving to command output
|
|
68
|
+
*/
|
|
69
|
+
executeRemoteFile(pathToFile: string, interpreter: string): Promise<{
|
|
70
|
+
stdout: string;
|
|
71
|
+
stderr: string;
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* Executes the accumulated commands and optionally processes output.
|
|
75
|
+
*
|
|
76
|
+
* **Behavior**:
|
|
77
|
+
* - Resets the command builder (gets accumulated command)
|
|
78
|
+
* - Creates a new SimpleShell instance with debug mode
|
|
79
|
+
* - Executes the command
|
|
80
|
+
* - On success: calls callback with stdout, stderr, exitCode=0
|
|
81
|
+
* - On error: catches CliError, calls callback with error details, returns result
|
|
82
|
+
* - On unexpected error: throws ThisShouldNotHappenException
|
|
83
|
+
*
|
|
84
|
+
* **Note**: The callback is always called if provided, even on error.
|
|
85
|
+
* This allows handling errors without try/catch.
|
|
86
|
+
*
|
|
87
|
+
* @template T - Return type of callback
|
|
88
|
+
* @param callback - Optional function to process command output
|
|
89
|
+
* @returns Promise resolving to callback result or void
|
|
90
|
+
*/
|
|
91
|
+
execute<T>(callback?: (stdout: string, stderr: string, exitCode: number) => T): Promise<T | void>;
|
|
92
|
+
}
|