#!/usr/bin/env bun // Vendors the site's icons from lucide (lucide-static, ISC licence) into site/img/icons/: the official SVG files, // copied byte for byte, plus lucide's licence. The pages show them as CSS masks (site/style.css .ic-*), so they take // the text colour in both themes and the site makes no request outside its own folder. // bun tools/site-icons.ts copy (after a lucide-static bump or a new icon in ICONS) // bun tools/site-icons.ts --check fail when a vendored file differs from lucide-static (CI, when installed) import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; export const SITE_ICONS = ['chevron-right', 'play', 'user-round', 'layout-grid', 'briefcase-business'] as const; const root = new URL('..', import.meta.url).pathname; const from = join(root, 'node_modules/lucide-static'); export const ICON_DIR = join(root, 'site/img/icons'); /** Problems of the vendored folder against lucide-static ([] when it matches, or when lucide-static is not installed). */ export function checkSiteIcons(): string[] { if (!existsSync(from)) return []; const out: string[] = []; for (const n of SITE_ICONS) { const f = join(ICON_DIR, `${n}.svg`); if (!existsSync(f)) out.push(`site/img/icons/${n}.svg missing (bun tools/site-icons.ts)`); else if (readFileSync(f, 'utf8') !== readFileSync(join(from, 'icons', `${n}.svg`), 'utf8')) out.push(`site/img/icons/${n}.svg is not lucide-static's file`); } for (const f of readdirSync(ICON_DIR)) if (f.endsWith('.svg') && !(SITE_ICONS as readonly string[]).includes(f.slice(0, -4))) out.push(`site/img/icons/${f} is not in SITE_ICONS`); return out; } if (import.meta.main) { if (!existsSync(from)) { console.error('site-icons: lucide-static is not installed (bun install)'); process.exit(1); } if (process.argv.includes('--check')) { const bad = checkSiteIcons(); for (const b of bad) console.error(`site-icons: ${b}`); process.exit(bad.length ? 1 : 0); } mkdirSync(ICON_DIR, { recursive: true }); const version = JSON.parse(readFileSync(join(from, 'package.json'), 'utf8')).version; for (const n of SITE_ICONS) writeFileSync(join(ICON_DIR, `${n}.svg`), readFileSync(join(from, 'icons', `${n}.svg`))); writeFileSync(join(ICON_DIR, 'LICENSE.txt'), `Icons in this folder: Lucide ${version} (https://lucide.dev), copied unchanged from the lucide-static\npackage by tools/site-icons.ts.\n\n${readFileSync(join(from, 'LICENSE'), 'utf8')}`); console.log(`site-icons: ${SITE_ICONS.length} icons from lucide-static ${version} -> site/img/icons/`); }