listr
Advanced tools
Comparing version 0.11.0 to 0.12.0
27
index.js
'use strict'; | ||
const pMap = require('p-map'); | ||
const Task = require('./lib/task'); | ||
@@ -19,2 +20,6 @@ const TaskWrapper = require('./lib/task-wrapper'); | ||
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'); | ||
} | ||
opts = tasks; | ||
@@ -35,2 +40,10 @@ tasks = []; | ||
this._tasks = []; | ||
this.concurrency = 1; | ||
if (this._options.concurrent === true) { | ||
this.concurrency = Infinity; | ||
} else if (typeof this._options.concurrent === 'number') { | ||
this.concurrency = this._options.concurrent; | ||
} | ||
this._RendererClass = renderer.getRenderer(this._options.renderer, this._options.nonTTYRenderer); | ||
@@ -84,13 +97,7 @@ | ||
let tasks; | ||
if (this._options.concurrent === true) { | ||
tasks = Promise.all(this._tasks.map(task => runTask(task, context, errors))); | ||
} else { | ||
tasks = this._tasks.reduce((promise, task) => promise.then(() => { | ||
this._checkAll(context); | ||
const tasks = pMap(this._tasks, task => { | ||
this._checkAll(context); | ||
return runTask(task, context, errors); | ||
}, {concurrency: this.concurrency}); | ||
return runTask(task, context, errors); | ||
}), Promise.resolve()); | ||
} | ||
return tasks | ||
@@ -97,0 +104,0 @@ .then(() => { |
@@ -21,2 +21,11 @@ 'use strict'; | ||
set output(data) { | ||
this._task.output = data; | ||
this._task.next({ | ||
type: 'DATA', | ||
data | ||
}); | ||
} | ||
get title() { | ||
@@ -42,3 +51,3 @@ return this._task.title; | ||
if (message) { | ||
this._task._output = message; | ||
this._task.output = message; | ||
} | ||
@@ -45,0 +54,0 @@ |
@@ -41,6 +41,6 @@ 'use strict'; | ||
this._subtasks = []; | ||
this._output = undefined; | ||
this._enabledFn = task.enabled; | ||
this._isEnabled = true; | ||
this.output = undefined; | ||
this.title = task.title; | ||
@@ -51,6 +51,2 @@ this.skip = task.skip || defaultSkipFn; | ||
get output() { | ||
return this._output; | ||
} | ||
get subtasks() { | ||
@@ -140,3 +136,3 @@ return this._subtasks; | ||
next: data => { | ||
this._output = data; | ||
this.output = data; | ||
@@ -170,3 +166,3 @@ this.next({ | ||
if (typeof skipped === 'string') { | ||
this._output = skipped; | ||
this.output = skipped; | ||
} | ||
@@ -192,3 +188,6 @@ this.state = state.SKIPPED; | ||
this._output = err.message; | ||
if (!this.hasSubtasks()) { | ||
// Do not show the message if we have subtasks as the error is already shown in the subtask | ||
this.output = err.message; | ||
} | ||
@@ -195,0 +194,0 @@ this.next({ |
{ | ||
"name": "listr", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"description": "Terminal task list", | ||
@@ -17,3 +17,4 @@ "license": "MIT", | ||
"test": "clinton && xo && nyc ava", | ||
"coveralls": "nyc report --reporter=text-lcov | coveralls" | ||
"coveralls": "nyc report --reporter=text-lcov | coveralls", | ||
"lint:staged": "lint-staged" | ||
}, | ||
@@ -54,2 +55,3 @@ "files": [ | ||
"ora": "^0.2.3", | ||
"p-map": "^1.1.1", | ||
"rxjs": "^5.0.0-beta.11", | ||
@@ -65,3 +67,5 @@ "stream-to-observable": "^0.1.0", | ||
"hook-std": "^0.2.0", | ||
"lint-staged": "^3.3.1", | ||
"nyc": "^8.3.2", | ||
"pre-commit": "^1.2.2", | ||
"xo": "*", | ||
@@ -72,3 +76,7 @@ "zen-observable": "^0.3.0" | ||
"esnext": true | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.js": "xo" | ||
}, | ||
"pre-commit": "lint:staged" | ||
} |
@@ -254,3 +254,3 @@ # listr | ||
A special task object is being passed as second argument into the `task` function. This task object lets you change the title while running your task or you can skip it depending on some results. | ||
A special task object is being passed as second argument into the `task` function. This task object lets you change the title while running your task, you can skip it depending on some results or you can update the task's output. | ||
@@ -272,3 +272,7 @@ ```js | ||
skip: ctx => ctx.yarn !== false && 'Dependencies already installed with Yarn' | ||
task: () => execa('npm', ['install']) | ||
task: (ctx, task) => { | ||
task.output = 'Installing dependencies...'; | ||
return execa('npm', ['install']) | ||
} | ||
} | ||
@@ -383,6 +387,6 @@ ]); | ||
Type: `boolean`<br> | ||
Type: `boolean` `number`<br> | ||
Default: `false` | ||
Set to `true` if you want tasks to run concurrently. | ||
Set to `true` if you want to run tasks in parallel, set to a number to control the concurrency. By default it runs tasks sequentially. | ||
@@ -389,0 +393,0 @@ ##### exitOnError |
22787
364
445
16
10
+ Addedp-map@^1.1.1
+ Addedp-map@1.2.0(transitive)