SPB Git forge
38commits 1branches 0releases
338.7 MBsize
maindefault branch
3 h agolast push
HTML 53.9% TypeScript 44.5% JavaScript 0.6% SQL 0.5%
1.6 KB · 33 lines javascript
Raw Blame History
1// One-shot: render PNG icons from the SVG mark with sharp (run: node scripts/render-icons.mjs)2import { mkdirSync, writeFileSync } from "node:fs";3import { dirname, resolve } from "node:path";4import { fileURLToPath } from "node:url";5import { createRequire } from "node:module";67const here = dirname(fileURLToPath(import.meta.url));8const root = resolve(here, "..");9const require = createRequire(import.meta.url);10const sharp = require(process.env.SHARP_PATH ?? "sharp");1112const svg = (pad, rx, bg = "#0b0f14") => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="1024" height="1024" fill="none">13  <rect width="32" height="32" rx="${rx}" fill="${bg}"/>14  <g transform="translate(${pad} ${pad}) scale(${(32 - 2 * pad) / 32})">15    <circle cx="15" cy="16" r="10.5" stroke="#eceae5" stroke-width="2.2"/>16    <path d="M5.9 11.3h18.2M5.9 20.7h18.2" stroke="#eceae5" stroke-width="2" stroke-linecap="round"/>17    <path d="M4 16h25" stroke="#e8763a" stroke-width="2.8" stroke-linecap="round"/>18  </g>19</svg>`;2021async function out(file, size, source) {22  const buf = await sharp(Buffer.from(source)).resize(size, size).png().toBuffer();23  mkdirSync(dirname(file), { recursive: true });24  writeFileSync(file, buf);25  console.log("wrote", file, size);26}2728await out(resolve(root, "src/app/icon.png"), 512, svg(0, 6));29await out(resolve(root, "src/app/apple-icon.png"), 180, svg(0, 0));30await out(resolve(root, "public/icons/icon-192.png"), 192, svg(0, 6));31await out(resolve(root, "public/icons/icon-512.png"), 512, svg(0, 6));32await out(resolve(root, "public/icons/icon-512-maskable.png"), 512, svg(4, 0));33