From 93f9c8394a65f2008c408f1fa9fd5e163100951a Mon Sep 17 00:00:00 2001 From: Richard Zampieri Date: Mon, 29 Apr 2024 13:25:54 -0700 Subject: [PATCH] fix: npm package installation progress message --- src/new/form.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/new/form.ts b/src/new/form.ts index 7860196..54c19a2 100644 --- a/src/new/form.ts +++ b/src/new/form.ts @@ -28,9 +28,21 @@ async function packageManagerInstall({ }); installProcess.stdout.on("data", (data: Buffer) => { - progressBar.increment(5, { - doing: `${data.toString().trim()}`, - }); + const output = data.toString().trim(); + + const npmProgressMatch = output.match( + /\[(\d+)\/(\d+)\] (?:npm )?([\w\s]+)\.{3}/, + ); + + if (npmProgressMatch) { + const [, current, total, task] = npmProgressMatch; + const progress = Math.round( + (parseInt(current) / parseInt(total)) * 100, + ); + progressBar.update(progress, { doing: task }); + } else { + progressBar.increment(5, { doing: output }); + } }); installProcess.on("close", (code) => { @@ -211,7 +223,7 @@ const projectForm = async (projectName: string, args: any[]): Promise => { "| {percentage}% || {doing}", hideCursor: true, }, - Presets.shades_classic, + Presets.rect, ); progressBar.start(100, 0, {