Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,10 @@ async function embed(args) {
}

async function invokeAndroidBuild(args) {
taskLogger.enableProgressBar();
taskLogger.start(androidBuildSteps[4].start);
taskLogger.setTotal(androidBuildSteps[4].total);
taskLogger.incrementProgress(0.5); // Show initial progress (0% -> 25%)
let keyStore, storePassword, keyAlias,keyPassword;

if (args.buildType === 'debug' && !args.aKeyStore) {
Expand Down Expand Up @@ -413,7 +415,7 @@ async function invokeAndroidBuild(args) {
addProguardRule();
updateOptimizationFlags();
updateAndroidBuildGradleFile(args.buildType);
taskLogger.incrementProgress(1);
taskLogger.incrementProgress(0.5); // 25% -> 50%
await generateSignedApk(keyStore, storePassword, keyAlias, keyPassword, args.packageType);
taskLogger.succeed(androidBuildSteps[4].succeed);
} else {
Expand All @@ -422,12 +424,12 @@ async function invokeAndroidBuild(args) {
label: loggerLabel,
message: 'Updated build.gradle file with debug configuration'
});
taskLogger.incrementProgress(0.5)
taskLogger.incrementProgress(0.5) // 50% -> 75%
try {
await exec('./gradlew', ['assembleDebug'], {
cwd: config.src + 'android'
});
taskLogger.incrementProgress(1.2)
taskLogger.incrementProgress(1.0) // 75% -> 100%
taskLogger.succeed(androidBuildSteps[4].succeed);
} catch(e) {
console.error('error generating release apk. ', e);
Expand Down
5 changes: 5 additions & 0 deletions src/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ async function extractRNZip(src) {

async function setupBuildDirectory(src, dest, platform) {
try{
taskLogger.enableProgressBar();
taskLogger.setTotal(androidBuildSteps[0].total);
taskLogger.start(androidBuildSteps[0].start);
src = await extractRNZip(src);
Expand Down Expand Up @@ -288,6 +289,7 @@ async function setupBuildDirectory(src, dest, platform) {
});
global.logDirectory = logDirectory;
logger.setLogDirectory(logDirectory);
taskLogger.incrementProgress(1); // Complete the final step
taskLogger.info("Full log details can be found in: " + logDirectory);
return {
src: src,
Expand Down Expand Up @@ -358,6 +360,7 @@ async function writeWmRNConfig(content) {
// src points to unzip proj
async function ejectProject(args) {
try {
taskLogger.enableProgressBar();
taskLogger.start(androidBuildSteps[3].start);
taskLogger.setTotal(androidBuildSteps[3].total);
taskLogger.incrementProgress(1);
Expand Down Expand Up @@ -403,6 +406,7 @@ async function ejectProject(args) {

async function prepareProject(args) {
try {
taskLogger.enableProgressBar();
taskLogger.setTotal(androidBuildSteps[1].total);
taskLogger.start(androidBuildSteps[1].start);
config.src = args.dest;
Expand Down Expand Up @@ -441,6 +445,7 @@ async function prepareProject(args) {
}
taskLogger.incrementProgress(1);
taskLogger.succeed(androidBuildSteps[1].succeed);
taskLogger.enableProgressBar();
taskLogger.setTotal(androidBuildSteps[2].total);
taskLogger.start(androidBuildSteps[2].start);
logger.info({
Expand Down
105 changes: 86 additions & 19 deletions src/custom-logger/progress-bar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const chalk = require('chalk');
const readline = require("readline");

class ProgressBar {
constructor(options = {}) {
Expand All @@ -16,79 +15,147 @@ class ProgressBar {
this.completeColor = options.completeColor || null;
this.incompleteColor = options.incompleteColor || null;
this.textColor = options.textColor || null;

// Performance optimizations
this.cachedOutput = '';
this.lastValue = -1;
this.lastPercentage = -1;
this.etaCache = '?';
this.etaCacheTime = 0;
this.etaCacheInterval = 2000; // Cache ETA for 2 seconds
}

start() {
this.startTime = Date.now();
this.invalidateCache();
}

setProgress(value) {
this.value = Math.min(Math.max(0, value), this.total);
const newValue = Math.min(Math.max(0, value), this.total);
if (newValue !== this.value) {
this.value = newValue;
this.invalidateCache();
}
}

incrementProgress(amount = 1) {
this.setProgress(this.value + amount);
}

setTotal(total) {
this.total = total;
if (total !== this.total) {
this.total = total;
this.invalidateCache();
}
}

enable() {
this.showProgressBar = true;
this.invalidateCache();
}

disable() {
this.showProgressBar = false;
this.invalidateCache();
}

status() {
return this.showProgressBar;
}

invalidateCache() {
this.cachedOutput = '';
this.lastValue = -1;
this.lastPercentage = -1;
}

calculateETA() {
if (!this.startTime || this.value === 0) return '?';
const elapsedTime = (Date.now() - this.startTime) / 1000;
if (!this.startTime || this.value === 0 || this.value === this.total) {
return '?';
}

const now = Date.now();

// Use cached ETA if it's still fresh
if (now - this.etaCacheTime < this.etaCacheInterval && this.etaCache !== '?') {
return this.etaCache;
}

const elapsedTime = (now - this.startTime) / 1000;
if (elapsedTime < 2) { // Wait at least 2 seconds before calculating ETA
this.etaCache = '?';
this.etaCacheTime = now;
return '?';
}

const itemsPerSecond = this.value / elapsedTime;
if (itemsPerSecond <= 0) {
this.etaCache = '?';
this.etaCacheTime = now;
return '?';
}

const eta = Math.round((this.total - this.value) / itemsPerSecond);
return isFinite(eta) ? eta : '?';
this.etaCache = isFinite(eta) && eta > 0 ? this.formatTime(eta) : '?';
this.etaCacheTime = now;

return this.etaCache;
}

formatTime(seconds) {
if (seconds < 60) return `${seconds}s`;
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
return `${minutes}m ${remainingSeconds}s`;
}

render() {
if (!this.showProgressBar) return '';

const percentage = Math.floor((this.value / this.total) * 100);

// Use cached output if nothing significant changed
if (this.value === this.lastValue && percentage === this.lastPercentage && this.cachedOutput) {
return this.cachedOutput;
}

const completeLength = Math.round((this.value / this.total) * this.barWidth);
const incompleteLength = this.barWidth - completeLength;

let completeBar = this.barCompleteChar.repeat(completeLength);
let incompleteBar = this.barIncompleteChar.repeat(incompleteLength);

// Apply colors only if specified
if (this.completeColor) completeBar = chalk[this.completeColor](completeBar);
if (this.incompleteColor) incompleteBar = chalk[this.incompleteColor](incompleteBar);

let bar = completeBar + incompleteBar;
const bar = completeBar + incompleteBar;

// Apply textColor only to non-bar parts to preserve bar colors
let formattedText = this.barFormat
.replace('{bar}', bar)
.replace('{percentage}', percentage)
.replace('{value}', this.value)
.replace('{total}', this.total)
.replace('{eta}', this.calculateETA());
.replace('{percentage}', this.textColor ? chalk[this.textColor](percentage) : percentage)
.replace('{value}', this.textColor ? chalk[this.textColor](this.value) : this.value)
.replace('{total}', this.textColor ? chalk[this.textColor](this.total) : this.total)
.replace('{eta}', this.textColor ? chalk[this.textColor](this.calculateETA()) : this.calculateETA());

// Cache the result
this.cachedOutput = formattedText;
this.lastValue = this.value;
this.lastPercentage = percentage;

if (this.textColor){
formattedText = chalk[this.textColor](formattedText);
}
readline.cursorTo(process.stdout, 0);

return formattedText;
}
}

// Create a more efficient overall progress bar (disabled by default)
const overallProgressBar = new ProgressBar({
showProgressBar: true,
barWidth: 40,
showProgressBar: false, // Disabled by default to avoid dual progress bars
barWidth: 30, // Slightly smaller for better performance
completeColor: 'green',
incompleteColor: 'gray',
textColor: 'cyan'
textColor: 'cyan',
barFormat: '[{bar}] {percentage}%' // Removed ETA for overall progress to improve performance
});

module.exports = {
Expand Down
Loading