34 lines
1.4 KiB
JavaScript
34 lines
1.4 KiB
JavaScript
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 + '<path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="8.5" cy="7" r="4"/><line x1="20" y1="8" x2="20" y2="14"/><line x1="23" y1="11" x2="17" y2="11"/></svg>',`
|
|
const mapPatched = mapBody.replace(/\n\}\s*$/, `,\n${userPlus}\n}`)
|
|
|
|
const file = `const s =
|
|
'<svg viewBox="0 0 24 24" fill="none" stroke="COLOR" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">'
|
|
|
|
export const SVG_MAP: Record<string, string> = ${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')
|