ShtukbaseStandard
包文件→ .shtukbase/packages/shtukbase-icons/checks/s01_style.ts

checks/s01_style.ts

32 行, 1.8 KB.

文件按包中的原样显示:代码及其注释不做翻译。

  1. // SBI-R01: every drawing of the Shtukbase icon set keeps the set's style (the flat form, the canvas, the palette, no
  2. // plate, no outline of its own, lines that survive at 16 px), and the rendered set in /assets/icons/set is fresh: each
  3. // file there is its drawing rendered in the held style, so the outline is the style's and nothing else.
  4. import { fmOf, iconStyle, settings } from '../../icons/lib/iconlib.ts';
  5. import { checkFlat } from '../lib/style-check.ts';
  6. import { BASE_STYLE, outDir, readText, registry, renderIcon, setStyles, styleById } from '../lib/sbicons.ts';
  7. const root = process.cwd();
  8. const fm = fmOf(root, '/norms/rules/shtukbase-icons/SBI-R01.md');
  9. const active = !Object.keys(fm).length || String(fm.status ?? 'active').trim() === 'active';
  10. const mode = String(fm.mode ?? 'enforce').trim();
  11. const out: string[] = [];
  12. if (active) {
  13. try {
  14. const reg = registry(root);
  15. const held = iconStyle(root, settings(root));
  16. const style = held && setStyles(root).some((s) => s.page === held.page) ? held : styleById(root, BASE_STYLE);
  17. const dir = outDir(root);
  18. for (const rec of reg.icons) {
  19. const svg = readText(root, rec.file);
  20. if (svg === null) continue; // ICN-R04 reports a record without its file
  21. for (const f of checkFlat(svg, style.rawPalette)) out.push(`${rec.file}: ${f}`);
  22. const built = readText(root, `${dir}/${rec.name}.svg`);
  23. if (built !== null && built !== renderIcon(root, rec, style)) out.push(`${dir}/${rec.name}.svg: not the drawing in style ${style.id} (edited by hand or stale) → run: shtuk run shtukbase-icons build`);
  24. }
  25. } catch (e) {
  26. out.push((e as Error).message);
  27. }
  28. }
  29. const soft = mode !== 'enforce';
  30. if (out.length) console.log(out.map((f) => (soft ? `(${mode}) ${f}` : f)).join('\n'));
  31. process.exitCode = active && out.length && !soft ? 1 : 0;