import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const iconJs = fs.readFileSync( path.join(__dirname, '../../miniprogram/components/icon/icon.js'), 'utf8' ) const start = iconJs.indexOf('const svgMap = {') const end = iconJs.indexOf('\n return svgMap[name]', start) if (start < 0 || end < 0) { console.error('svgMap block not found') process.exit(1) } const mapBody = iconJs.slice(start + 'const svgMap = '.length, end).trim() const userPlus = ` 'user-plus': s + '',` const mapPatched = mapBody.replace(/\n\}\s*$/, `,\n${userPlus}\n}`) const file = `const s = '' export const SVG_MAP: Record = ${mapPatched} export function getSvgDataUrl(name: string, color: string): string { const raw = SVG_MAP[name] if (!raw) return '' const svg = raw.replace(/COLOR/g, color) return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg) } ` fs.writeFileSync(path.join(__dirname, '../src/components/Icon/svgMap.ts'), file, 'utf8') console.log('wrote svgMap.ts')