diff --git a/src/build/buildMain.js b/src/build/buildMain.js index 382f58e..0da0844 100644 --- a/src/build/buildMain.js +++ b/src/build/buildMain.js @@ -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) { diff --git a/src/helpers/dishonestProgress.js b/src/helpers/dishonestProgress.js new file mode 100644 index 0000000..02e20cf --- /dev/null +++ b/src/helpers/dishonestProgress.js @@ -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;