Socket
Socket
Sign inDemoInstall

listr

Package Overview
Dependencies
8
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.3.0

29

lib/task.js

@@ -7,2 +7,4 @@ 'use strict';

const indentString = require('indent-string');
const isStream = require('is-stream');
const streamToObservable = require('stream-to-observable');
const LocalRenderer = require('./renderer').LocalRenderer;

@@ -59,2 +61,6 @@ const state = require('./state');

if (this.state === state.PENDING && this._lastLine) {
out += `\n ${indentString(chalk.gray(`${figures.arrowRight} ${this._lastLine}`), ' ', this._listr.level)}`;
}
return out;

@@ -67,6 +73,6 @@ }

this.state = state.PENDING;
const result = this.task();
let result = this.task();
// Detect the subtask
if (result.addTask && result.run) {
// Oh yes, we have a subtask!
result.level = this._listr.level + 1;

@@ -78,2 +84,21 @@ result.setRenderer(LocalRenderer);

// Detect stream
if (isStream(result)) {
result = streamToObservable(result);
}
// https://github.com/sindresorhus/is-observable/issues/1
// Detect Observable
if (result.subscribe && result.forEach) {
return new Promise((resolve, reject) => {
result.subscribe(
data => {
this._lastLine = data.trim().split('\n').pop();
},
reject,
resolve
);
});
}
return result;

@@ -80,0 +105,0 @@ })

7

package.json
{
"name": "listr",
"version": "0.2.0",
"version": "0.3.0",
"description": "Terminal task list",

@@ -43,5 +43,7 @@ "license": "MIT",

"indent-string": "^2.1.0",
"is-stream": "^1.1.0",
"log-symbols": "^1.0.2",
"log-update": "^1.0.2",
"ora": "^0.2.3"
"ora": "^0.2.3",
"stream-to-observable": "^0.1.0"
},

@@ -51,2 +53,3 @@ "devDependencies": {

"clinton": "*",
"rxjs": "^5.0.0-beta.9",
"xo": "*"

@@ -53,0 +56,0 @@ },

@@ -5,3 +5,3 @@ # listr [![Build Status](https://travis-ci.org/SamVerschueren/listr.svg?branch=master)](https://travis-ci.org/SamVerschueren/listr)

<img src="screenshot.gif" width="627">
<img src="media/screenshot.gif" width="774">

@@ -65,2 +65,76 @@ ## Install

### Task
A `task` can return different values. If a `task` returns, it means the task was completed succesfully. If a task throws an error, the task failed.
```js
const tasks = new Listr([
{
title: 'Success',
task: () => 'Foo'
},
{
title: 'Failure',
task: () => {
throw new Error('Bar')
}
}
]);
```
#### Promises
A `task` can also be async by returning a `Promise`. If the promise resolves, the task completed sucessfully, it it rejects, the task failed.
```js
const tasks = new Listr([
{
title: 'Success',
task: () => Promise.resolve('Foo');
},
{
title: 'Failure',
task: () => Promise.reject('Bar')
}
]);
```
#### Observable
<img src="media/observable.gif" width="255" align="right">
A `task` can also return an `Observable`. The thing about observables is that it can emit multiple values and can be used to show the output of the
task. Please note that only the last line of the output is rendered.
```js
const tasks = new Listr([
{
title: 'Success',
task: () => {
return new Observable(observer => {
observer.next('Foo');
setTimeout(() => {
observer.next('Bar');
}, 2000);
setTimeout(() => {
observer.complete();
}, 4000);
});
}
},
{
title: 'Failure',
task: () => Promise.reject(new Error('Bar'))
}
]);
```
#### Streams
It's also possible to return a `stream`. The stream will be converted to an `Observable` and handled as such.
## API

@@ -67,0 +141,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc