Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/manovotny/execa-output

A utility to display command output when using execa with listr.
https://github.com/manovotny/execa-output

child-process command execa listr observable output process task

Last synced: 12 days ago
JSON representation

A utility to display command output when using execa with listr.

Awesome Lists containing this project

README

        

# execa-output

> A utility to display command output when using [execa](https://www.npmjs.com/package/execa) with [listr](https://www.npmjs.com/package/listr).

`execa-output` is responsible for creating the output sub text, like `→ text`, as seen in the screenshot below.

![Screenshot](assets/demo.gif)

## Install

### NPM

```
$ npm i execa-output
```

### Yarn

```
$ yarn add execa-output
```

## Usage

Basic usage is exactly the same as using `execa`.

```js
const execa = require('execa');
const execao = require('execa-output');
const Listr = require('listr');

const tasks = new Listr([
{
task: () => execa('some', ['command']),
title: 'Comamnd without output or output you do not care to show'
},
{
task: () => execao('some', ['other', 'command']),
title: 'Command with output you want to show'
}
]);

tasks.run().catch((error) => {
console.error(error);
});
```

You can also pass in options to `execa`, just like when using `execa` directly.

```js
const execao = require('execa-output');

const options = {};

execao('some', ['command'], options);
```

Lastly, you can also provide a callback when you need access to the commnand output.

```js
const execao = require('execa-output');

execao('some', ['command'], null, (result) => {
console.log('command output:', value);
});
```

## Credit

I use [np](https://github.com/sindresorhus/np) to release npm packages and I have always :heart: it's simple, elegant presentation. It's how I learned about [execa](https://github.com/sindresorhus/execa) and [listr](https://github.com/SamVerschueren/listr), which I now use to build a lot of my own, custom [npm scripts](https://docs.npmjs.com/misc/scripts).

There's [an issue on listr](https://github.com/SamVerschueren/listr/issues/90) where people wanted to know how to display long running task output and [it was recommended](https://github.com/SamVerschueren/listr/issues/90#issuecomment-382702459) that one could reimplement / resue [the code np uses](https://github.com/sindresorhus/np/blob/5d923655a3986d04ea14035d20d5c0c16964b7fe/index.js#L17-L25).

This is exactly why `execa-output` was created.

All credit for this code goes to [@sindresorhus](https://github.com/sindresorhus) and [@SamVerschueren](https://github.com/SamVerschueren) for the original implementation. :pray:

I simply modularized it for reuse.

## License

MIT © [Michael Novotny](https://manovotny.com)