first commit

This commit is contained in:
2026-09-08 20:28:54 +08:00
commit 2ada8d3d5a
37380 changed files with 4886169 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) tiaanduplessis <tiaanduplessis@hotmail.com> (tiaan.beer)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+60
View File
@@ -0,0 +1,60 @@
# shell-exec
[![package version](https://img.shields.io/npm/v/shell-exec.svg?style=flat-square)](https://npmjs.org/package/shell-exec)
[![package downloads](https://img.shields.io/npm/dm/shell-exec.svg?style=flat-square)](https://npmjs.org/package/shell-exec)
[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![package license](https://img.shields.io/npm/l/shell-exec.svg?style=flat-square)](https://npmjs.org/package/shell-exec)
[![make a pull request](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![Greenkeeper badge](https://badges.greenkeeper.io/tiaanduplessis/shell-exec.svg)](https://greenkeeper.io/)
> A tiny cross-platform promise based wrapper around child_process.spawn.
## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [Contribute](#contribute)
- [License](#License)
## Install
This project uses [node](https://nodejs.org) and [npm](https://www.npmjs.com).
```sh
$ npm install shell-exec
$ # OR
$ yarn add shell-exec
```
## Usage
```js
const shellExec = require('shell-exec')
shellExec('echo Hi!').then(console.log).catch(console.log)
// Hi!
// { stdout: '', stderr: '', cmd: 'echo Hi!', code: 0 }
```
## API
### `shellExec(command, options)`
**Parameters:**
- *`command`* {String | Array} - String or Array of commands to run
- *`options`* {Object} - Options object passed to [`child_process.spawn`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)
The function then returns a `Promise`.
## Contribute
1. Fork it and create your feature branch: git checkout -b my-new-feature
2. Commit your changes: git commit -am 'Add some feature'
3.Push to the branch: git push origin my-new-feature
4. Submit a pull request
## License
MIT
+47
View File
@@ -0,0 +1,47 @@
'use strict'
const childProcess = require('child_process')
function shellExec (cmd = '', opts = {}) {
if (Array.isArray(cmd)) {
cmd = cmd.join(';')
}
opts = Object.assign({ stdio: 'pipe', cwd: process.cwd() }, opts)
let child
const shell = process.platform === 'win32' ? { cmd: 'cmd', arg: '/C' } : { cmd: 'sh', arg: '-c' }
try {
child = childProcess.spawn(shell.cmd, [shell.arg, cmd], opts)
} catch (error) {
return Promise.reject(error)
}
return new Promise(resolve => {
let stdout = ''
let stderr = ''
if (child.stdout) {
child.stdout.on('data', data => {
stdout += data
})
}
if (child.stderr) {
child.stderr.on('data', data => {
stderr += data
})
}
child.on('error', error => {
resolve({ error, stdout, stderr, cmd })
})
child.on('close', code => {
resolve({ stdout, stderr, cmd, code })
})
})
}
module.exports = shellExec
+29
View File
@@ -0,0 +1,29 @@
{
"name": "shell-exec",
"version": "1.0.2",
"description": "A tiny cross-platform promise based wrapper around child_process.spawn.",
"license": "MIT",
"repository": {
"url": "https://github.com/tiaanduplessis/shell-exec",
"type": "git"
},
"homepage": "https://github.com/tiaanduplessis/shell-exec",
"bugs": "https://github.com/tiaanduplessis/shell-exec",
"main": "index.js",
"files": [
"index.js"
],
"scripts": {
"test": "jest",
"lint": "standard --fix index.js",
"start": "yarn test",
"pretest": "yarn lint",
"precommit": "yarn test"
},
"author": "Tiaan du Plessis",
"devDependencies": {
"husky": "^0.14.3",
"jest": "^22.4.3",
"standard": "^12.0.0"
}
}