- tools/check-theme.mjs(新增,扫描 171 个文件,错误即退出码 1):
① 后台视图/业务 JS/CSS 无历史主题色残留(旧暖橙 + 生态绿,含 rgba(14,124,102,·) 衍生色,
例外放行 FcInstall 的 LEGACY_COLOR_KEYS 指纹清单)
② 登录页品牌令牌齐全,且亮绿面必须配墨绿字(白字压亮绿仅 1.77:1)
③ FcInstall::BANNERS 三条底色均为春绿 105deg 渐变
④ LEGACY_COLOR_KEYS 同时覆盖「旧暖橙 + 上一版生态绿」两族(跨版本升级不漏色)
⑤ 轮播表单占位示例与主题一致;已做注入式负向测试(注入 #0e7c66 → 报错并退出 1)
- login.html:4 处旧品牌半透明衍生色(右侧光晕/卡片描边/聚焦环/移动端按钮投影)改春绿
- docs/05:补登工具链三条命令,§7.6 增加 v1.0.6 线上实测记录(varchar(16)→255、3 条底色升级、
接口核对)与「历史色指纹必须覆盖两族」的教训
155 行
6.9 KiB
JavaScript
155 行
6.9 KiB
JavaScript
#!/usr/bin/env node
|
||
/**
|
||
* 后台主题守卫(春绿 Spring Green v4)
|
||
*
|
||
* 校验目标:
|
||
* 1) 后台视图 / 业务 JS / 业务 CSS 里不残留**历史主题色**
|
||
* —— ① 旧暖橙(#FF8A5B 一族)② v1.2 生态绿(#0e7c66 一族)③ 其半透明衍生色 rgba(14,124,102,·)
|
||
* 例外:`FcInstall.php` 的 LEGACY_COLOR_KEYS 是「故意保留的历史色指纹」,用于幂等升级,不算残留
|
||
* 2) 登录页品牌令牌齐全且亮绿只做「面」(按钮墨绿字,白字不落在亮绿上)
|
||
* 3) `FcInstall::BANNERS` 三条内置轮播底色都是春绿 105deg 渐变(亮绿→深绿)
|
||
* 4) `LEGACY_COLOR_KEYS` 同时覆盖「旧暖橙 + 上一版生态绿」两族
|
||
* —— 线上库经常落后一个主题版本,缺哪一族就会漏升级(v1.0.6 实测线上仍是 #FF8A5B)
|
||
* 5) 轮播表单的占位示例与主题一致(105deg 亮绿→深绿)
|
||
*
|
||
* 用法:node tools/check-theme.mjs
|
||
*/
|
||
import fs from 'node:fs'
|
||
import path from 'node:path'
|
||
import url from 'node:url'
|
||
|
||
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
|
||
const ROOT = path.resolve(__dirname, '..')
|
||
|
||
let errors = 0
|
||
let warns = 0
|
||
const bad = (m) => { console.log(` ❌ ${m}`); errors++ }
|
||
const warn = (m) => { console.log(` ⚠️ ${m}`); warns++ }
|
||
const ok = (m) => console.log(` ✅ ${m}`)
|
||
const read = (p) => (fs.existsSync(p) ? fs.readFileSync(p, 'utf8') : '')
|
||
|
||
/* ---------------- 1) 历史主题色残留扫描 ---------------- */
|
||
|
||
/** 历史主题色(小写;同时匹配 #RRGGBB 与 rgba() 形式) */
|
||
const RETIRED = {
|
||
'#ff8a5b': '旧暖橙 v1.0.x', '#ffb86b': '旧暖橙 v1.0.x', '#ff6f61': '旧暖橙 v1.0.x',
|
||
'#ff9a3c': '旧暖橙 v1.0.x', '#ff7a45': '旧暖橙 v1.0.x',
|
||
'#18a587': '生态绿 v1.2', '#0e7c66': '生态绿 v1.2', '#0a5d4d': '生态绿 v1.2',
|
||
'#04302a': '生态绿 v1.2', '#16897f': '生态绿 v1.2', '#0e6b62': '生态绿 v1.2',
|
||
'#07443e': '生态绿 v1.2', '#0f8f72': '生态绿 v1.2', '#0a5f4d': '生态绿 v1.2',
|
||
'rgba(14, 124, 102': '生态绿 v1.2(半透明衍生色)',
|
||
'rgba(14,124,102': '生态绿 v1.2(半透明衍生色)',
|
||
'rgba(18, 161, 132': '生态绿 v1.2(半透明衍生色)',
|
||
}
|
||
|
||
/** 仅扫描「后台自己写的」代码,第三方资源(bootstrap/fastadmin 等)不动 */
|
||
const SCAN_DIRS = [
|
||
'application/admin/view',
|
||
'application/admin/lang',
|
||
'application/admin/command',
|
||
'public/assets/js/backend/fc',
|
||
'public/assets/css/backend.css',
|
||
]
|
||
const SKIP_FILE = /FcInstall\.php$/
|
||
|
||
function walk(target) {
|
||
const abs = path.join(ROOT, target)
|
||
if (!fs.existsSync(abs)) return []
|
||
const st = fs.statSync(abs)
|
||
if (st.isFile()) return [abs]
|
||
return fs.readdirSync(abs).flatMap((f) => walk(path.join(target, f)))
|
||
}
|
||
|
||
console.log('== 1) 历史主题色残留扫描 ==')
|
||
let scanned = 0
|
||
const hits = []
|
||
for (const file of SCAN_DIRS.flatMap(walk)) {
|
||
if (!/\.(html|js|css|php|json)$/.test(file) || SKIP_FILE.test(file)) continue
|
||
const src = read(file).toLowerCase()
|
||
if (!src) continue
|
||
scanned++
|
||
for (const key of Object.keys(RETIRED)) {
|
||
const idx = src.indexOf(key)
|
||
if (idx === -1) continue
|
||
const line = read(file).slice(0, idx).split('\n').length
|
||
hits.push(`${path.relative(ROOT, file)}:${line} → ${key}(${RETIRED[key]})`)
|
||
}
|
||
}
|
||
if (hits.length) hits.forEach((h) => bad(h))
|
||
else ok(`已扫描 ${scanned} 个文件,无历史主题色残留(旧暖橙 / 生态绿)`)
|
||
|
||
/* ---------------- 2) 登录页品牌令牌 ---------------- */
|
||
|
||
console.log('== 2) 登录页品牌令牌(亮绿只做面)==')
|
||
const login = read(path.join(ROOT, 'application/admin/view/index/login.html'))
|
||
const loginChecks = [
|
||
['--brand: #04874a', '白底可读的品牌绿字/描边 #04874A'],
|
||
['--brand-bright: #00e070', '品牌亮绿 #00E070(与小程序 $fc-primary 同色号)'],
|
||
['--brand-ink: #04301e', '亮绿面上的墨绿字 #04301E'],
|
||
['linear-gradient(152deg, #023a21 0%, #046b3b 50%, #04874a 115%)', '左侧品牌栏深绿渐变(白字安全)'],
|
||
]
|
||
loginChecks.forEach(([needle, desc]) => {
|
||
if (login.includes(needle)) ok(desc)
|
||
else bad(`登录页缺少:${desc}`)
|
||
})
|
||
// 登录按钮:亮绿面必须配墨绿字
|
||
const btn = login.match(/\.login-btn[^{]*\{[^}]*\}/s)
|
||
if (btn && /var\(--brand-bright\)/.test(btn[0])) {
|
||
if (/color:\s*var\(--brand-ink\)/.test(btn[0])) ok('登录按钮 = 亮绿渐变面 + 墨绿字(对比度 8.2:1)')
|
||
else bad('登录按钮用了亮绿面却不是墨绿字(白字压亮绿仅 1.77:1,不可读)')
|
||
} else {
|
||
warn('未在登录页匹配到 .login-btn 亮绿面按钮(样式结构可能已调整)')
|
||
}
|
||
|
||
/* ---------------- 3) 内置轮播底色 ---------------- */
|
||
|
||
console.log('== 3) FcInstall 内置轮播底色 ==')
|
||
const install = read(path.join(ROOT, 'application/admin/command/FcInstall.php'))
|
||
const banners = install.match(/const BANNERS = \[([\s\S]*?)\n \];/)
|
||
if (!banners) {
|
||
bad('未找到 FcInstall::BANNERS 定义')
|
||
} else {
|
||
const rows = banners[1].split('\n').filter((l) => l.includes('linear-gradient'))
|
||
if (rows.length !== 3) bad(`内置轮播应为 3 条,实际识别到 ${rows.length} 条`)
|
||
else ok('3 条内置轮播齐备')
|
||
rows.forEach((r, i) => {
|
||
if (/linear-gradient\(105deg, #00e070|linear-gradient\(105deg, #00d96c|linear-gradient\(105deg, #00e878/.test(r)
|
||
&& /#0(0c860|0b85c|49e52|46b3b|23a21|45c34)|#046b3b|#023a21|#045c34/.test(r)) ok(`轮播 ${i + 1}:105deg 亮绿→深绿`)
|
||
else bad(`轮播 ${i + 1} 底色不是春绿 105deg 渐变:${r.trim().slice(0, 90)}`)
|
||
})
|
||
}
|
||
|
||
/* ---------------- 4) 历史色指纹覆盖度 ---------------- */
|
||
|
||
console.log('== 4) LEGACY_COLOR_KEYS 覆盖度(跨版本升级)==')
|
||
const legacy = install.match(/const LEGACY_COLOR_KEYS = \[([\s\S]*?)\n \];/)
|
||
if (!legacy) {
|
||
bad('未找到 LEGACY_COLOR_KEYS(老库升级会漏色)')
|
||
} else {
|
||
const list = legacy[1]
|
||
const groups = [
|
||
['旧暖橙族', ['ff8a5b', 'ffb86b', 'ff6f61']],
|
||
['生态绿族', ['0e7c66', '0a5d4d', '04302a', '18a587']],
|
||
]
|
||
groups.forEach(([name, keys]) => {
|
||
const missing = keys.filter((k) => !list.includes(k))
|
||
if (missing.length) bad(`${name} 指纹缺失:${missing.join(', ')}(线上停留该版本时不会被升级)`)
|
||
else ok(`${name} 指纹齐备(${keys.join(' / ')})`)
|
||
})
|
||
}
|
||
|
||
/* ---------------- 5) 轮播表单占位示例 ---------------- */
|
||
|
||
console.log('== 5) 轮播表单占位示例 ==')
|
||
for (const f of ['application/admin/view/fc/banner/add.html', 'application/admin/view/fc/banner/edit.html']) {
|
||
const src = read(path.join(ROOT, f))
|
||
const ph = src.match(/placeholder="(linear-gradient\([^"]*\))"/)
|
||
if (!ph) { warn(`${f} 未找到底色占位示例`); continue }
|
||
if (/^linear-gradient\(105deg, #00E070 /.test(ph[1])) ok(`${path.basename(f)}:${ph[1]}`)
|
||
else bad(`${path.basename(f)} 占位示例不是春绿 105deg:${ph[1]}`)
|
||
}
|
||
|
||
console.log('')
|
||
console.log(`主题守卫结束:错误 ${errors},警告 ${warns}`)
|
||
process.exit(errors ? 1 : 0)
|