ShtukbaseStandard
файл пакета→ .shtukbase/packages/design-components/actions/sync.ts

actions/sync.ts

39 строк, 2.2 КБ.

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

  1. // design-components `sync`: reads every component header under /design/*/components/** and the folders listed in
  2. // `sources:` of /design/components.md, and writes one page per id to /design/components/, the data file for lenses
  3. // (lib/design/components.data.js), the resolved library CSS (lib/design/ui.css), the Custom Elements Manifest and the Storybook stories
  4. // (/design/stories/<id>.stories.js). The text under a page's header is kept. A header that does not parse stops
  5. // the run: nothing is written, the problems are printed, exit 1.
  6. // By hand: `shtuk run design-components sync [--prune]` (`--prune` also deletes pages whose component has no header).
  7. import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
  8. import { dirname, join } from 'node:path';
  9. import { plan } from '../lib/outputs.ts';
  10. import { collect } from '../lib/project.ts';
  11. const root = process.cwd();
  12. const prune = process.argv.includes('--prune');
  13. const col = collect(root);
  14. if (col.problems.length) {
  15. console.log(`design-components: nothing written — headers with errors:\n${col.problems.join('\n')}`);
  16. process.exit(1);
  17. }
  18. const p = plan(root, col);
  19. let wrote = 0;
  20. const put = (rel: string, text: string) => {
  21. const abs = join(root, rel);
  22. if (existsSync(abs) && readFileSync(abs, 'utf8') === text) return;
  23. mkdirSync(dirname(abs), { recursive: true });
  24. writeFileSync(abs, text);
  25. wrote++;
  26. };
  27. for (const page of p.pages) put(page.rel, page.text);
  28. for (const [rel, text] of p.files) put(rel, text);
  29. for (const rel of p.orphanStories) { rmSync(join(root, rel)); wrote++; }
  30. for (const n of col.notes) console.log(`note: ${n}`);
  31. for (const { library, message } of col.overrideWarnings) console.log(`warning: ${library}: ${message}`);
  32. for (const rel of p.orphanPages) {
  33. if (prune) { rmSync(join(root, rel)); wrote++; console.log(`removed: ${rel} (no header any more)`); }
  34. else console.log(`note: ${rel} has no component header any more; delete it, or run with --prune`);
  35. }
  36. const html = col.comps.filter((c) => c.html).length;
  37. const react = col.comps.filter((c) => c.react).length;
  38. console.log(`design-components: ${col.comps.length} components (${html} html, ${react} react), ${wrote} files written`);