UNPKG

@lark-project/cli

Version:

飞书项目插件开发工具

44 lines (43 loc) 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeOptionLabels = void 0; /** * 把本地配置里所有「选项」(AIPropOption 形态)的 `label` 归一到 `translation.zh`。 * * 依据 schema(developer-plugin.yaml `AIPropOption`):`label` 是展示名、**必须与 translation.zh 一致**, * `value` 才是内部值。AI/手写常把 value 误塞进 label(label=value=英文),与后端归一(正向 * `wire.label = translation.zh || label`)冲突,导致 `local-config diff` 恒报 label MODIFIED 伪差。 * 在 set 写盘前归一,既合 schema 又让往返对称、伪差从源头消失。 * * 判定一个对象是「选项」:同时带 `label`(string)与 `translation.zh`(string)——足够具体, * 不会误伤 button/point 等其它带 label 的结构(它们没有 option 的 translation)。 * `translation.zh` 为空时**保留原 label**(对齐 schema「某语言缺失退回 label」)。 * * 就地修改传入对象(调用方传的是 normalizeLocalConfigDsl 产出的新对象),返回被改动的选项条数, * 供 set 决定是否打透明提示。`value` 与 `translation` 全程不动——内部值与多语言文案无损。 */ function normalizeOptionLabels(config) { let changed = 0; const isOption = (o) => o && typeof o === 'object' && typeof o.label === 'string' && o.translation && typeof o.translation.zh === 'string'; const walk = (node) => { if (Array.isArray(node)) { node.forEach(walk); return; } if (!node || typeof node !== 'object') return; const obj = node; if (isOption(obj)) { const zh = obj.translation.zh; if (zh && obj.label !== zh) { obj.label = zh; changed += 1; } } for (const key of Object.keys(obj)) walk(obj[key]); }; walk(config); return changed; } exports.normalizeOptionLabels = normalizeOptionLabels;