-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: manage packages installation by registry
- Loading branch information
1 parent
c7fa5aa
commit 8c6d6c6
Showing
12 changed files
with
392 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
import { MultiBar, type SingleBar } from "cli-progress"; | ||
import type { DownloadProgressCallback } from "../utils"; | ||
import { BYTES_PER_MEGABYTE } from "../constants"; | ||
|
||
export type RegisterProgressBarFn = (browserName: string, browserVersion: string) => DownloadProgressCallback; | ||
|
||
export const createBrowserDownloadProgressBar = (): { register: RegisterProgressBarFn } => { | ||
export const createBrowserDownloadProgressBar = (): { register: RegisterProgressBarFn; stop: () => void } => { | ||
const progressBar = new MultiBar({ | ||
stopOnComplete: true, | ||
forceRedraw: true, | ||
autopadding: true, | ||
hideCursor: true, | ||
fps: 5, | ||
format: " [{bar}] | {filename} | {value}/{total} MB", | ||
format: " [{bar}] | {filename} | {value}%", | ||
}); | ||
|
||
const register: RegisterProgressBarFn = (browserName, browserVersion) => { | ||
let bar: SingleBar; | ||
|
||
const downloadProgressCallback: DownloadProgressCallback = (downloadedBytes, totalBytes) => { | ||
const downloadProgressCallback: DownloadProgressCallback = (done, total = 100) => { | ||
if (!bar) { | ||
const totalMB = Math.round((totalBytes / BYTES_PER_MEGABYTE) * 100) / 100; | ||
bar = progressBar.create(totalMB, 0, { filename: `${browserName}@${browserVersion}` }); | ||
bar = progressBar.create(100, 0, { filename: `${browserName}@${browserVersion}` }); | ||
} | ||
|
||
const downloadedMB = Math.round((downloadedBytes / BYTES_PER_MEGABYTE) * 100) / 100; | ||
const downloadedPercents = Math.floor((done / total) * 100); | ||
|
||
bar.update(downloadedMB); | ||
bar.update(downloadedPercents); | ||
}; | ||
|
||
return downloadProgressCallback; | ||
}; | ||
|
||
return { register }; | ||
const stop = (): void => { | ||
progressBar.stop(); | ||
}; | ||
|
||
process.once("exit", stop); | ||
|
||
return { register, stop }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.