ShtukbaseStandard
файл пакета→ .shtukbase/packages/icons/checks/i04_registry.ts

checks/i04_registry.ts

25 строк, 1.5 КБ.

Файл как есть в пакете: код и комментарии в нём не переводятся.

  1. // ICN-R04, the health of the convention icon-set (/icons/conventions/icon-set.md): an icon set and its registry agree.
  2. // For every /design/<set>/registry.json: every SVG in <set>/flat/ has a record and every record has its file; names are
  3. // kebab-case and unique, no word (name or alias) belongs to two icons, every record has a description and a use.
  4. // Prints one health line per set (`health icon-set/<set>: full | missing: ... | extra: ...`, the shape of /base/conventions.md)
  5. // and the details under it. Mode warn: it never fails; a project that sets the norm to enforce fails on `missing`.
  6. import { existsSync, readFileSync } from 'node:fs';
  7. import { join } from 'node:path';
  8. import { norm, settings } from '../lib/iconlib.ts';
  9. import { checkRegistry, healthLines, loadSets, setFiles } from '../lib/registry.ts';
  10. const root = process.cwd();
  11. const n = norm(root, 'ICN-R04', 'warn');
  12. const { sets, errors } = loadSets(root, settings(root).sets);
  13. const read = (p: string) => { const a = join(root, p.replace(/^\/+/, '')); return existsSync(a) ? readFileSync(a, 'utf8') : null; };
  14. let missing = errors.length;
  15. const lines: string[] = errors.map((e) => `health icon-set/registry: missing: ${e}`);
  16. if (n.active) {
  17. for (const set of sets) {
  18. const f = checkRegistry(set.registry, setFiles(root, set), read, set.path);
  19. missing += f.filter((x) => x.level === 'error').length;
  20. lines.push(...healthLines(set.id, f));
  21. }
  22. }
  23. if (lines.length) console.log(lines.join('\n'));
  24. process.exitCode = n.active && n.mode === 'enforce' && missing ? 1 : 0;