-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·38 lines (30 loc) · 1.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env node
import {optimize} from "svgo";
import {readFile as readFileAsync, writeFile as writeFileAsync} from 'node:fs/promises';
import {Buffer} from 'node:buffer';
import sharp from "sharp";
// read data and optimize SVG
const origin = await readFileAsync("src/bluesky-icon.svg", "utf8");
const svg = optimize(origin, {
path: "src/bluesky-icon.svg",
multipass: true,
});
const bluesky = {
black: svg.data, // default color variant is black
white: svg.data.replace('fill="currentColor"', 'fill="#fff"'),
blue: svg.data.replace('fill="currentColor"', 'fill="#1185fe"'),
}
// export all variants
for (const [variant, src] of Object.entries(bluesky)) {
const icon = await sharp(Buffer.from(src));
if (variant === "black") {
await writeFileAsync("dist/bluesky-icon.svg", src)
await icon.toFile("dist/bluesky-icon.png");
await icon.toFile("dist/bluesky-icon.webp");
} else {
await writeFileAsync(`dist/bluesky-icon.${variant}.svg`, src)
await icon.toFile(`dist/bluesky-icon.${variant}.png`);
await icon.toFile(`dist/bluesky-icon.${variant}.webp`);
}
}
console.log("Done!");