| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- // 票 15 实施辅助(只读):枚举面板域内的裸 hex 字面量与 var(..., #fallback) 形式,用于制定替换映射
- import { readFileSync, readdirSync, statSync } from 'node:fs'
- import { join, relative } from 'node:path'
- const root = 'src/modules/cockpit'
- const files = []
- ;(function walk(dir) {
- for (const e of readdirSync(dir)) {
- const p = join(dir, e)
- if (statSync(p).isDirectory()) walk(p)
- else if (/\.(vue|js)$/.test(e)) files.push(p)
- }
- })(root)
- const hexes = new Map() // literal -> Map(file -> count)
- const fallbacks = new Map() // "var(--x, literal)" -> Map(file->count)
- for (const f of files) {
- const rel = relative('.', f)
- const src = readFileSync(f, 'utf8')
- for (const m of src.matchAll(/#[0-9a-fA-F]{3,8}\b/g)) {
- const k = m[0].toLowerCase()
- const cur = hexes.get(k) || new Map()
- cur.set(rel, (cur.get(rel) || 0) + 1)
- hexes.set(k, cur)
- }
- for (const m of src.matchAll(/var\(\s*(--[\w-]+)\s*,\s*([^)]+)\)/g)) {
- const k = `${m[1]}, ${m[2].trim()}`
- const cur = fallbacks.get(k) || new Map()
- cur.set(rel, (cur.get(rel) || 0) + 1)
- fallbacks.set(k, cur)
- }
- }
- console.log('=== 裸 hex 字面量(面板域,全部文件)')
- for (const [hex, m] of [...hexes.entries()].sort((a, b) => [...b[1].values()].reduce((x, y) => x + y, 0) - [...a[1].values()].reduce((x, y) => x + y, 0))) {
- const total = [...m.values()].reduce((a, b) => a + b, 0)
- console.log(`\n${hex} 合计 ${total}`)
- for (const [f, c] of [...m.entries()].sort((a, b) => b[1] - a[1])) console.log(` ${String(c).padStart(3)} ${f}`)
- }
- console.log('\n\n=== var(--token, fallback) 形式')
- for (const [k, m] of [...fallbacks.entries()].sort()) {
- const total = [...m.values()].reduce((a, b) => a + b, 0)
- console.log(`${k} ×${total} [${[...m.keys()].map((f) => f.split('\\').pop()).join(', ')}]`)
- }
|