ShtukbaseStandard
package file→ .shtukbase/packages/shtukbase-ui-html/checks/fresh.ts

checks/fresh.ts

22 lines, 1.0 KB.

  1. // SUI-R03. /design/shtukbase-ui-html/ui.css is exactly what `build` writes from the current component CSS. A broken
  2. // component is SUI-R01's business: this check then stays quiet.
  3. import { existsSync, readFileSync } from 'node:fs';
  4. import { join } from 'node:path';
  5. import { build } from '../actions/build.ts';
  6. import { LIB_DIR } from '../lib/components.ts';
  7. export const RULE = { id: 'sui-r03', title: 'ui.css is rebuilt from the component CSS' };
  8. export function check(root = process.cwd()): string[] {
  9. const { problems, css } = build(root);
  10. if (problems.length) return [];
  11. const p = join(root, LIB_DIR, 'ui.css');
  12. if (!existsSync(p)) return [`${LIB_DIR}/ui.css: the file is missing; build it: shtuk run shtukbase-ui-html build`];
  13. return readFileSync(p, 'utf8') === css ? [] : [`${LIB_DIR}/ui.css: does not match the component CSS; rebuild: shtuk run shtukbase-ui-html build (this file is not edited by hand)`];
  14. }
  15. if (import.meta.main) {
  16. const out = check();
  17. for (const l of out) console.log(l);
  18. process.exitCode = out.length ? 1 : 0;
  19. }