UNPKG

angular-ide

Version:

Provides a seamless integration with the Angular IDE from the command-line for developers looking for an enhanced development experience with Angular.

62 lines (50 loc) 1.49 kB
const readline = require('readline'); const R = require('ramda'); const chalk = require('chalk'); function ProgressBar(format) { this.format = format; } ProgressBar.prototype.update = function update(currentValue, maxValue) { const barWidth = 20; const barFilled = Math.ceil((currentValue / maxValue) * (barWidth) ); const barRemaining = barWidth - barFilled; const leftSide = chalk.dim('['); const rightSide = chalk.dim(']'); const progress = chalk.green(R.range(0, barFilled).map(R.always('=')).join('')); const remaining = chalk.yellow( R.range(0, barRemaining).map(R.always('-')).join('') ); const percentCompleted = ((currentValue / maxValue) * 100) .toFixed() .toString(); const bar = leftSide.concat(progress, remaining, rightSide); const replaceData = [ { token: ':bar', value: bar, }, { token: ':completed', value: percentCompleted, }, ]; const progressBarText = R.reduce( (currentString, replaceData) => { return R.apply(R.curry(R.replace), R.concat( R.props(['token', 'value'], replaceData), [currentString] ) ); }, this.format, replaceData ); readline.clearLine(process.stdout, -1); process.stdout.write(progressBarText); readline.moveCursor(process.stdout, -progressBarText.length, 0); }; ProgressBar.prototype.complete = function complete() { process.stdout.write("\n"); }; module.exports = ProgressBar;