/** * 把脚本里 antd 两字按钮字面量改成"插空格版" —— 见 README 必知事实 #1。 * antd 会给 type="default" 的两字按钮中间插一个空格,但 type="link" / "text" 的不插, * 所以最稳妥是同时匹配两种渲染:用「忽略空白」的正则。 */ import fs from 'node:fs' import path from 'node:path' const PAIRS = [ ['新\\s*建', '新 建'], ['刷\\s*新', '刷 新'], ['查\\s*询', '查 询'], ['重\\s*置', '重 置'], ['保\\s*存', '保 存'], ['取\\s*消', '取 消'] ] const dir = 'cases' let fixCount = 0 for (const f of fs.readdirSync(dir).filter((n) => n.endsWith('.mjs'))) { const fp = path.join(dir, f) let s = fs.readFileSync(fp, 'utf8') const orig = s for (const [pattern, _] of PAIRS) { // 把 button:has-text("新建") → button:has-text(/新\s*建/) —— 正则能兼容两种渲染 s = s.replace( new RegExp(`button:has-text\\(\\s*"(${pattern})"\\s*\\)`, 'g'), (m, p) => `button:has-text(/${p}/)` ) } if (s !== orig) { fs.writeFileSync(fp, s); fixCount++ } } console.log(`已修 ${fixCount} 个文件`)