feat(update): use std lib to replace the custom processbar (#3027)

- The constructor of the process-bar in the currently used std/cli
differs from that of the latest version, so the relevant dependencies
have been updated.

- The custom processbar has been replaced with the std lib, and
customization has been carried out to meet the current scenario.

In test env, seem like: 

![bb2868ed3911071ce9915a9c8662786](https://github.com/user-attachments/assets/e4419965-40fc-4ad8-8647-74e30c75ea98)

close #3021

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
This commit is contained in:
zhizheng
2025-06-12 12:32:09 +02:00
committed by GitHub
co-authored by 李嘉图·M·路
parent 133d4bcfb5
commit e9cb6486c8
3 changed files with 24 additions and 25 deletions
+13 -21
View File
@@ -2,6 +2,7 @@ import * as path from "@std/path";
import * as JSONC from "@std/jsonc";
import * as tsmorph from "ts-morph";
import * as colors from "@std/fmt/colors";
import { ProgressBar } from "@std/cli/unstable-progress-bar";
export const SyntaxKind = tsmorph.ts.SyntaxKind;
@@ -17,17 +18,6 @@ export interface DenoJson {
imports?: Record<string, string>;
}
// add a progress bar function
function createProgressBar(current: number, total: number): string {
const percentage = Math.round((current / total) * 100);
const progressLength = 40;
const filled = Math.round((percentage / 100) * progressLength);
const empty = progressLength - filled;
const bar = "█".repeat(filled) + "░".repeat(empty);
return `[${bar}] ${percentage}% (${current}/${total})`;
}
async function format(filePath: string) {
const command = new Deno.Command(Deno.execPath(), {
args: ["fmt", filePath],
@@ -193,7 +183,15 @@ export async function updateProject(dir: string) {
let completedFiles = 0;
const modifiedFilesList: string[] = [];
// process files sequentially to show proper pro
// Create a progress bar
const bar = new ProgressBar({
max: sfs.length,
fmt(x) {
return `[${x.styledTime}] [${x.progressBar}] [${x.value}/${x.max} files]`;
},
});
// process files sequentially to show proper progress
await Promise.all(sfs.map(async (sourceFile) => {
try {
const wasModified = await updateFile(sourceFile);
@@ -208,18 +206,12 @@ export async function updateProject(dir: string) {
throw err;
} finally {
completedFiles++;
// update progress bar
const progress = createProgressBar(completedFiles, sfs.length);
Deno.stdout.writeSync(
new TextEncoder().encode(`\r${colors.blue(progress)} Complete!`),
);
bar.value = completedFiles;
}
}));
// add completion log
// deno-lint-ignore no-console
console.log("");
// Clear the progress line and add a newline
await bar.stop();
// add migration summary
// deno-lint-ignore no-console