PRA-only-demo/scripts/catalog-overrides.mjs
yu 8414c4f355 feat: 平台标记单一源 PLATFORM_GROUPS + catalog 重生成 platformTag 生效
迁移前置项(指南五件小事 #1 + 第 0 步作业 #2):
- register-all.ts 新增 PLATFORM_GROUPS 单一权威表(33 域全标 win32,darwin/linux 仅类型占位)
- registerAll 逐域加载时把平台默认值落进 meta.platforms(能力显式声明优先);
  新增 buildDomainPlatformMap 供构建脚本与运行时共用同一张表
- build-catalog.mjs 删除 WIN32_GROUPS 硬编码,platformTag 从包内分组表派生(改 tsx 运行)
- 守卫测试 platform-groups.test.ts:域无缺行 / 不偷填非 win32 数据 / meta 派生一致
- catalog.json 重生成:687 个组件获得 platformTag=win32(此前从未生效)
- 源数据恢复:对面重构删了 shizai-catalog-data.js,从其历史 commit 7bc627c8 恢复到
  temp/catalog-source/(不入库)并作为回退路径
- catalog-overrides 增强 addFields 支持;把此前直接改 catalog.json 的 96 处假必填修正、
  label 修正、Screenlock 字段清理、12 个实现读取但源数据缺失的字段全部沉淀进 overrides,
  重生成后参数审计 A/B 类保持 0/0
2026-11-05 17:53:07 +08:00

25 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from "node:fs";
const overrides = JSON.parse(fs.readFileSync(new URL("../resources/catalog-overrides.json", import.meta.url), "utf8"));
/** 把本项目已实现的参数契约覆盖到派生目录,避免重新生成时恢复旧的错误元数据。 */
export function applyCatalogOverrides(catalog) {
for (const component of catalog.components) {
const override = overrides[component.id];
if (!override) continue;
const { fields = {}, addFields = [], removeFields = [], ...metadata } = override;
Object.assign(component, metadata);
component.fields = component.fields.filter(field => !removeFields.includes(field.key))
.map(field => ({ ...field, ...fields[field.key] }));
// addFields:补源数据里缺失、但实现确实读取的字段(完整字段定义,key 重复则跳过)
if (addFields.length) {
const have = new Set(component.fields.map(f => f.key));
for (const f of addFields) {
if (f && f.key && !have.has(f.key)) component.fields.push(f);
}
}
}
catalog.counts.fields = catalog.components.reduce((count, component) => count + component.fields.length, 0);
return catalog;
}