ShtukbaseStandard
package file→ .shtukbase/packages/keer-ui/tools/vendor.ts

tools/vendor.ts

111 lines, 8.2 KB.

  1. // Copies the reusable part of the source app packages/ui into keer-ui/library, rewriting alias imports to relative.
  2. // Usage: bun vendor.ts <source packages/ui/src> <keer-ui package dir>
  3. import { mkdirSync, readFileSync, writeFileSync, existsSync, rmSync } from 'node:fs';
  4. import { join, dirname, relative } from 'node:path';
  5. const [src, pkg] = process.argv.slice(2);
  6. const out = join(pkg, 'library');
  7. const PRIM = 'alert alert-dialog attachment avatar badge breadcrumb bubble button card checkbox collapsible dialog dropdown-menu empty field input input-group kbd label link marker message progress radio-group scroll-area select separator sheet sidebar skeleton sonner switch table tabs textarea toggle-group tooltip'.split(' ');
  8. const COMP = 'answer-card before-after-pair checklist choice-list example-list file-pick-button key-value-list list-card outcome-banner page-header page-layout section-header settings-panel sourced-value split-layout state-view status-badge status-list step-list'.split(' ');
  9. const files: string[] = ['lib/define.ts', 'lib/utils.ts', 'hooks/use-mobile.ts'];
  10. for (const n of PRIM) files.push(`primitives/${n}.tsx`, `primitives/${n}.states.tsx`);
  11. for (const n of COMP) files.push(`composites/${n}.tsx`, `composites/${n}.states.tsx`);
  12. // Demo data of the states files: Source-app domain words replaced by neutral ones.
  13. const NEUTRAL: [string, string, string][] = [
  14. ['primitives/toggle-group.states.tsx', '{ value: "leads", label: "Leads" }', '{ value: "tasks", label: "Tasks" }'],
  15. ['primitives/toggle-group.states.tsx', '{ value: "tenders", label: "Tenders" }', '{ value: "notes", label: "Notes" }'],
  16. ['primitives/toggle-group.states.tsx', '{ value: "seo", label: "SEO" }', '{ value: "reports", label: "Reports" }'],
  17. ['primitives/toggle-group.states.tsx', '{ value: "sites", label: "Sites" }', '{ value: "files", label: "Files" }'],
  18. ['primitives/toggle-group.states.tsx', '{ value: "clients", label: "Clients" }', '{ value: "people", label: "People" }'],
  19. ['primitives/toggle-group.states.tsx', 'value: "leads"', 'value: "tasks"'],
  20. ['primitives/toggle-group.states.tsx', 'const FUNCTIONS', 'const SECTIONS'],
  21. ['primitives/toggle-group.states.tsx', 'items: FUNCTIONS', 'items: SECTIONS'],
  22. ['primitives/toggle-group.states.tsx', 'label: "Function"', 'label: "Section"'],
  23. ['primitives/breadcrumb.states.tsx', 'href="#leads">Leads<', 'href="#tasks">Tasks<'],
  24. ['primitives/sheet.states.tsx', 'Narrow the list of leads.', 'Narrow the list of tasks.'],
  25. ['primitives/tabs.states.tsx', 'All purchases', 'All tasks'],
  26. ['primitives/tabs.states.tsx', 'My purchases', 'My tasks'],
  27. ['primitives/button.states.tsx', 'that have a site found', 'that have contacts found'],
  28. ['primitives/link.states.tsx', '#lead-42', '#company-42'],
  29. ['primitives/field.states.tsx', 'Collect new purchases for the day', 'Collect new requests for the day'],
  30. ['composites/section-header.states.tsx', 'The last five tasks for the leads.', 'The last five tasks of the project.'],
  31. ['composites/status-list.states.tsx', 'id: "tenders"', 'id: "reports"'],
  32. ['composites/status-list.states.tsx', 'Tender selection', 'Weekly report'],
  33. ['composites/choice-list.states.tsx', 'Purchase number', 'Contract number'],
  34. ['composites/choice-list.states.tsx', 'Purchase profitability estimate', 'Contract estimate'],
  35. ['composites/choice-list.states.tsx', 'Purchase requirements review', 'Contract requirements review'],
  36. ['composites/choice-list.tsx', '“Purchase number”', '“Contract number”'],
  37. ['composites/state-view.states.tsx', 'Connect the CRM in settings to see the deals here.', 'Connect a source in settings to see the records here.'],
  38. ['composites/example-list.states.tsx', 'const LEADS', 'const EXAMPLES'],
  39. ['composites/example-list.states.tsx', 'items: LEADS', 'items: EXAMPLES'],
  40. ['composites/example-list.states.tsx', 'Find boiler houses, heat networks and water utilities in the region with backup power of 100-500 kW', 'Collect the open questions of the project for the week'],
  41. ['composites/example-list.states.tsx', 'Find 50 clients in warehouse logistics', 'Summarize the meetings of the month'],
  42. ['composites/example-list.states.tsx', 'Count the funnel for November by direction', 'Count the tasks for November by section'],
  43. ['composites/step-list.states.tsx', 'Found 73 companies with purchases on the topic in the procurement portal.', 'Found 73 companies on the topic.'],
  44. ['composites/step-list.states.tsx', 'Prepared a new text in the style of the site.', 'Prepared a new text in the agreed style.'],
  45. ['composites/step-list.states.tsx', 'Found sites and contacts', 'Found contacts'],
  46. ['composites/step-list.states.tsx', 'Writing the leads to the CRM', 'Writing the contacts to a table'],
  47. // Radii outside the scale, written through the radius token so that KS-R02 holds (same pixels).
  48. ['primitives/tooltip.tsx', 'rounded-[2px]', 'rounded-[calc(var(--ds-radius-xs)/2)]'],
  49. ['primitives/checkbox.tsx', 'rounded-[4px]', 'rounded-[var(--ds-radius-xs)]'],
  50. ['primitives/input-group.states.tsx', 'import { BrandMark } from "./brand-mark";\n', ''],
  51. ['primitives/input-group.states.tsx', '<BrandMark size="sm" />', '<SearchIcon />'],
  52. ['primitives/input-group.states.tsx', 'Describe which clients to find', 'Describe the task'],
  53. ['primitives/toggle-group.tsx', '`{ "data-function": "leads" }`', '`{ "data-section": "tasks" }`'],
  54. ];
  55. rmSync(out,{ recursive: true, force: true });
  56. const ext = (p: string) => (p.startsWith('lib/') || p.startsWith('hooks/') ? '.ts' : '.tsx');
  57. const problems: string[] = [];
  58. const externals = new Set<string>();
  59. for (const f of files) {
  60. const from = join(src, f);
  61. if (!existsSync(from)) { problems.push(`missing ${f}`); continue; }
  62. let text = readFileSync(from, 'utf8');
  63. text = text.replace(/(from\s+|import\s+)(["'])@copilot\/ui\/([a-z-]+)\/([a-z.-]+)\2/g, (_m, kw, q, dir, name) => {
  64. const target = `${dir}/${name}`;
  65. if (!files.includes(target + ext(target)) && !files.includes(target + '.tsx') && !files.includes(target + '.ts')) problems.push(`${f}: import of ${target} not in the library`);
  66. let rel = relative(dirname(f), target);
  67. if (!rel.startsWith('.')) rel = './' + rel;
  68. return `${kw}${q}${rel}${q}`;
  69. });
  70. for (const m of text.matchAll(/from\s+["'](\.[^"']*)["']/g)) {
  71. const t2 = join(dirname(f), m[1]);
  72. if (!files.includes(t2 + '.tsx') && !files.includes(t2 + '.ts') && !NEUTRAL.some(([nf, a]) => nf === f && a.includes(m[1]))) problems.push(`${f}: relative ${m[1]} not in the library`);
  73. }
  74. for (const m of text.matchAll(/from\s+["']([^"'.][^"']*)["']/g)) {
  75. if (m[1].startsWith('@copilot')) problems.push(`${f}: still ${m[1]}`);
  76. else externals.add(m[1].startsWith('@') ? m[1].split('/').slice(0, 2).join('/') : m[1].split('/')[0]);
  77. }
  78. for (const [file, a, b] of NEUTRAL) if (file === f) {
  79. if (!text.includes(a)) problems.push(`${f}: neutral text not found: ${a}`);
  80. text = text.split(a).join(b);
  81. }
  82. mkdirSync(dirname(join(out, f)), { recursive: true });
  83. writeFileSync(join(out, f), text);
  84. }
  85. // Styles: Tailwind theme over the keer-style tokens (the tokens import is filled in by `place`).
  86. const st = join(src, 'styles');
  87. mkdirSync(join(out, 'styles'), { recursive: true });
  88. const head = `/*
  89. * keer-ui: the Tailwind theme and the map of shadcn roles over the keer-style tokens.
  90. * There are no values here: only references to --ds-* from design/keer-style/tokens.css.
  91. * The @import line of the tokens is written by the place action: the path from this folder to the tokens of the project.
  92. * Source: the source app, packages/ui/src/styles/globals.css (28.11.2026); the app themes (themes.css) are not taken.
  93. */
  94. @import "tailwindcss";
  95. @import "tw-animate-css";
  96. @import "shadcn/tailwind.css";
  97. @import "{{tokens}}";
  98. @import "./typography.css";
  99. @import "./frame.css";
  100. @source "../**/*.{ts,tsx}";
  101. `;
  102. const g = readFileSync(join(st, 'globals.css'), 'utf8').split('\n');
  103. if (!g[8].startsWith('@source')) problems.push('globals.css: line 9 is not the last @source any more');
  104. writeFileSync(join(out, 'styles/keer-ui.css'), head + g.slice(9).join('\n'));
  105. for (const n of ['typography.css', 'frame.css']) writeFileSync(join(out, 'styles', n), readFileSync(join(st, n), 'utf8'));
  106. console.log('files', files.length);
  107. console.log('externals', [...externals].sort().join(' '));
  108. console.log(problems.join('\n') || 'no problems');