Skip to content

Commit

Permalink
fix: npm package installation progress message
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz committed Apr 29, 2024
1 parent 94bc93d commit 93f9c83
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/new/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -211,7 +223,7 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {
"| {percentage}% || {doing}",
hideCursor: true,
},
Presets.shades_classic,
Presets.rect,
);

progressBar.start(100, 0, {
Expand Down

0 comments on commit 93f9c83

Please sign in to comment.