Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
cd3675280a | |||
7c14102324 | |||
cb41dbaf1c | |||
149eb800e7 | |||
91e84c8422 | |||
ff26cd0678 | |||
acdd729e06 | |||
522fbfc42c | |||
b854715940 | |||
35f59054f8 | |||
c9a3de2207 | |||
6904097960 | |||
1474fd541f | |||
9befccefd6 | |||
415c9de553 | |||
980a2c9781 | |||
c13a0f5d48 | |||
71e239c5b1 | |||
0d7c87051b | |||
067f1a9c17 | |||
e7cf3bcb5e | |||
18cfa3e16a | |||
ea921766dc | |||
7e6d632afb | |||
25c61d7d7d | |||
d84c7a16a4 | |||
c5937da870 |
128
.gitlab-ci.yml
128
.gitlab-ci.yml
@ -1,128 +0,0 @@
|
|||||||
# gitzone ci_default
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: '$CI_BUILD_STAGE'
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- pnpm install -g pnpm
|
|
||||||
- pnpm install -g @shipzone/npmci
|
|
||||||
- npmci npm prepare
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
auditProductionDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command pnpm audit --audit-level=high --prod
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
auditDevDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command pnpm audit --audit-level=high --dev
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testStable:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testBuild:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm build
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run buildDocs
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
87
changelog.md
Normal file
87
changelog.md
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-02-20 - 3.2.3 - fix(core)
|
||||||
|
Refactor Smartshell class for improved code clarity and performance
|
||||||
|
|
||||||
|
- Refactored `_exec` method to improve code clarity.
|
||||||
|
- Introduced `IExecOptions` interface for better type handling.
|
||||||
|
- Replaced promise defer with native promises in command execution methods.
|
||||||
|
- Improved logging and error handling in child process execution.
|
||||||
|
- Ensured robust process management with signals handling.
|
||||||
|
|
||||||
|
## 2024-12-13 - 3.2.2 - fix(core)
|
||||||
|
Fix minor code style and formatting issues
|
||||||
|
|
||||||
|
|
||||||
|
## 2024-12-13 - 3.2.1 - fix(dependencies)
|
||||||
|
Update @types/node dependency version
|
||||||
|
|
||||||
|
- Updated @types/node dependency from version ^22.10.1 to ^22.10.2.
|
||||||
|
|
||||||
|
## 2024-12-09 - 3.2.0 - feat(SmartExecution)
|
||||||
|
Add support for scheduling restarts to SmartExecution
|
||||||
|
|
||||||
|
- Introduced the ability to handle consecutive restarts efficiently in SmartExecution.
|
||||||
|
- Ensures that multiple restart requests merge into a single additional restart request if one is already in progress.
|
||||||
|
|
||||||
|
## 2024-12-09 - 3.1.0 - feat(core)
|
||||||
|
Refactor codebase and update dependencies.
|
||||||
|
|
||||||
|
- Refactored core classes with improved structure and modularization.
|
||||||
|
- Updated tsbuild, tsrun, tapbundle, and @types/node dependencies to newer versions.
|
||||||
|
- Improved build script in package.json to use tsbuild with tsfolders.
|
||||||
|
|
||||||
|
## 2024-09-17 - 3.0.6 - fix(core)
|
||||||
|
Fix interactive shell execution and update dependencies
|
||||||
|
|
||||||
|
- Corrected the interactive shell execution logic by separating it into a dedicated method.
|
||||||
|
- Updated development dependencies for `@git.zone/tsbuild`, `@git.zone/tsrun`, `@git.zone/tstest`, `@push.rocks/tapbundle`, and `@types/node`.
|
||||||
|
- Updated runtime dependencies for `@push.rocks/smartpromise`, and `@types/which`.
|
||||||
|
- Removed legacy .gitlab-ci.yml file.
|
||||||
|
|
||||||
|
## 2024-05-29 - 3.0.5 - Documentation
|
||||||
|
update description
|
||||||
|
|
||||||
|
## 2024-04-18 - 3.0.4 to 3.0.5 - Maintenance
|
||||||
|
Bug fixes and configuration updates
|
||||||
|
|
||||||
|
- fix(core): update
|
||||||
|
- update tsconfig
|
||||||
|
- update npmextra.json: githost
|
||||||
|
|
||||||
|
## 2024-03-16 - 3.0.3 to 3.0.4 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2023-06-22 - 2.0.30 to 3.0.3 - Major Update
|
||||||
|
Major changes including breaking changes, bug fixes, and improvements.
|
||||||
|
|
||||||
|
- BREAKING CHANGE(core): switched to ES syntax and added support for interactivity
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2021-11-07 - 2.0.27 to 2.0.30 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): cosmetics
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2021-08-17 - 2.0.26 to 2.0.27 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2020-05-22 - 2.0.25 to 2.0.26 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2019-08-27 - 2.0.22 to 2.0.25 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2019-05-28 - 2.0.16 to 2.0.22 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): update
|
@ -7,12 +7,26 @@
|
|||||||
"gitzone": {
|
"gitzone": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartshell",
|
"gitrepo": "smartshell",
|
||||||
"description": "shell actions designed as promises",
|
"description": "A library for executing shell commands using promises.",
|
||||||
"npmPackagename": "@pushrocks/smartshell",
|
"npmPackagename": "@push.rocks/smartshell",
|
||||||
"license": "MIT"
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"shell commands",
|
||||||
|
"promises",
|
||||||
|
"asynchronous execution",
|
||||||
|
"child processes",
|
||||||
|
"environment management",
|
||||||
|
"command streaming",
|
||||||
|
"interactive commands",
|
||||||
|
"process management",
|
||||||
|
"typescript"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
43
package.json
43
package.json
@ -1,44 +1,51 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartshell",
|
"name": "@push.rocks/smartshell",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.0.0",
|
"version": "3.2.3",
|
||||||
"description": "shell actions designed as promises",
|
"description": "A library for executing shell commands using promises.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web)",
|
"build": "(tsbuild tsfolders --web)",
|
||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartshell.git"
|
"url": "https://code.foss.global/push.rocks/smartshell.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"shell",
|
"shell commands",
|
||||||
"promise"
|
"promises",
|
||||||
|
"asynchronous execution",
|
||||||
|
"child processes",
|
||||||
|
"environment management",
|
||||||
|
"command streaming",
|
||||||
|
"interactive commands",
|
||||||
|
"process management",
|
||||||
|
"typescript"
|
||||||
],
|
],
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/pushrocks/smartshell/issues"
|
"url": "https://gitlab.com/pushrocks/smartshell/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartshell#README",
|
"homepage": "https://code.foss.global/push.rocks/smartshell",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.66",
|
"@git.zone/tsbuild": "^2.2.0",
|
||||||
"@gitzone/tsrun": "^1.2.42",
|
"@git.zone/tsrun": "^1.3.3",
|
||||||
"@gitzone/tstest": "^1.0.74",
|
"@git.zone/tstest": "^1.0.90",
|
||||||
"@pushrocks/tapbundle": "^5.0.4",
|
"@push.rocks/tapbundle": "^5.5.3",
|
||||||
"@types/node": "^20.3.1"
|
"@types/node": "^22.10.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^3.0.1",
|
"@push.rocks/smartdelay": "^3.0.1",
|
||||||
"@pushrocks/smartexit": "^1.0.20",
|
"@push.rocks/smartexit": "^1.0.23",
|
||||||
"@pushrocks/smartpromise": "^4.0.2",
|
"@push.rocks/smartpromise": "^4.0.4",
|
||||||
"@types/which": "^3.0.0",
|
"@types/which": "^3.0.4",
|
||||||
"tree-kill": "^1.2.2",
|
"tree-kill": "^1.2.2",
|
||||||
"which": "^3.0.1"
|
"which": "^5.0.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
11336
pnpm-lock.yaml
generated
11336
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
167
readme.md
167
readme.md
@ -1,37 +1,152 @@
|
|||||||
# @pushrocks/smartshell
|
# @push.rocks/smartshell
|
||||||
shell actions designed as promises
|
shell actions designed as promises
|
||||||
|
|
||||||
## Availabililty and Links
|
## Install
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartshell)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartshell)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartshell)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartshell/)
|
|
||||||
|
|
||||||
## Status for master
|
To install `@push.rocks/smartshell`, use npm:
|
||||||
|
|
||||||
Status Category | Status Badge
|
```sh
|
||||||
-- | --
|
npm install @push.rocks/smartshell --save
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
```
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
|
||||||
npm | [](https://lossless.cloud)
|
Or if you prefer using Yarn:
|
||||||
Snyk | [](https://lossless.cloud)
|
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
```sh
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
yarn add @push.rocks/smartshell
|
||||||
Code Style | [](https://lossless.cloud)
|
```
|
||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
Ensure that you have TypeScript and the related dependencies installed as well since `@push.rocks/smartshell` is designed to work with TypeScript.
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
The `@push.rocks/smartshell` package simplifies running shell commands within Node.js applications by wrapping these commands within promises. This approach enhances the readability and maintainability of code that relies on shell execution, making it particularly useful in automation scripts, build processes, and any scenario where interaction with the system shell is required.
|
||||||
|
|
||||||
## Contribution
|
### Getting Started with `@push.rocks/smartshell`
|
||||||
|
|
||||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
First, ensure that you import `Smartshell` from `@push.rocks/smartshell` using ESM syntax in your TypeScript file:
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
```typescript
|
||||||
|
import { Smartshell } from '@push.rocks/smartshell';
|
||||||
|
```
|
||||||
|
|
||||||
## Legal
|
### Creating a Smartshell Instance
|
||||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
Before executing any shell command, you need to create an instance of `Smartshell`. The constructor accepts configuration options such as the shell executor (`bash` or `sh`), and optionally, paths to source files and directories to include in the shell’s environment.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const smartShellInstance = new Smartshell({
|
||||||
|
executor: 'bash', // or 'sh'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Executing Commands
|
||||||
|
|
||||||
|
#### Basic Execution
|
||||||
|
|
||||||
|
To execute a shell command, use the `exec` method. This method returns a promise that resolves with an execution result object containing `exitCode` and `stdout`.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
(async () => {
|
||||||
|
const result = await smartShellInstance.exec('echo "Hello, SmartShell"');
|
||||||
|
console.log(result.stdout); // Outputs: Hello, SmartShell
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Silent Execution
|
||||||
|
|
||||||
|
If you prefer not to display the output in the console, use `execSilent`:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
(async () => {
|
||||||
|
const result = await smartShellInstance.execSilent('ls');
|
||||||
|
console.log(result.stdout); // Outputs the list of files and directories
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Strict Execution
|
||||||
|
|
||||||
|
For scenarios where an execution error should immediately throw an exception, use `execStrict`:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const result = await smartShellInstance.execStrict('exit 1');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Command execution failed');
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Streaming Output
|
||||||
|
|
||||||
|
Some commands benefit from streaming output as they execute, especially long-running tasks. For these cases, use `execStreaming`:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
(async () => {
|
||||||
|
const execStreamingResult = await smartShellInstance.execStreaming('tail -f /var/log/system.log');
|
||||||
|
|
||||||
|
execStreamingResult.childProcess.stdout.on('data', (data) => {
|
||||||
|
console.log(data.toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
// Remember to handle the process termination as necessary.
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced Usage
|
||||||
|
|
||||||
|
#### Executing With Custom Environment Variables
|
||||||
|
|
||||||
|
`smartshell` allows for the execution of commands within a modified environment, facilitating the use of custom variables or altered PATH values:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
(async () => {
|
||||||
|
smartShellInstance.shellEnv.addSourceFiles(['/path/to/envFile']);
|
||||||
|
smartShellInstance.shellEnv.pathDirArray.push('/custom/bin');
|
||||||
|
|
||||||
|
const result = await smartShellInstance.exec('echo $CUSTOM_VAR');
|
||||||
|
console.log(result.stdout); // Outputs the value of CUSTOM_VAR
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Interactive Mode
|
||||||
|
|
||||||
|
For commands that require interactive terminal input (not typically recommended for automated scripts), you can use `execInteractive`:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
(async () => {
|
||||||
|
await smartShellInstance.execInteractive('npm init');
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Waiting for Specific Output
|
||||||
|
|
||||||
|
To wait for a specific line before proceeding, you might use `execAndWaitForLine`. This is useful for waiting on a process to log a certain message:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
(async () => {
|
||||||
|
await smartShellInstance.execAndWaitForLine('npm run watch', /Compilation complete./);
|
||||||
|
console.log('The watch process has finished compiling.');
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
Given the vast array of features offered by `@push.rocks/smartshell`, integrating shell operations into your TypeScript applications becomes both straightforward and powerful. By harnessing promises and async/await syntax, `smartshell` effectively streamlines shell interactions, making your code cleaner and more intuitive.
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
12
test/test.ts
12
test/test.ts
@ -1,7 +1,7 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
|
|
||||||
import * as smartshell from '../ts/index.js';
|
import * as smartshell from '../ts/index.js';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
|
||||||
let testSmartshell: smartshell.Smartshell;
|
let testSmartshell: smartshell.Smartshell;
|
||||||
|
|
||||||
@ -15,12 +15,12 @@ tap.test('smartshell should create a Smartshell instance', async () => {
|
|||||||
|
|
||||||
tap.test('smartshell should run async', async () => {
|
tap.test('smartshell should run async', async () => {
|
||||||
let execResult = await testSmartshell.exec('npm -v');
|
let execResult = await testSmartshell.exec('npm -v');
|
||||||
// expect(execResult.stdout).toMatch(/[0-9\.]*/);
|
expect(execResult.stdout).toMatch(/[0-9\.]*/);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('smartshell should run async and silent', async () => {
|
tap.test('smartshell should run async and silent', async () => {
|
||||||
let execResult = await testSmartshell.execSilent('npm -v');
|
let execResult = await testSmartshell.execSilent('npm -v');
|
||||||
// expect(execResult.stdout).toMatch(/[0-9\.]*/);
|
expect(execResult.stdout).toMatch(/[0-9\.]*/);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('smartshell should stream a shell execution', async () => {
|
tap.test('smartshell should stream a shell execution', async () => {
|
||||||
@ -30,7 +30,7 @@ tap.test('smartshell should stream a shell execution', async () => {
|
|||||||
done.resolve(data);
|
done.resolve(data);
|
||||||
});
|
});
|
||||||
let data = await done.promise;
|
let data = await done.promise;
|
||||||
// expect(data).toMatch(/[0-9\.]*/);
|
expect(data).toMatch(/[0-9\.]*/);
|
||||||
await execStreamingResponse.finalPromise;
|
await execStreamingResponse.finalPromise;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ tap.test('should be able to find git', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should spawn an interactive cli', async () => {
|
tap.test('should spawn an interactive cli', async () => {
|
||||||
// await testSmartshell.execInteractive('echo "hi"');
|
await testSmartshell.execInteractive('echo "hi"');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start({
|
tap.start({
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartshell',
|
name: '@push.rocks/smartshell',
|
||||||
version: '3.0.0',
|
version: '3.2.3',
|
||||||
description: 'shell actions designed as promises'
|
description: 'A library for executing shell commands using promises.'
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smartshell.plugins.js';
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a log handler for spawned logs
|
* a log handler for spawned logs
|
55
ts/classes.smartexecution.ts
Normal file
55
ts/classes.smartexecution.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import * as plugins from './plugins.js';
|
||||||
|
import { Smartshell, type IExecResultStreaming } from './classes.smartshell.js';
|
||||||
|
|
||||||
|
export interface IDeferred<T> {
|
||||||
|
resolve: (value?: T | PromiseLike<T>) => void;
|
||||||
|
reject: (reason?: any) => void;
|
||||||
|
promise: Promise<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SmartExecution {
|
||||||
|
public smartshell: Smartshell;
|
||||||
|
public currentStreamingExecution: IExecResultStreaming;
|
||||||
|
public commandString: string;
|
||||||
|
|
||||||
|
private isRestartInProgress = false;
|
||||||
|
private isAnotherRestartRequested = false;
|
||||||
|
|
||||||
|
constructor(commandStringArg: string) {
|
||||||
|
this.commandString = commandStringArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedules a restart. If a restart is currently in progress, any additional calls
|
||||||
|
* to restart will merge into a single additional restart request, which will only execute
|
||||||
|
* once the current restart completes.
|
||||||
|
*/
|
||||||
|
public async restart(): Promise<void> {
|
||||||
|
if (this.isRestartInProgress) {
|
||||||
|
// If there's already a restart in progress, just mark that another restart was requested
|
||||||
|
this.isAnotherRestartRequested = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isRestartInProgress = true;
|
||||||
|
try {
|
||||||
|
if (!this.smartshell) {
|
||||||
|
this.smartshell = new Smartshell({
|
||||||
|
executor: 'bash',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (this.currentStreamingExecution) {
|
||||||
|
await this.currentStreamingExecution.kill();
|
||||||
|
}
|
||||||
|
this.currentStreamingExecution = await this.smartshell.execStreaming(this.commandString);
|
||||||
|
} finally {
|
||||||
|
this.isRestartInProgress = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If another restart was requested while we were busy, we handle it now
|
||||||
|
if (this.isAnotherRestartRequested) {
|
||||||
|
this.isAnotherRestartRequested = false;
|
||||||
|
await this.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
203
ts/classes.smartshell.ts
Normal file
203
ts/classes.smartshell.ts
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
import * as plugins from './plugins.js';
|
||||||
|
import { ShellEnv } from './classes.shellenv.js';
|
||||||
|
import type { IShellEnvContructorOptions, TExecutor } from './classes.shellenv.js';
|
||||||
|
import { ShellLog } from './classes.shelllog.js';
|
||||||
|
import * as cp from 'child_process';
|
||||||
|
|
||||||
|
// -- interfaces --
|
||||||
|
export interface IExecResult {
|
||||||
|
exitCode: number;
|
||||||
|
stdout: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IExecResultStreaming {
|
||||||
|
childProcess: cp.ChildProcess;
|
||||||
|
finalPromise: Promise<IExecResult>;
|
||||||
|
kill: () => Promise<void>;
|
||||||
|
terminate: () => Promise<void>;
|
||||||
|
keyboardInterrupt: () => Promise<void>;
|
||||||
|
customSignal: (signal: plugins.smartexit.TProcessSignal) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IExecOptions {
|
||||||
|
commandString: string;
|
||||||
|
silent?: boolean;
|
||||||
|
strict?: boolean;
|
||||||
|
streaming?: boolean;
|
||||||
|
interactive?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Smartshell {
|
||||||
|
public shellEnv: ShellEnv;
|
||||||
|
public smartexit = new plugins.smartexit.SmartExit();
|
||||||
|
|
||||||
|
constructor(optionsArg: IShellEnvContructorOptions) {
|
||||||
|
this.shellEnv = new ShellEnv(optionsArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a given command asynchronously.
|
||||||
|
*/
|
||||||
|
private async _exec(options: IExecOptions): Promise<IExecResult | IExecResultStreaming | void> {
|
||||||
|
if (options.interactive) {
|
||||||
|
return await this._execInteractive({ commandString: options.commandString });
|
||||||
|
}
|
||||||
|
return await this._execCommand(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes an interactive command.
|
||||||
|
*/
|
||||||
|
private async _execInteractive(options: Pick<IExecOptions, 'commandString'>): Promise<void> {
|
||||||
|
// Skip interactive execution in CI environments.
|
||||||
|
if (process.env.CI) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
const shell = cp.spawn(options.commandString, {
|
||||||
|
stdio: 'inherit',
|
||||||
|
shell: true,
|
||||||
|
detached: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.smartexit.addProcess(shell);
|
||||||
|
|
||||||
|
shell.on('close', (code) => {
|
||||||
|
console.log(`Interactive shell terminated with code ${code}`);
|
||||||
|
this.smartexit.removeProcess(shell);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a command and returns either a non-streaming result or a streaming interface.
|
||||||
|
*/
|
||||||
|
private async _execCommand(options: IExecOptions): Promise<IExecResult | IExecResultStreaming> {
|
||||||
|
const commandToExecute = this.shellEnv.createEnvExecString(options.commandString);
|
||||||
|
const shellLogInstance = new ShellLog();
|
||||||
|
|
||||||
|
const execChildProcess = cp.spawn(commandToExecute, [], {
|
||||||
|
shell: true,
|
||||||
|
cwd: process.cwd(),
|
||||||
|
env: process.env,
|
||||||
|
detached: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.smartexit.addProcess(execChildProcess);
|
||||||
|
|
||||||
|
// Capture stdout and stderr output.
|
||||||
|
execChildProcess.stdout.on('data', (data) => {
|
||||||
|
if (!options.silent) {
|
||||||
|
shellLogInstance.writeToConsole(data);
|
||||||
|
}
|
||||||
|
shellLogInstance.addToBuffer(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
execChildProcess.stderr.on('data', (data) => {
|
||||||
|
if (!options.silent) {
|
||||||
|
shellLogInstance.writeToConsole(data);
|
||||||
|
}
|
||||||
|
shellLogInstance.addToBuffer(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wrap child process termination into a Promise.
|
||||||
|
const childProcessEnded: Promise<IExecResult> = new Promise((resolve, reject) => {
|
||||||
|
execChildProcess.on('exit', (code, signal) => {
|
||||||
|
this.smartexit.removeProcess(execChildProcess);
|
||||||
|
|
||||||
|
const execResult: IExecResult = {
|
||||||
|
exitCode: typeof code === 'number' ? code : (signal ? 1 : 0),
|
||||||
|
stdout: shellLogInstance.logStore.toString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (options.strict && code !== 0) {
|
||||||
|
reject(new Error(`Command "${options.commandString}" exited with code ${code}`));
|
||||||
|
} else {
|
||||||
|
resolve(execResult);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
execChildProcess.on('error', (error) => {
|
||||||
|
this.smartexit.removeProcess(execChildProcess);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// If streaming mode is enabled, return a streaming interface immediately.
|
||||||
|
if (options.streaming) {
|
||||||
|
return {
|
||||||
|
childProcess: execChildProcess,
|
||||||
|
finalPromise: childProcessEnded,
|
||||||
|
kill: async () => {
|
||||||
|
console.log(`Running tree kill with SIGKILL on process ${execChildProcess.pid}`);
|
||||||
|
await plugins.smartexit.SmartExit.killTreeByPid(execChildProcess.pid, 'SIGKILL');
|
||||||
|
},
|
||||||
|
terminate: async () => {
|
||||||
|
console.log(`Running tree kill with SIGTERM on process ${execChildProcess.pid}`);
|
||||||
|
await plugins.smartexit.SmartExit.killTreeByPid(execChildProcess.pid, 'SIGTERM');
|
||||||
|
},
|
||||||
|
keyboardInterrupt: async () => {
|
||||||
|
console.log(`Running tree kill with SIGINT on process ${execChildProcess.pid}`);
|
||||||
|
await plugins.smartexit.SmartExit.killTreeByPid(execChildProcess.pid, 'SIGINT');
|
||||||
|
},
|
||||||
|
customSignal: async (signal: plugins.smartexit.TProcessSignal) => {
|
||||||
|
console.log(`Running tree kill with custom signal ${signal} on process ${execChildProcess.pid}`);
|
||||||
|
await plugins.smartexit.SmartExit.killTreeByPid(execChildProcess.pid, signal);
|
||||||
|
},
|
||||||
|
} as IExecResultStreaming;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For non-streaming mode, wait for the process to complete.
|
||||||
|
return await childProcessEnded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async exec(commandString: string): Promise<IExecResult> {
|
||||||
|
return (await this._exec({ commandString })) as IExecResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execSilent(commandString: string): Promise<IExecResult> {
|
||||||
|
return (await this._exec({ commandString, silent: true })) as IExecResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execStrict(commandString: string): Promise<IExecResult> {
|
||||||
|
return (await this._exec({ commandString, strict: true })) as IExecResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execStrictSilent(commandString: string): Promise<IExecResult> {
|
||||||
|
return (await this._exec({ commandString, silent: true, strict: true })) as IExecResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execStreaming(commandString: string, silent: boolean = false): Promise<IExecResultStreaming> {
|
||||||
|
return (await this._exec({ commandString, silent, streaming: true })) as IExecResultStreaming;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execStreamingSilent(commandString: string): Promise<IExecResultStreaming> {
|
||||||
|
return (await this._exec({ commandString, silent: true, streaming: true })) as IExecResultStreaming;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execInteractive(commandString: string): Promise<void> {
|
||||||
|
await this._exec({ commandString, interactive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execAndWaitForLine(
|
||||||
|
commandString: string,
|
||||||
|
regex: RegExp,
|
||||||
|
silent: boolean = false
|
||||||
|
): Promise<void> {
|
||||||
|
const execStreamingResult = await this.execStreaming(commandString, silent);
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
execStreamingResult.childProcess.stdout.on('data', (chunk: Buffer | string) => {
|
||||||
|
const data = typeof chunk === 'string' ? chunk : chunk.toString();
|
||||||
|
if (regex.test(data)) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execAndWaitForLineSilent(commandString: string, regex: RegExp): Promise<void> {
|
||||||
|
return this.execAndWaitForLine(commandString, regex, true);
|
||||||
|
}
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
export * from './smartshell.classes.smartshell.js';
|
export * from './classes.smartshell.js';
|
||||||
export { which } from './smartshell.plugins.js';
|
export * from './classes.smartexecution.js';
|
||||||
|
export { which } from './plugins.js';
|
||||||
|
6
ts/plugins.ts
Normal file
6
ts/plugins.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import * as smartdelay from '@push.rocks/smartdelay';
|
||||||
|
import * as smartexit from '@push.rocks/smartexit';
|
||||||
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
import which from 'which';
|
||||||
|
|
||||||
|
export { smartdelay, smartexit, smartpromise, which };
|
@ -1,182 +0,0 @@
|
|||||||
import * as plugins from './smartshell.plugins.js';
|
|
||||||
import { ShellEnv } from './smartshell.classes.shellenv.js';
|
|
||||||
import type { IShellEnvContructorOptions, TExecutor } from './smartshell.classes.shellenv.js';
|
|
||||||
import { ShellLog } from './smartshell.classes.shelllog.js';
|
|
||||||
|
|
||||||
import * as cp from 'child_process';
|
|
||||||
|
|
||||||
// -- interfaces --
|
|
||||||
export interface IExecResult {
|
|
||||||
exitCode: number;
|
|
||||||
stdout: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IExecResultStreaming {
|
|
||||||
childProcess: cp.ChildProcess;
|
|
||||||
finalPromise: Promise<IExecResult>;
|
|
||||||
kill: () => void;
|
|
||||||
terminate: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Smartshell {
|
|
||||||
public shellEnv: ShellEnv;
|
|
||||||
public smartexit = new plugins.smartexit.SmartExit();
|
|
||||||
|
|
||||||
constructor(optionsArg: IShellEnvContructorOptions) {
|
|
||||||
this.shellEnv = new ShellEnv(optionsArg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* executes a given command async
|
|
||||||
*/
|
|
||||||
private async _exec(options: {
|
|
||||||
commandString: string,
|
|
||||||
silent?: boolean,
|
|
||||||
strict?: boolean,
|
|
||||||
streaming?: boolean,
|
|
||||||
interactive?: boolean
|
|
||||||
}): Promise<IExecResult | IExecResultStreaming | void> {
|
|
||||||
|
|
||||||
if (options.interactive) {
|
|
||||||
if (process.env.CI) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const done = plugins.smartpromise.defer();
|
|
||||||
const shell = cp.spawn('sh', [], { stdio: 'pipe' });
|
|
||||||
this.smartexit.addProcess(shell);
|
|
||||||
|
|
||||||
const stdInStream = process.stdin.pipe(shell.stdin);
|
|
||||||
const stdOutStream = shell.stdout.pipe(process.stdout);
|
|
||||||
|
|
||||||
shell.on('close', (code) => {
|
|
||||||
console.log(`interactive shell terminated with code ${code}`);
|
|
||||||
stdInStream.removeAllListeners();
|
|
||||||
stdInStream.uncork();
|
|
||||||
stdOutStream.removeAllListeners();
|
|
||||||
stdOutStream.unpipe();
|
|
||||||
shell.kill('SIGTERM');
|
|
||||||
process.stdin.pause();
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
|
|
||||||
let commandString = options.commandString;
|
|
||||||
if (process.env.CI) {
|
|
||||||
commandString += ' && exit';
|
|
||||||
}
|
|
||||||
commandString += '\n';
|
|
||||||
|
|
||||||
shell.stdin.write(commandString);
|
|
||||||
await done.promise;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const done = plugins.smartpromise.defer<IExecResult | IExecResultStreaming>();
|
|
||||||
const childProcessEnded = plugins.smartpromise.defer<IExecResult>();
|
|
||||||
|
|
||||||
let commandToExecute = options.commandString;
|
|
||||||
commandToExecute = this.shellEnv.createEnvExecString(options.commandString);
|
|
||||||
|
|
||||||
const spawnlogInstance = new ShellLog();
|
|
||||||
const execChildProcess = cp.spawn(commandToExecute, [], {
|
|
||||||
shell: true,
|
|
||||||
cwd: process.cwd(),
|
|
||||||
env: process.env,
|
|
||||||
detached: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.smartexit.addProcess(execChildProcess);
|
|
||||||
|
|
||||||
execChildProcess.stdout.on('data', (data) => {
|
|
||||||
if (!options.silent) {
|
|
||||||
spawnlogInstance.writeToConsole(data);
|
|
||||||
}
|
|
||||||
spawnlogInstance.addToBuffer(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
execChildProcess.stderr.on('data', (data) => {
|
|
||||||
if (!options.silent) {
|
|
||||||
spawnlogInstance.writeToConsole(data);
|
|
||||||
}
|
|
||||||
spawnlogInstance.addToBuffer(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
execChildProcess.on('exit', (code, signal) => {
|
|
||||||
this.smartexit.removeProcess(execChildProcess);
|
|
||||||
if (options.strict && code === 1) {
|
|
||||||
done.reject();
|
|
||||||
}
|
|
||||||
|
|
||||||
const execResult = {
|
|
||||||
exitCode: code,
|
|
||||||
stdout: spawnlogInstance.logStore.toString(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!options.streaming) {
|
|
||||||
done.resolve(execResult);
|
|
||||||
}
|
|
||||||
childProcessEnded.resolve(execResult);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (options.streaming) {
|
|
||||||
done.resolve({
|
|
||||||
childProcess: execChildProcess,
|
|
||||||
finalPromise: childProcessEnded.promise,
|
|
||||||
kill: () => {
|
|
||||||
console.log(`running tree kill with SIGKILL on process ${execChildProcess.pid}`);
|
|
||||||
plugins.treeKill(execChildProcess.pid, 'SIGKILL');
|
|
||||||
},
|
|
||||||
terminate: () => {
|
|
||||||
console.log(`running tree kill with SIGTERM on process ${execChildProcess.pid}`);
|
|
||||||
plugins.treeKill(execChildProcess.pid, 'SIGTERM');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return await done.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async exec(commandString: string): Promise<IExecResult> {
|
|
||||||
return (await this._exec({ commandString })) as IExecResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async execSilent(commandString: string): Promise<IExecResult> {
|
|
||||||
return (await this._exec({ commandString, silent: true })) as IExecResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async execStrict(commandString: string): Promise<IExecResult> {
|
|
||||||
return (await this._exec({ commandString, strict: true })) as IExecResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async execStrictSilent(commandString: string): Promise<IExecResult> {
|
|
||||||
return (await this._exec({ commandString, silent: true, strict: true })) as IExecResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async execStreaming(commandString: string, silent: boolean = false): Promise<IExecResultStreaming> {
|
|
||||||
return (await this._exec({ commandString, silent, streaming: true })) as IExecResultStreaming;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async execStreamingSilent(commandString: string): Promise<IExecResultStreaming> {
|
|
||||||
return (await this._exec({ commandString, silent: true, streaming: true })) as IExecResultStreaming;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async execInteractive(commandString: string) {
|
|
||||||
await this._exec({ commandString, interactive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
public async execAndWaitForLine(commandString: string, regexArg: RegExp, silentArg: boolean = false) {
|
|
||||||
let done = plugins.smartpromise.defer();
|
|
||||||
let execStreamingResult = await this.execStreaming(commandString, silentArg);
|
|
||||||
execStreamingResult.childProcess.stdout.on('data', (stdOutChunk: string) => {
|
|
||||||
if (regexArg.test(stdOutChunk)) {
|
|
||||||
done.resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async execAndWaitForLineSilent(commandString: string, regexArg: RegExp) {
|
|
||||||
return this.execAndWaitForLine(commandString, regexArg, true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
|
||||||
import * as smartexit from '@pushrocks/smartexit';
|
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
|
||||||
import which from 'which';
|
|
||||||
|
|
||||||
export { smartdelay, smartexit, smartpromise, which };
|
|
||||||
|
|
||||||
// third party
|
|
||||||
import treeKill from 'tree-kill';
|
|
||||||
|
|
||||||
export { treeKill };
|
|
@ -3,9 +3,12 @@
|
|||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"useDefineForClassFields": false,
|
"useDefineForClassFields": false,
|
||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "ES2022",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "NodeNext",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"verbatimModuleSyntax": true,
|
"verbatimModuleSyntax": true
|
||||||
}
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user