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:  close #3021 --------- Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
This commit is contained in:
+13
-21
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user