ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/shtukbase-ui-html/actions/build.ts

actions/build.ts

34 líneas, 1.9 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // shtukbase-ui-html `build`: joins the component CSS into /design/shtukbase-ui-html/ui.css and writes demo.html next to it.
  2. // Runs by itself after install and update; by hand: `shtuk run shtukbase-ui-html build`. The working directory is the
  3. // project root (`--root <dir>` for another one; in the repository after a CSS edit: `bun actions/build.ts --root pages
  4. // --css-only`, which refreshes the shipped ui.css). A component that breaks the format
  5. // (SUI-R01) is named and nothing is written: exit 1.
  6. import { mkdirSync, writeFileSync } from 'node:fs';
  7. import { join } from 'node:path';
  8. import { uiCss } from '../lib/build.ts';
  9. import { LIB_DIR, scan } from '../lib/components.ts';
  10. import { demoPage } from '../lib/demo.ts';
  11. export function build(root: string): { problems: string[]; css: string; demo: string } {
  12. const comps = scan(root);
  13. const problems = comps.flatMap((c) => c.problems.map((p) => `${c.html}: ${p}`));
  14. if (!comps.length) problems.push(`${LIB_DIR}/components: no components found`);
  15. if (problems.length) return { problems, css: '', demo: '' };
  16. return { problems, css: uiCss(root, comps), demo: demoPage(comps) };
  17. }
  18. if (import.meta.main) {
  19. const at = process.argv.indexOf('--root');
  20. const root = at > 0 ? process.argv[at + 1] : process.cwd();
  21. const { problems, css, demo } = build(root);
  22. if (problems.length) {
  23. console.log(`shtukbase-ui-html: not built, components break the format:\n${problems.join('\n')}`);
  24. process.exitCode = 1;
  25. } else {
  26. mkdirSync(join(root, LIB_DIR), { recursive: true });
  27. writeFileSync(join(root, LIB_DIR, 'ui.css'), css);
  28. // --css-only: the package's own pages/ ship ui.css prebuilt (design-components sync runs before this build on install)
  29. if (!process.argv.includes('--css-only')) writeFileSync(join(root, LIB_DIR, 'demo.html'), demo);
  30. console.log(`shtukbase-ui-html: ${LIB_DIR}/ui.css (${css.length} bytes) and ${LIB_DIR}/demo.html`);
  31. }
  32. }