#!/usr/bin/env node /** * D36: 第八轮令牌收割(仅登记 uni.scss 已有等值令牌的残留 hex) * 排除 8 位带 alpha 的 hex(如 #F9731622),避免丢失透明度 */ const fs = require('fs'); const path = require('path'); function norm(h) { const x = h.toUpperCase(); const body = x.slice(1); if (body.length === 3) return '#' + body.split('').map(c => c + c).join(''); return x; } const scss = fs.readFileSync('uni.scss', 'utf8'); const byHex = {}; for (const line of scss.split(/\r?\n/)) { const m = line.match(/^\s*(\$[\w-]+)\s*:\s*(#[0-9a-fA-F]{3,8})\s*;/); if (m) { const k = norm(m[2]); (byHex[k] = byHex[k] || []).push(m[1]); } } const RULES_FILE = 'scripts/replace-hex-to-token.js'; let ruleSrc = fs.readFileSync(RULES_FILE, 'utf8'); const ruleUpper = ruleSrc.toUpperCase(); const HEX = /#[0-9a-fA-F]{3,8}\b/g; const counts = new Map(); function walk(d) { for (const n of fs.readdirSync(d)) { if (['node_modules', 'dist', 'unpackage', '.git', 'scripts', '.tmp_equiv'].includes(n)) continue; const p = path.join(d, n); const st = fs.statSync(p); if (st.isDirectory()) walk(p); else if (n.endsWith('.vue')) { const s = fs.readFileSync(p, 'utf8'); const si = s.search(/