From 7d956b2ac1a5ba0a8d00bf8f177966cba34ed9f0 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Sat, 1 Mar 2025 11:46:27 +0530 Subject: [PATCH] Added progress bar while publishing to github --- packages/publisher/github/package.json | 2 ++ .../publisher/github/src/PublisherGithub.ts | 23 +++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/publisher/github/package.json b/packages/publisher/github/package.json index b7c776f573..8d11845f73 100644 --- a/packages/publisher/github/package.json +++ b/packages/publisher/github/package.json @@ -8,6 +8,7 @@ "main": "dist/PublisherGithub.js", "typings": "dist/PublisherGithub.d.ts", "devDependencies": { + "@types/cli-progress": "^3.11.6", "vitest": "^3.0.3" }, "engines": { @@ -22,6 +23,7 @@ "@octokit/rest": "^18.0.11", "@octokit/types": "^6.1.2", "chalk": "^4.0.0", + "cli-progress": "^3.12.0", "debug": "^4.3.1", "fs-extra": "^10.0.0", "log-symbols": "^4.0.0", diff --git a/packages/publisher/github/src/PublisherGithub.ts b/packages/publisher/github/src/PublisherGithub.ts index a219924eba..f303da90ef 100644 --- a/packages/publisher/github/src/PublisherGithub.ts +++ b/packages/publisher/github/src/PublisherGithub.ts @@ -5,6 +5,7 @@ import { ForgeMakeResult } from '@electron-forge/shared-types'; import { RequestError } from '@octokit/request-error'; import { GetResponseDataTypeFromEndpointMethod } from '@octokit/types'; import chalk from 'chalk'; +import cliProgress from 'cli-progress'; import fs from 'fs-extra'; import logSymbols from 'log-symbols'; import mime from 'mime-types'; @@ -90,19 +91,26 @@ export default class PublisherGithub extends PublisherBase { - setStatusLine(`Uploading distributable (${uploaded}/${artifacts.length} to ${releaseName})`); - }; - updateUploadStatus(); + const totalArtifacts = artifacts.flatMap((artifact) => artifact.artifacts).length; + + const progressBar = new cliProgress.SingleBar( + { + format: `Uploading to ${releaseName} | {bar} | {percentage}% ({value}/{total})`, + barCompleteChar: '#', + barIncompleteChar: '.', + hideCursor: true, + }, + cliProgress.Presets.shades_classic + ); + + progressBar.start(totalArtifacts, 0); await Promise.all( artifacts .flatMap((artifact) => artifact.artifacts) .map(async (artifactPath) => { const done = () => { - uploaded += 1; - updateUploadStatus(); + progressBar.increment(); }; const artifactName = path.basename(artifactPath); const sanitizedArtifactName = GitHub.sanitizeName(artifactName); @@ -152,6 +160,7 @@ export default class PublisherGithub extends PublisherBase