diff --git a/index.js b/index.js index b3da8ac..98fd6f9 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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; @@ -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 || []); } @@ -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(); diff --git a/readme.md b/readme.md index e9936fd..e41b203 100644 --- a/readme.md +++ b/readme.md @@ -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`
+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`