# git-spawned-promise

> Run git command with child_process.spawn

Latest version **0.1.1** (published 2017-02-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install git-spawned-promise
pnpm add git-spawned-promise
yarn add git-spawned-promise
bun add git-spawned-promise
```

## 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.1.1 |
| Published | 2017-02-09 |
| First published | 2017-02-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | release |
| Keywords | git, promise |

## Links

- npm: https://www.npmjs.com/package/git-spawned-promise
- Repository: https://github.com/dinoboff/git-spawned-promise
- Homepage: https://github.com/dinoboff/git-spawned-promise#readme
- Issues: https://github.com/dinoboff/git-spawned-promise/issues
- npm.io page: https://npm.io/package/git-spawned-promise

## Dependencies (3)

- [split](https://npm.io/package/split.md) ^1.0.0
- [through2](https://npm.io/package/through2.md) ^2.0.3
- [get-stream](https://npm.io/package/get-stream.md) ^3.0.0

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2017-02-09
- 0.1.0 — 2017-02-09
- 0.0.0 — 2017-02-08

## README

# git-spawned-promise

[![Build Status][ci-badge]][travis]
[![Build Status (win)][ci-badge-win]][appveyor]
[![Coverage][codecov-badge]][codecov]
[![bitHound Overall Score][bithound-badge]][bithound]

Promisify a [git][git] [child process], settling once the process exit and its [stdio] streams and [transformers][transformer] close.


## Usage

Operations can ignore `stdout` (`run(...cmd)` method), can return it (`get(...cmd)`method) or can split it while transforming each element (`array(...cmd, {sep, map})`).

In any case, they capture `stderr` and reject errors when the exit codes are not zero, which will including `sdterr` in their messages and as a property:

```js
const gitSpawnedPromise = require('../');

async function init(path = '.') {
  const git = gitPromise();

  // `run()`` ignores stdout.
  await git.run('init', path);
  await git.run('commit', '--allow-empty', '--message', 'chore: first commit');
  await git.run('commit', '--allow-empty', '--message', 'feat: first feature');
  await git.run('commit', '--allow-empty', '--message', 'fix: first fix');
  await git.run('commit', '--allow-empty', '--message', 'feat: second feature');

  const log = ['log', '--format="%s"', '--no-merges', '--grep', 'feat', 'HEAD'];
  const map = msg => msg.slice(5).trim();

  const [hash, feats] = await Promise.all([
    // `get()` resolves with stdout
    git.get('parse-rev', 'HEAD'),

    // `array` splits stdout stream and pipe transform stream.
    git.array(...log, {map, sep: '\n'})
  ]);

  console.log(`Status up to ${hash.slice(0, 7)}...`);
  console.log(feats.map(title => `  ${title}`).join('\n'));
}

// stderr available (when the error is a git error).
init(repo)
  .catch(err => console.log(`${err.stderr} (${err.code})`));
```


## API

- `gitSpawnedPromise`: `function({gitDir: ?string}): GitClient`

  Bound a `GitClient` to a local repository.

- `GitClient`: `function(cmd: string[], ?options: ClientOption): Promise<any,Error>`

  Run the git command and settle once the git child process exit and the stdout/stderr pipe closes, or when either fail.

- `ClientOption`: `{ignore: ?boolean, sep: ?string, map: mapper[]}`

  * `ignore`: ignore stdout when set to `true` (`false` by default).
  * `sep`: separator to split the stream (default to `\n` if a mapper is provided).
  * `map`: when splitting a stream, apply each element and replace the returned value. If the value is a promise it will resolve it.

  if `sep` or `map` are set, the `gitCLient` `Promise` will resolve to an `Array`.

- `Mapper`: function(item: any): any

  A handler for a `stream.Transformer` for `stdout`. Unlike regular handler async values are passed via a `Promise` instead of a callback function, and returning `null` (or `Promise<null>)` does not close the stream; the Transformer would just skip the value.

  If the mapper throws or reject, the `GitClient` returned `Promise` will reject with that error.

- `GitClient.run`: `function(...cmd: string[]): Promise<void,GitError>`

  `gitClient.run(...cmd)` is equivalent to `gitClient(cmd, {capture: true})`.

- `GitClient.get`: `function(...cmd: string[]): Promise<string,GitError>`

  `gitClient.get(...cmd)` is equivalent to `gitClient(cmd)`.

- `GitClient.array`: `function(...cmd: string[], ?options: ClientOption): Promise<any[],Error>`

  `gitClient.array(...cmd)` is equivalent to `gitClient(cmd, {sep: '\n', map: someMapperOrMappperArray})`.



## Installation

using npm:

```shell
npm install git-spawned-promise
```


## License

MIT License

Copyright (c) 2017 Damien Lebrun

[git]: https://git-scm.com/
[child process]: https://nodejs.org/api/child_process.html#child_process_class_childprocess
[stdio]: https://nodejs.org/api/child_process.html#child_process_options_stdio
[transformer]: https://nodejs.org/api/stream.html#stream_duplex_and_transform_streams
[travis]: https://travis-ci.org/dinoboff/git-spawned-promise
[ci-badge]: https://travis-ci.org/dinoboff/git-spawned-promise.svg?branch=master
[appveyor]: https://ci.appveyor.com/project/dinoboff/git-spawned-promise/branch/master
[ci-badge-win]: https://ci.appveyor.com/api/projects/status/sgjrh23qgd1g5bd9/branch/master?svg=true
[bithound]: https://www.bithound.io/github/dinoboff/git-spawned-promise
[bithound-badge]: https://www.bithound.io/github/dinoboff/git-spawned-promise/badges/score.svg
[codecov]: https://codecov.io/gh/dinoboff/git-spawned-promise
[codecov-badge]: https://codecov.io/gh/dinoboff/git-spawned-promise/branch/master/graph/badge.svg

---
_Source: https://npm.io/package/git-spawned-promise · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
