Use separate progress bar

This commit is contained in:
Jia Hao 2016-03-14 00:27:13 +08:00
parent 013e988391
commit 09e5d3b7c7
2 changed files with 75 additions and 23 deletions

View File

@ -4,7 +4,7 @@ import tmp from 'tmp';
import ncp from 'ncp';
import async from 'async';
import hasBinary from 'hasbin';
import ProgressBar from 'progress';
import DishonestProgress from './../helpers/dishonestProgress';
import optionsFactory from './../options/optionsMain';
import iconBuild from './iconBuild';
import helpers from './../helpers/helpers';
@ -34,25 +34,15 @@ function buildMain(options, callback) {
// todo check if this is still needed on later version of packager
const packagerConsole = new PackagerConsole();
const bar = new ProgressBar(' :task [:bar] :percent', {
complete: '=',
incomplete: ' ',
total: 5,
width: 50,
clear: true
});
const progress = new DishonestProgress(5);
async.waterfall([
callback => {
bar.tick({
task: 'infering'
});
progress.tick('infering');
optionsFactory(options, callback);
},
(options, callback) => {
bar.tick({
task: 'copying'
});
progress.tick('copying');
buildApp(options.dir, tmpPath, options, error => {
if (error) {
callback(error);
@ -64,17 +54,13 @@ function buildMain(options, callback) {
});
},
(options, callback) => {
bar.tick({
task: 'icons'
});
progress.tick('icons');
iconBuild(options, (error, optionsWithIcon) => {
callback(null, optionsWithIcon);
});
},
(options, callback) => {
bar.tick({
task: 'packaging'
});
progress.tick('packaging');
// maybe skip passing icon parameter to electron packager
const packageOptions = maybeNoIconOption(options);
@ -90,9 +76,7 @@ function buildMain(options, callback) {
});
},
(options, appPathArray, callback) => {
bar.tick({
task: 'finalizing'
});
progress.tick('finalizing');
// somehow appPathArray is a 1 element array
const appPath = getAppPath(appPathArray);
if (!appPath) {

View File

@ -0,0 +1,68 @@
import ProgressBar from 'progress';
class DishonestProgress {
constructor(total) {
this.tickParts = total * 10;
this.bar = new ProgressBar(' :task [:bar] :percent', {
complete: '=',
incomplete: ' ',
total: total * this.tickParts,
width: 50,
clear: true
});
this.tickingPrevious = {
message: '',
remainder: 0,
interval: null
};
}
tick(message) {
const {remainder: prevRemainder, message: prevMessage, interval: prevInterval} = this.tickingPrevious;
if (prevRemainder) {
this.bar.tick(prevRemainder, {
task: prevMessage
});
clearInterval(prevInterval);
}
const realRemainder = this.bar.total - this.bar.curr;
if (realRemainder === this.tickParts) {
this.bar.tick(this.tickParts, {
task: message
});
return;
}
this.bar.tick({
task: message
});
this.tickingPrevious = {
message: message,
remainder: this.tickParts,
interval: null
};
this.tickingPrevious.remainder -= 1;
this.tickingPrevious.interval = setInterval(() => {
if (this.tickingPrevious.remainder === 1) {
clearInterval(this.tickingPrevious.interval);
return;
}
this.bar.tick({
task: message
});
this.tickingPrevious.remainder -= 1;
}, 200);
}
}
export default DishonestProgress;