805bf8e2ca
- design/prototype/serve.mjs:零依赖热重载预览服务器(照搬 jiu,check-ds 存在性守护,Phase 5 前静默跳过) - design/prototype/tokens.css:token 真源(现结构已满足 ds-flow 的 base :root + [data-theme=dark],字节迁移保证 codegen 零 diff) - design/colors_and_type.css:退化为薄 @import 别名(供历史 preview/*.html 浏览器内引用;codegen 不再读它) - 三个 codegen(Flutter gen_flutter_tokens / website+usercenter build-tokens) + drift 检查全部重指向 prototype/tokens.css - 生成产物 diff 仅头注释源路径行,token 数值零变化(已验证) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
43 lines
1.7 KiB
JavaScript
43 lines
1.7 KiB
JavaScript
#!/usr/bin/env node
|
||
/**
|
||
* build-tokens.mjs — 设计令牌同源生成器(usercenter)
|
||
*
|
||
* 唯一真相来源是仓库根的 `design/prototype/tokens.css`。
|
||
* 本脚本把它原样读入,仅删除 Google Fonts @import 行后写入
|
||
* `public/colors_and_type.css`(usercenter 通过 <link> 引入此文件)。
|
||
*
|
||
* 与 web/website/scripts/build-tokens.mjs 逻辑一致,目标路径不同。
|
||
*
|
||
* 容灾:若源文件不存在,保留已提交的 public/colors_and_type.css,构建继续。
|
||
*/
|
||
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
||
import { fileURLToPath } from 'node:url';
|
||
import { dirname, resolve } from 'node:path';
|
||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||
const SRC = resolve(__dirname, '../../../design/prototype/tokens.css');
|
||
const OUT = resolve(__dirname, '../public/colors_and_type.css');
|
||
|
||
const BANNER =
|
||
'/* AUTO-GENERATED — 勿手改。源: design/prototype/tokens.css。' +
|
||
'生成器: web/usercenter/scripts/build-tokens.mjs。仅移除第三方 Google Fonts @import。 */\n';
|
||
|
||
if (!existsSync(SRC)) {
|
||
if (existsSync(OUT)) {
|
||
console.log('[build-tokens] 源 colors_and_type.css 缺失,沿用已提交的 public/colors_and_type.css。');
|
||
process.exit(0);
|
||
}
|
||
console.error('[build-tokens] 致命:找不到源 token 文件,也没有已生成文件:', SRC);
|
||
process.exit(1);
|
||
}
|
||
|
||
const raw = readFileSync(SRC, 'utf8');
|
||
|
||
const stripped = raw
|
||
.split('\n')
|
||
.filter((line) => !/@import\s+url\(['"]?https?:\/\/fonts\.googleapis\.com/i.test(line))
|
||
.join('\n');
|
||
|
||
writeFileSync(OUT, BANNER + stripped, 'utf8');
|
||
console.log('[build-tokens] ✅ 已生成', OUT, `(${stripped.length} 字节,源自 design/prototype/tokens.css)`);
|