包文件→ .shtukbase/packages/icons/checks/i04_registry.ts
checks/i04_registry.ts
25 行, 1.5 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // ICN-R04, the health of the convention icon-set (/icons/conventions/icon-set.md): an icon set and its registry agree.
- // For every /design/<set>/registry.json: every SVG in <set>/flat/ has a record and every record has its file; names are
- // kebab-case and unique, no word (name or alias) belongs to two icons, every record has a description and a use.
- // Prints one health line per set (`health icon-set/<set>: full | missing: ... | extra: ...`, the shape of /base/conventions.md)
- // and the details under it. Mode warn: it never fails; a project that sets the norm to enforce fails on `missing`.
- import { existsSync, readFileSync } from 'node:fs';
- import { join } from 'node:path';
- import { norm, settings } from '../lib/iconlib.ts';
- import { checkRegistry, healthLines, loadSets, setFiles } from '../lib/registry.ts';
- const root = process.cwd();
- const n = norm(root, 'ICN-R04', 'warn');
- const { sets, errors } = loadSets(root, settings(root).sets);
- const read = (p: string) => { const a = join(root, p.replace(/^\/+/, '')); return existsSync(a) ? readFileSync(a, 'utf8') : null; };
- let missing = errors.length;
- const lines: string[] = errors.map((e) => `health icon-set/registry: missing: ${e}`);
- if (n.active) {
- for (const set of sets) {
- const f = checkRegistry(set.registry, setFiles(root, set), read, set.path);
- missing += f.filter((x) => x.level === 'error').length;
- lines.push(...healthLines(set.id, f));
- }
- }
- if (lines.length) console.log(lines.join('\n'));
- process.exitCode = n.active && n.mode === 'enforce' && missing ? 1 : 0;