56 lines
2.2 KiB
JavaScript
56 lines
2.2 KiB
JavaScript
/* Tek seferlik ikon üretici: SVG'yi PNG'ye çevirip icons/ klasörüne yazar. */
|
||
// Proje klasörünü kirletmemek için kütüphaneyi geçici kurulumdan al
|
||
const { chromium } = (() => {
|
||
const yollar = [
|
||
process.env.NUMEX_PLAYWRIGHT_YOLU,
|
||
require("path").join(require("os").tmpdir(), "numex-playwright", "node_modules", "playwright")
|
||
].filter(Boolean);
|
||
for (const y of yollar) { try { return require(y); } catch (e) { /* sıradakini dene */ } }
|
||
return require("playwright");
|
||
})();
|
||
|
||
const fs = require("fs");
|
||
const path = require("path");
|
||
|
||
const svg = (boyut, maskable) => {
|
||
const dolgu = maskable ? 0.68 : 0.86;
|
||
const yaricap = maskable ? 0 : Math.round(boyut * 0.22);
|
||
const icBoyut = Math.round(boyut * dolgu);
|
||
const kaydirma = Math.round((boyut - icBoyut) / 2);
|
||
return `<svg xmlns="http://www.w3.org/2000/svg" width="${boyut}" height="${boyut}" viewBox="0 0 ${boyut} ${boyut}">
|
||
<rect width="${boyut}" height="${boyut}" rx="${yaricap}" fill="#141a2e"/>
|
||
<g transform="translate(${kaydirma} ${kaydirma}) scale(${icBoyut / 32})">
|
||
<rect x="2" y="5" width="28" height="25" rx="5" fill="none" stroke="#f3f1ec" stroke-width="2.2"/>
|
||
<path d="M2 12h28" stroke="#f3f1ec" stroke-width="2.2"/>
|
||
<path d="M10 2v6M22 2v6" stroke="#f3f1ec" stroke-width="2.2" stroke-linecap="round"/>
|
||
<circle cx="16" cy="21" r="3.4" fill="#c2703d"/>
|
||
</g>
|
||
</svg>`;
|
||
};
|
||
|
||
(async () => {
|
||
const cikti = path.join(__dirname, "icons");
|
||
fs.mkdirSync(cikti, { recursive: true });
|
||
const tarayici = await chromium.launch();
|
||
const sayfa = await tarayici.newPage();
|
||
const isler = [
|
||
{ ad: "icon-180.png", boyut: 180, maskable: false },
|
||
{ ad: "icon-192.png", boyut: 192, maskable: false },
|
||
{ ad: "icon-512.png", boyut: 512, maskable: false },
|
||
{ ad: "icon-maskable-512.png", boyut: 512, maskable: true }
|
||
];
|
||
for (const is of isler) {
|
||
await sayfa.setViewportSize({ width: is.boyut, height: is.boyut });
|
||
await sayfa.setContent(
|
||
`<html><body style="margin:0;background:transparent">${svg(is.boyut, is.maskable)}</body></html>`,
|
||
{ waitUntil: "load" }
|
||
);
|
||
await sayfa.locator("svg").screenshot({
|
||
path: path.join(cikti, is.ad),
|
||
omitBackground: true
|
||
});
|
||
console.log("yazıldı:", is.ad);
|
||
}
|
||
await tarayici.close();
|
||
})();
|