# @keg-hub/spawn-cmd

> Cross platform child_process execution in Node

Latest version **0.3.2** (published 2022-07-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @keg-hub/spawn-cmd
pnpm add @keg-hub/spawn-cmd
yarn add @keg-hub/spawn-cmd
bun add @keg-hub/spawn-cmd
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2022-07-17 |
| First published | 2020-09-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 27.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Lance Tipton |
| Maintainers | lktipton, mpcarolin, keg-admin |

## Links

- npm: https://www.npmjs.com/package/@keg-hub/spawn-cmd
- Repository: https://github.com/keg-hub/keg-hub
- Homepage: https://github.com/keg-hub/keg-hub#readme
- Issues: https://github.com/keg-hub/keg-hub/issues
- npm.io page: https://npm.io/package/@keg-hub/spawn-cmd

## Dependencies (8)

- [tree-kill](https://npm.io/package/tree-kill.md) 1.2.2
- [log-update](https://npm.io/package/log-update.md) 4.0.0
- [shell-exec](https://npm.io/package/shell-exec.md) 1.0.2
- [cross-spawn](https://npm.io/package/cross-spawn.md) 7.0.3
- [cli-progress](https://npm.io/package/cli-progress.md) 3.9.1
- [cli-spinners](https://npm.io/package/cli-spinners.md) 2.6.1
- [app-root-path](https://npm.io/package/app-root-path.md) 3.0.0
- [@keg-hub/jsutils](https://npm.io/package/@keg-hub/jsutils.md) *

## Recent versions

- 0.3.2 (latest) — 2022-07-17
- 0.3.1 — 2022-06-05
- 0.3.0 — 2022-01-05
- 0.2.0 — 2021-12-31
- 0.1.4 — 2021-11-13
- 0.1.3 — 2021-10-29
- 0.1.2 — 2021-03-17
- 0.1.1 — 2021-03-08
- 0.1.0 — 2020-12-17
- 0.0.1 — 2020-09-02

## README

### Spawn-CMD
  * Cross-Platform child_process library for Node

### Dependencies
* [app-root-path](https://github.com/inxilpro/node-app-root-path)
* [@keg-hub/jsutils](https://github.com/keg-hub/@keg-hub/jsutils)
* [tree-kill](https://github.com/pkrumins/node-tree-kill)
* [cross-spawn](https://github.com/moxystudio/node-cross-spawn)
* [shell-exec](https://github.com/tiaanduplessis/shell-exec)

## Install

  * Install with 'yarn' or 'npm'
    ```js
      // With Yarn
      yarn add @keg-hub/spawn-cmd
      // With NPM
      npm install @keg-hub/spawn-cmd
    ```
  * Add to your code
    ```js

      // * Require code
      const { spawnCmd } = require('@keg-hub/spawn-cmd')

      // Spawns a new terminal session and runs `ls -la` inside of it
      await spawnCmd('ls -la')

      // Pass in a config object as the second argument
      // See more information about the config in the config section
      const config = { args: [ '-la' ] cwd: __dirname }
      await spawnCmd('ls', config)

      // Pass in a directory to run the command from as the third argument
      const config = { args: [ '-la' ] cwd: __dirname }
      await spawnCmd('ls', config, path.join(__dirname, '../'))

    ```

### Config Object
  * args <Array> - Arguments to pass to the spawned command
  * cwd - Directory to run the command from
    * This can be overwirtten by passing the cwd as a third argument
  * onExit <Function> - Called when the process exits
  * onStdErr <Function> - Called on stderr output
  * onError <Function> - Called on an error other then stderr
  * onStdOut <Function> - Called on stdout
  * options <Object> - Settings to pass to the spawned process
    * Is joined with the default settings below
      ```js
        defaultSettings = {
          gid: process.getgid(),
          uid: process.getuid(),
          env: process.env,
          cwd: rootDir, // Project root directory, NOT spawn-cmd directory
          stdio: 'inherit',
        }
      ```

### Extra Command
 **asyncCmd**
  * Extra command that wraps around nodes `child_process.exec`
  * Makes it a promise wrapped in a try/catch
  * Also adds the commands exit code
  * Promise resolves consistently
  * Example => 
      ```js
        const { asyncCmd } = require('@keg-hub/spawn-cmd')
        
        ;(()=>{

          const { error, data, exitCode } = await asyncCmd('echo test')

          // String output of stderr
          console.log(error)

          // String output of stdout
          console.log(data)

          // Numbered exit code from the command
          // 0 === success, anything else is exit from error
          console.log(exitCode)

        })()
        

      ```

---
_Source: https://npm.io/package/@keg-hub/spawn-cmd · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
