#!/usr/bin/env node /** * Build icons.svg — one inline SVG sprite combined from the Font Awesome Pro kit's * pre-built per-style sprites under node_modules/@awesome.me/kit-/icons/sprites/. * * Symbol ids are namespaced `dw-` (e.g. dw-house). Consumed via the dw_icon() * helper (inc/template.php) or directly: . * * Run: npm run icons (also chained into `npm run build`). * The kit is the curated icon set, so the sprite is exactly the icons we use (~40, ~40 KB) * — replacing the 689 KB Font Awesome webfont. */ import { readFileSync, writeFileSync, readdirSync, existsSync } from 'node:fs'; import { resolve } from 'node:path'; const scope = 'node_modules/@awesome.me'; let kit; try { kit = readdirSync(scope).find((d) => d.startsWith('kit-')); } catch { /* scope missing */ } if (!kit) { console.error('build-icons: no @awesome.me/kit-* installed — skipping (run `npm install` your FA kit first)'); process.exit(0); } const spritesDir = resolve(scope, kit, 'icons/sprites'); const symbols = []; const seen = new Set(); for (const file of readdirSync(spritesDir).filter((f) => f.endsWith('.svg'))) { const svg = readFileSync(resolve(spritesDir, file), 'utf8'); for (const m of svg.matchAll(//g)) { const name = m[1]; if (seen.has(name)) continue; // first style wins on a name clash seen.add(name); symbols.push(``); } } // Custom local icons (non-FA, e.g. Bootstrap Icons) live in bin/custom-icons/*.svg. // Merged here so they survive a kit rebuild; filename (minus .svg) is the icon name. const customDir = resolve('bin/custom-icons'); if (existsSync(customDir)) { for (const file of readdirSync(customDir).filter((f) => f.endsWith('.svg'))) { const name = file.replace(/\.svg$/, ''); if (seen.has(name)) continue; // kit wins on a name clash seen.add(name); const svg = readFileSync(resolve(customDir, file), 'utf8'); const viewBox = (svg.match(/viewBox="([^"]+)"/) || [, '0 0 16 16'])[1]; const inner = svg.replace(/[\s\S]*?]*>/, '').replace(/<\/svg>[\s\S]*/, '').trim(); symbols.push(`${inner}`); } } symbols.sort(); const sprite = '\n'; writeFileSync('icons.svg', sprite); console.log(`build-icons: wrote icons.svg — ${symbols.length} icons from ${kit}`);