// Icon list tooling. // // npm run icons print the exhaustive list as Markdown // npm run icons -- --write refresh the list inside README.md // npm run icons -- --manifest print a theme.json "assets" skeleton (every key -> img/.svg) import { readFileSync, writeFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { assetsSkeleton, renderMarkdown } from './icon-keys.js'; import { loadContext } from './context.js'; export const README = fileURLToPath(new URL('../README.md', import.meta.url)); export const START = ''; export const END = ''; /** README text with the generated list refreshed between the markers. */ export function withIconList(readme, ctx) { const start = readme.indexOf(START); const end = readme.indexOf(END); if (start < 0 || end < start) throw new Error('README.md has no icon list markers'); return `${readme.slice(0, start + START.length)}\n\n${renderMarkdown(ctx)}\n\n${readme.slice(end)}`; } if (process.argv[1] === fileURLToPath(import.meta.url)) { const ctx = loadContext(); const args = process.argv.slice(2); if (args.includes('--write')) { writeFileSync(README, withIconList(readFileSync(README, 'utf8'), ctx)); console.log('README.md updated'); } else if (args.includes('--manifest')) { console.log(JSON.stringify({ assets: assetsSkeleton(ctx) }, null, 2)); } else { console.log(renderMarkdown(ctx)); } }