Skip to content

Commit

Permalink
fix: png bar no stop error (#36)
Browse files Browse the repository at this point in the history
* fix: png bar no stop error

* chore: changeset
  • Loading branch information
junghyeonsu authored Dec 7, 2023
1 parent 30520e7 commit 51a6e58
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
7 changes: 7 additions & 0 deletions .changeset/heavy-hornets-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@icona/generator": patch
"@icona/types": patch
"@icona/utils": patch
---

fix: png, pdf bar no stop issue
1 change: 1 addition & 0 deletions packages/generator/src/core/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const generatePDF = ({

SVGtoPDF(pdfDoc, svg, x, y, restSvgToPdfOptions);
pdfDoc.pipe(createWriteStream(svgPath));
pdfDoc.end();
bar.increment();
}

Expand Down
51 changes: 19 additions & 32 deletions packages/generator/src/core/png.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -46,46 +46,33 @@ 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;

const buffer = Buffer.from(base64, "base64");
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();
}
};

0 comments on commit 51a6e58

Please sign in to comment.