iter(g156): ua tokens 支持按名过滤
传子串只列匹配令牌并在末尾标注匹配词,--json 同步过滤。 无匹配时报总数并以 1 退出,替代「全表打印后再肉眼找」。
This commit is contained in:
@@ -541,12 +541,18 @@ function cmdTokens(args) {
|
||||
console.error('未找到 packages/design/tokens/tokens.json');
|
||||
process.exit(1);
|
||||
}
|
||||
const keyword = args.find((a) => !a.startsWith('--'))?.toLowerCase(); // 带名字参数时按子串过滤,写样式时不必翻全表
|
||||
const picked = keyword ? list.filter((t) => t.cssVar.toLowerCase().includes(keyword)) : list;
|
||||
if (keyword && !picked.length) {
|
||||
console.error(`no token match: ${keyword}(共 ${list.length} 个令牌,ua tokens 看全表)`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (args.includes('--json')) {
|
||||
console.log(JSON.stringify(list, null, 2));
|
||||
console.log(JSON.stringify(picked, null, 2));
|
||||
return;
|
||||
}
|
||||
for (const t of list) console.log(`${t.cssVar.padEnd(26)} ${t.value}${t.dark && t.dark !== t.value ? ' / 暗色 ' + t.dark : ''}`);
|
||||
console.log(`共 ${list.length} 个令牌`);
|
||||
for (const t of picked) console.log(`${t.cssVar.padEnd(26)} ${t.value}${t.dark && t.dark !== t.value ? ' / 暗色 ' + t.dark : ''}`);
|
||||
console.log(`共 ${picked.length} 个令牌${keyword ? `(匹配 ${keyword})` : ''}`);
|
||||
}
|
||||
|
||||
// ---- 内置 stdio MCP server(JSON-RPC 2.0,按行分帧) ----
|
||||
|
||||
Reference in New Issue
Block a user