Skip to content

Commit

Permalink
Fix the build script progress bar
Browse files Browse the repository at this point in the history
holy crap that was driving me up the wall
  • Loading branch information
pineapplemachine committed Feb 7, 2019
1 parent 3305cb6 commit b1da481
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/logger.js
Expand Up @@ -43,9 +43,12 @@ Logger.prototype.log = function (type, libName, err, libSource) {

var message = makeMsg(err)

if (this.last == 'progress')
process.stdout.write('\033[1F\033[0K')
if (type !== SUCCESS || this.verbose) {
if (this.last == 'progress') {
process.stdout.cursorTo(0)
process.stdout.write('\033[1F\033[0K')
process.stdout.clearLine(1)
}
process.stdout.write(
strings.rpad((type.toUpperCase() + ':'), 8)[type === ERROR ? 'red' : type === WARNING ? 'yellow' : 'green']
+ ' ' + strings.rpad(libName || 'UNKNOWN LIBRARY', 20).bold
Expand All @@ -54,8 +57,8 @@ Logger.prototype.log = function (type, libName, err, libSource) {
)
if (libSource)
console.log(strings.lpad('', 8), Array.isArray(libSource) ? libSource.join(', ') : libSource)
this.last = 'log'
}
this.last = 'log'
}

Logger.prototype.progress = function (completed, total) {
Expand All @@ -70,9 +73,13 @@ Logger.prototype.progress = function (completed, total) {
, PROGRESS_BAR_LENGTH)
+ '| ' + perc + '%' // (' + completed + '/' + total + ')'

if (this.last == 'progress')
process.stdout.write('\033[1F\033[0K')
console.log(ps.green.bold)
if (this.last == 'progress') {
process.stdout.cursorTo(0)
process.stdout.write(ps.green.bold)
process.stdout.clearLine(1)
} else {
process.stdout.write(ps.green.bold)
}
this.last = 'progress'
}

Expand Down

0 comments on commit b1da481

Please sign in to comment.