ShtukbaseStandard
包文件→ .shtukbase/packages/design-lenses/test/fixtures/override.ts

test/fixtures/override.ts

36 行, 1.4 KB.

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

  1. // The partial package used by the installed-project test and the catalog proof.
  2. import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
  3. import { dirname, join } from 'node:path';
  4. export const BASE = 'shtukbase-ui-html';
  5. export const OVERRIDE = 'my-ui';
  6. export const IDS = ['button', 'badge'] as const;
  7. export const packages = join(import.meta.dir, '../../..');
  8. export function writeOverride(dest: string) {
  9. const put = (rel: string, content: string) => {
  10. const path = join(dest, rel);
  11. mkdirSync(dirname(path), { recursive: true });
  12. writeFileSync(path, content);
  13. };
  14. put('package.md', `---
  15. type: Package
  16. id: my-ui
  17. version: 0.1.0
  18. title: Project UI
  19. requires: {design-components: ^0.1.5, design-tokens: ^0.2.0}
  20. follows: [design/conventions/component-library]
  21. ---
  22. `);
  23. put('pages/design/my-ui.md', '---\ntype: Page\ntitle: Project UI\n---\n');
  24. for (const id of IDS) {
  25. const from = join(packages, BASE, 'pages/design', BASE, 'components/primitive', id, id);
  26. const to = `pages/design/${OVERRIDE}/components/primitive/${id}/${id}`;
  27. put(to + '.css', readFileSync(from + '.css', 'utf8').replaceAll('var(--primary)', 'var(--foreground)')
  28. .replaceAll('var(--primary-foreground)', 'var(--background)') + `
  29. /* Project UI ${id} */
  30. .${id}[data-slot="${id}"] { border-radius: 999px; }
  31. `);
  32. copyFileSync(from + '.html', join(dest, to + '.html'));
  33. }
  34. }