Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Listr {
constructor(tasks, opts) {
if (tasks && !Array.isArray(tasks) && typeof tasks === 'object') {
if (typeof tasks.title === 'string' && typeof tasks.task === 'function') {
throw new TypeError('Expected an array of tasks or an options object, got a task object');
throw new TypeError(
'Expected an array of tasks or an options object, got a task object'
);
}

opts = tasks;
Expand All @@ -28,12 +30,16 @@ class Listr {
throw new TypeError('Expected an array of tasks');
}

this._options = Object.assign({
showSubtasks: true,
concurrent: false,
renderer: 'default',
nonTTYRenderer: 'verbose'
}, opts);
this._options = Object.assign(
{
showSubtasks: true,
errorOnExit: true,
concurrent: false,
renderer: 'default',
nonTTYRenderer: 'verbose'
},
opts
);
this._tasks = [];

this.concurrency = 1;
Expand All @@ -43,9 +49,13 @@ class Listr {
this.concurrency = this._options.concurrent;
}

this._RendererClass = renderer.getRenderer(this._options.renderer, this._options.nonTTYRenderer);
this._RendererClass = renderer.getRenderer(
this._options.renderer,
this._options.nonTTYRenderer
);

this.exitOnError = this._options.exitOnError;
this.errorOnExit = this._options.errorOnExit;

this.add(tasks || []);
}
Expand Down Expand Up @@ -91,17 +101,23 @@ class Listr {

this._checkAll(context);

const tasks = pMap(this._tasks, task => {
this._checkAll(context);
return runTask(task, context, errors);
}, {concurrency: this.concurrency});
const tasks = pMap(
this._tasks,
task => {
this._checkAll(context);
return runTask(task, context, errors);
},
{ concurrency: this.concurrency }
);

return tasks
.then(() => {
if (errors.length > 0) {
const err = new ListrError('Something went wrong');
err.errors = errors;
throw err;
if (this.errorOnExit === true) {
const err = new ListrError('Something went wrong');
err.errors = errors;
throw err;
}
}

this._renderer.end();
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,13 @@ Default: `true`

Set to `false` if you don't want to stop the execution of other tasks when one or more tasks fail.

##### errorOnExit

Type: `boolean`<br>
Default: `true`

Set to `false` if you don't want an error to be logged at the end of all tasks, if any of them has throwns an error

##### renderer

Type: `string` `object`<br>
Expand Down