diff --git a/.changeset/heavy-hornets-fly.md b/.changeset/heavy-hornets-fly.md new file mode 100644 index 0000000..b266051 --- /dev/null +++ b/.changeset/heavy-hornets-fly.md @@ -0,0 +1,7 @@ +--- +"@icona/generator": patch +"@icona/types": patch +"@icona/utils": patch +--- + +fix: png, pdf bar no stop issue diff --git a/packages/generator/src/core/pdf.ts b/packages/generator/src/core/pdf.ts index ccfdc55..685c209 100644 --- a/packages/generator/src/core/pdf.ts +++ b/packages/generator/src/core/pdf.ts @@ -87,6 +87,7 @@ export const generatePDF = ({ SVGtoPDF(pdfDoc, svg, x, y, restSvgToPdfOptions); pdfDoc.pipe(createWriteStream(svgPath)); + pdfDoc.end(); bar.increment(); } diff --git a/packages/generator/src/core/png.ts b/packages/generator/src/core/png.ts index 7392962..2b17f9b 100644 --- a/packages/generator/src/core/png.ts +++ b/packages/generator/src/core/png.ts @@ -5,7 +5,7 @@ import { getProjectRootPath, makeFolderIfNotExistFromRoot, } from "@icona/utils"; -import { MultiBar, Presets } from "cli-progress"; +import { Presets, SingleBar } from "cli-progress"; import { writeFile } from "fs/promises"; import { join, resolve } from "path"; @@ -46,22 +46,23 @@ export const generatePNG = async ({ console.log(`\nPNG Generate in \`${path}\` folder...`); - const bar = new MultiBar( - { - format: "PNG Generate {scale} | {bar} | {percentage}% | {value}/{total}", - hideCursor: true, - }, - Presets.shades_grey, - ); + const iconaData = Object.entries(icons); + // TODO: Name transform option + for (const scale of scales) { + const iconaScaleData = iconaData.filter(([, data]) => data.png[scale]); + if (iconaScaleData.length === 0) continue; - const scale1bar = bar.create(iconData.length, 0); - const scale2bar = bar.create(iconData.length, 0); - const scale3bar = bar.create(iconData.length, 0); - const scale4bar = bar.create(iconData.length, 0); + const bar = new SingleBar( + { + format: `Drawable Generate ${scale} | {bar} | {percentage}% | {value}/{total}`, + hideCursor: true, + }, + Presets.shades_grey, + ); - // TODO: Name transform option - for (const [name, data] of iconData) { - for (const scale of scales) { + bar.start(iconaScaleData.length, 0); + + for (const [name, data] of iconaScaleData) { const base64 = data.png[scale]; if (!base64) return; @@ -69,23 +70,9 @@ export const generatePNG = async ({ const filePath = resolve(projectPath, join(path, scale, `${name}.png`)); await writeFile(filePath, buffer); - - switch (scale) { - case "1x": - scale1bar.increment({ scale }); - break; - case "2x": - scale2bar.increment({ scale }); - break; - case "3x": - scale3bar.increment({ scale }); - break; - case "4x": - scale4bar.increment({ scale }); - break; - } + bar.increment(); } - } - bar.stop(); + bar.stop(); + } };