Skip to content

Commit

Permalink
Make observeListr function show task progress
Browse files Browse the repository at this point in the history
  • Loading branch information
shroudedcode committed Jan 30, 2021
1 parent 8aaf214 commit df5c100
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/observe-listr.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk = require('chalk')
import Listr = require('listr')
import { Observable, Subscriber } from 'rxjs'

Expand Down Expand Up @@ -36,11 +37,14 @@ class ObservableRenderer implements Listr.ListrRenderer {
}

render() {
for (const task of this.tasks) {
for (const [index, task] of this.tasks.entries()) {
task.subscribe(event => {
if (event.type === 'STATE') {
if (task.isPending()) {
return this.subscriber.next(`=> ${task.title}`)
const progress = `${index + 1}/${this.tasks.length}`
const message = chalk`{dim [${progress}]} ${task.title}`

return this.subscriber.next(message)
} else if (task.isSkipped()) {
return this.subscriber.next(task.output ?? '')
}
Expand Down

0 comments on commit df5c100

Please sign in to comment.