mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-06-17 11:22:20 +00:00
Use separate progress bar
This commit is contained in:
parent
013e988391
commit
09e5d3b7c7
|
@ -4,7 +4,7 @@ import tmp from 'tmp';
|
||||||
import ncp from 'ncp';
|
import ncp from 'ncp';
|
||||||
import async from 'async';
|
import async from 'async';
|
||||||
import hasBinary from 'hasbin';
|
import hasBinary from 'hasbin';
|
||||||
import ProgressBar from 'progress';
|
import DishonestProgress from './../helpers/dishonestProgress';
|
||||||
import optionsFactory from './../options/optionsMain';
|
import optionsFactory from './../options/optionsMain';
|
||||||
import iconBuild from './iconBuild';
|
import iconBuild from './iconBuild';
|
||||||
import helpers from './../helpers/helpers';
|
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
|
// todo check if this is still needed on later version of packager
|
||||||
const packagerConsole = new PackagerConsole();
|
const packagerConsole = new PackagerConsole();
|
||||||
|
|
||||||
const bar = new ProgressBar(' :task [:bar] :percent', {
|
const progress = new DishonestProgress(5);
|
||||||
complete: '=',
|
|
||||||
incomplete: ' ',
|
|
||||||
total: 5,
|
|
||||||
width: 50,
|
|
||||||
clear: true
|
|
||||||
});
|
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
callback => {
|
callback => {
|
||||||
bar.tick({
|
progress.tick('infering');
|
||||||
task: 'infering'
|
|
||||||
});
|
|
||||||
optionsFactory(options, callback);
|
optionsFactory(options, callback);
|
||||||
},
|
},
|
||||||
(options, callback) => {
|
(options, callback) => {
|
||||||
bar.tick({
|
progress.tick('copying');
|
||||||
task: 'copying'
|
|
||||||
});
|
|
||||||
buildApp(options.dir, tmpPath, options, error => {
|
buildApp(options.dir, tmpPath, options, error => {
|
||||||
if (error) {
|
if (error) {
|
||||||
callback(error);
|
callback(error);
|
||||||
|
@ -64,17 +54,13 @@ function buildMain(options, callback) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
(options, callback) => {
|
(options, callback) => {
|
||||||
bar.tick({
|
progress.tick('icons');
|
||||||
task: 'icons'
|
|
||||||
});
|
|
||||||
iconBuild(options, (error, optionsWithIcon) => {
|
iconBuild(options, (error, optionsWithIcon) => {
|
||||||
callback(null, optionsWithIcon);
|
callback(null, optionsWithIcon);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
(options, callback) => {
|
(options, callback) => {
|
||||||
bar.tick({
|
progress.tick('packaging');
|
||||||
task: 'packaging'
|
|
||||||
});
|
|
||||||
// maybe skip passing icon parameter to electron packager
|
// maybe skip passing icon parameter to electron packager
|
||||||
const packageOptions = maybeNoIconOption(options);
|
const packageOptions = maybeNoIconOption(options);
|
||||||
|
|
||||||
|
@ -90,9 +76,7 @@ function buildMain(options, callback) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
(options, appPathArray, callback) => {
|
(options, appPathArray, callback) => {
|
||||||
bar.tick({
|
progress.tick('finalizing');
|
||||||
task: 'finalizing'
|
|
||||||
});
|
|
||||||
// somehow appPathArray is a 1 element array
|
// somehow appPathArray is a 1 element array
|
||||||
const appPath = getAppPath(appPathArray);
|
const appPath = getAppPath(appPathArray);
|
||||||
if (!appPath) {
|
if (!appPath) {
|
||||||
|
|
68
src/helpers/dishonestProgress.js
Normal file
68
src/helpers/dishonestProgress.js
Normal 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;
|
Loading…
Reference in New Issue
Block a user