Tired of wrestling with Node.js child processes? Meet `@push.rocks/smartshell` - your promise-based shell command companion that makes executing system commands feel like a breeze. Whether you're building automation scripts, CI/CD pipelines, or need fine-grained control over shell execution, smartshell has got you covered.
### ✨ Key Features
- 🎯 **Promise-based API** - Async/await ready for modern codebases
- 🔇 **Silent execution modes** - Control output verbosity
- 📡 **Streaming support** - Real-time output for long-running processes
- 🎮 **Interactive commands** - Handle user input when needed
- ⚡ **Smart execution modes** - Strict, silent, or streaming
- 🔍 **Pattern matching** - Wait for specific output patterns
- 🌍 **Environment management** - Custom env vars and PATH handling
- 🛡️ **TypeScript first** - Full type safety and IntelliSense
**Key Point:** Silent methods (`execSilent`, `execStrictSilent`, `execStreamingSilent`) suppress console output but still capture everything in the result object for programmatic access.
finalPromise: Promise<void>; // Resolves when process exits
}
```
## Understanding Silent Modes 🤫
Silent execution modes are perfect when you need to capture command output for processing without cluttering the console. Here's what you need to know:
### How Silent Modes Work
1.**Output is captured, not lost**: All stdout content is stored in the result object
2.**Console stays clean**: Nothing is printed during execution
3.**Full programmatic access**: Process the output however you need
1.**Choose the right executor**: Use `bash` for full features, `sh` for minimal overhead
2.**Use strict mode for critical operations**: Ensures failures don't go unnoticed
3.**Stream long-running processes**: Better UX and memory efficiency
4.**Leverage silent modes**: When you only need to capture output
5.**Handle errors gracefully**: Always wrap strict executions in try-catch
6.**Clean up resources**: Streaming processes should be properly terminated
## 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.# @push.rocks/smartshell 🐚
**Execute shell commands with superpowers in Node.js**
Tired of wrestling with Node.js child processes? Meet `@push.rocks/smartshell` - your promise-based shell command companion that makes executing system commands feel like a breeze. Whether you're building automation scripts, CI/CD pipelines, or need fine-grained control over shell execution, smartshell has got you covered.
### ✨ Key Features
- 🎯 **Promise-based API** - Async/await ready for modern codebases
- 🔇 **Silent execution modes** - Control output verbosity
- 📡 **Streaming support** - Real-time output for long-running processes
- 🎮 **Interactive commands** - Handle user input when needed
- ⚡ **Smart execution modes** - Strict, silent, or streaming
- 🔍 **Pattern matching** - Wait for specific output patterns
- 🌍 **Environment management** - Custom env vars and PATH handling
- 🛡️ **TypeScript first** - Full type safety and IntelliSense
## Installation 📦
```bash
# Using npm
npm install @push.rocks/smartshell --save
# Using yarn
yarn add @push.rocks/smartshell
# Using pnpm (recommended)
pnpm add @push.rocks/smartshell
```
## Quick Start 🏃♂️
```typescript
import { Smartshell } from '@push.rocks/smartshell';
// Create your shell instance
const shell = new Smartshell({
executor: 'bash' // or 'sh' for lighter shells
});
// Run a simple command
const result = await shell.exec('echo "Hello, World!"');
console.log(result.stdout); // "Hello, World!"
```
## Core Concepts 💡
### The Smartshell Instance
The heart of smartshell is the `Smartshell` class. Each instance maintains its own environment and configuration:
```typescript
const shell = new Smartshell({
executor: 'bash', // Choose your shell: 'bash' or 'sh'
sourceFilePaths: ['/path/to/env.sh'], // Optional: source files on init
});
```
## Execution Modes 🎛️
### Standard Execution
Perfect for general commands where you want to see the output:
```typescript
const result = await shell.exec('ls -la');
console.log(result.stdout); // Directory listing
console.log(result.exitCode); // 0 for success
```
### Silent Execution
Run commands without printing to console - ideal for capturing output:
```typescript
const result = await shell.execSilent('cat /etc/hostname');
// Output is NOT printed to console but IS captured in result
console.log(result.stdout); // Access the captured output here
**Key Point:** Silent methods (`execSilent`, `execStrictSilent`, `execStreamingSilent`) suppress console output but still capture everything in the result object for programmatic access.
### Strict Execution
Throws an error if the command fails - great for critical operations:
```typescript
try {
await shell.execStrict('critical-command');
console.log('✅ Command succeeded!');
} catch (error) {
console.error('❌ Command failed:', error);
}
```
### Streaming Execution
For long-running processes or when you need real-time output:
Silent execution modes are perfect when you need to capture command output for processing without cluttering the console. Here's what you need to know:
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.
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.