#!/bin/sh # 设计 token 守卫:组件里不许直接写原色、白黑透明度、十六进制或 Tailwind 调色板颜色,一律走语义 token。 # 规范见仓库根 docs/design/(design-tokens.md、interface-materials.md、ui-controls.md)。 # 在 apps/web 目录下运行;/dev/* 陈列页不在范围内。 # 确实需要例外(第三方库的颜色参数等)时,在该行或上一行写 `token-allow: 原因`。 set -eu fail=0 EXCLUDE='app/routes/dev/' report() { # $1 范围,$2 说明,$3 正则(PCRE);跳过注释行、token-allow 标记的行和它的下一行 hits=$(grep -rnP "$3" $1 --include='*.tsx' --include='*.ts' | grep -v "$EXCLUDE" | grep -vP ':\d+:\s*(\*|//|/\*|\{/\*)' || true) hits=$(printf '%s\n' "$hits" | while IFS= read -r hit; do [ -z "$hit" ] && continue file=${hit%%:*}; rest=${hit#*:}; line=${rest%%:*} prev=$((line > 1 ? line - 1 : 1)) sed -n "${prev},${line}p" "$file" | grep -q 'token-allow' || printf '%s\n' "$hit" done) if [ -n "$hits" ]; then echo "✗ $2"; echo "$hits" | head -20; fail=1 fi } # 颜色:全站 report app "原色类(bone / ink / gold)只能在 app.css 的 token 定义里出现" '(?<=-)(bone|ink|gold)-\d+\b' report app "white / black 透明度请改写成 wash / on-media-wash / scrim / canvas(透明度留在调用处)" '(?<=-)(? 默认样式(pill-primary)" 'hover:bg-(primary|foreground|brand-strong)(?![\w/-])' report app "浮层(下拉、菜单、弹窗面板)请用 pg-float,不要手写 shadow-2xl 之类的投影" '(?