planify
Version:
Plan a series of steps and display the output in a beautiful way
53 lines (41 loc) • 1.23 kB
JavaScript
;
const ProgressBar = require('cli-progress-bar');
const chalk = require('chalk');
const duration = require('./util/duration');
const error = require('./util/error');
function reporter() {
let bar;
let completedSteps;
let totalSteps;
return {
plan: {
start(plan) {
totalSteps = plan.steps.length;
completedSteps = 0;
bar = new ProgressBar();
bar.show('', 0);
},
ok(plan) {
let str;
str = '\n';
str += plan.steps.length + ' step' + (plan.steps.length === 1 ? '' : 's') + ' ok';
str += ' ' + duration(plan, '(%s)') + '\n';
process.stdout.write(str);
},
fail(plan, err) {
let str;
str = '\n';
str += chalk.bold.red('ERROR:') + '\n';
str += error(err);
process.stdout.write(str);
},
},
step: {
ok() {
completedSteps += 1;
bar.show('', completedSteps / totalSteps);
},
},
};
}
module.exports = reporter;