// Rewrite `mdi:NAME` -> `lucide:MAPPED` across frontend src + CMS content. // KEEP_MDI names are left untouched (brand/language logos with no lucide pendant). import { MAP, KEEP_MDI } from './icon-map.mjs'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const WEB_ROOT = path.resolve(ROOT, '..'); const TARGETS = [ { dir: path.join(ROOT, 'src'), exts: /\.(svelte|ts|tsx|js|mjs)$/ }, { dir: path.join(WEB_ROOT, 'cms_content', 'windwiderstand'), exts: /\.json5$/ }, ]; const SKIP_DIR = /(node_modules|\.history|\.search|_legacy|\.svelte-kit)/; const stats = { files: 0, repl: 0, kept: {} }; function walk(dir, exts, acc) { for (const e of fs.readdirSync(dir, { withFileTypes: true })) { if (e.name.startsWith('.') && e.name !== '.') continue; const full = path.join(dir, e.name); if (SKIP_DIR.test(full)) continue; if (e.isDirectory()) walk(full, exts, acc); else if (exts.test(e.name)) acc.push(full); } return acc; } const RE = /mdi:([a-z0-9-]+)/g; for (const { dir, exts } of TARGETS) { if (!fs.existsSync(dir)) continue; for (const file of walk(dir, exts, [])) { const src = fs.readFileSync(file, 'utf8'); let n = 0; const out = src.replace(RE, (m, name) => { if (KEEP_MDI.has(name)) { stats.kept[name] = (stats.kept[name] || 0) + 1; return m; } const l = MAP[name]; if (!l) return m; // unknown -> leave, validator should have caught n++; return `lucide:${l}`; }); if (n > 0) { fs.writeFileSync(file, out); stats.files++; stats.repl += n; } } } console.log(`rewrote ${stats.repl} refs in ${stats.files} files`); console.log('kept on mdi:', JSON.stringify(stats.kept));