package file→ .shtukbase/packages/keer-ui/tools/vendor.ts
tools/vendor.ts
111 lines, 8.2 KB.
- // Copies the reusable part of the source app packages/ui into keer-ui/library, rewriting alias imports to relative.
- // Usage: bun vendor.ts <source packages/ui/src> <keer-ui package dir>
- import { mkdirSync, readFileSync, writeFileSync, existsSync, rmSync } from 'node:fs';
- import { join, dirname, relative } from 'node:path';
- const [src, pkg] = process.argv.slice(2);
- const out = join(pkg, 'library');
- 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(' ');
- 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(' ');
- const files: string[] = ['lib/define.ts', 'lib/utils.ts', 'hooks/use-mobile.ts'];
- for (const n of PRIM) files.push(`primitives/${n}.tsx`, `primitives/${n}.states.tsx`);
- for (const n of COMP) files.push(`composites/${n}.tsx`, `composites/${n}.states.tsx`);
- // Demo data of the states files: Source-app domain words replaced by neutral ones.
- const NEUTRAL: [string, string, string][] = [
- ['primitives/toggle-group.states.tsx', '{ value: "leads", label: "Leads" }', '{ value: "tasks", label: "Tasks" }'],
- ['primitives/toggle-group.states.tsx', '{ value: "tenders", label: "Tenders" }', '{ value: "notes", label: "Notes" }'],
- ['primitives/toggle-group.states.tsx', '{ value: "seo", label: "SEO" }', '{ value: "reports", label: "Reports" }'],
- ['primitives/toggle-group.states.tsx', '{ value: "sites", label: "Sites" }', '{ value: "files", label: "Files" }'],
- ['primitives/toggle-group.states.tsx', '{ value: "clients", label: "Clients" }', '{ value: "people", label: "People" }'],
- ['primitives/toggle-group.states.tsx', 'value: "leads"', 'value: "tasks"'],
- ['primitives/toggle-group.states.tsx', 'const FUNCTIONS', 'const SECTIONS'],
- ['primitives/toggle-group.states.tsx', 'items: FUNCTIONS', 'items: SECTIONS'],
- ['primitives/toggle-group.states.tsx', 'label: "Function"', 'label: "Section"'],
- ['primitives/breadcrumb.states.tsx', 'href="#leads">Leads<', 'href="#tasks">Tasks<'],
- ['primitives/sheet.states.tsx', 'Narrow the list of leads.', 'Narrow the list of tasks.'],
- ['primitives/tabs.states.tsx', 'All purchases', 'All tasks'],
- ['primitives/tabs.states.tsx', 'My purchases', 'My tasks'],
- ['primitives/button.states.tsx', 'that have a site found', 'that have contacts found'],
- ['primitives/link.states.tsx', '#lead-42', '#company-42'],
- ['primitives/field.states.tsx', 'Collect new purchases for the day', 'Collect new requests for the day'],
- ['composites/section-header.states.tsx', 'The last five tasks for the leads.', 'The last five tasks of the project.'],
- ['composites/status-list.states.tsx', 'id: "tenders"', 'id: "reports"'],
- ['composites/status-list.states.tsx', 'Tender selection', 'Weekly report'],
- ['composites/choice-list.states.tsx', 'Purchase number', 'Contract number'],
- ['composites/choice-list.states.tsx', 'Purchase profitability estimate', 'Contract estimate'],
- ['composites/choice-list.states.tsx', 'Purchase requirements review', 'Contract requirements review'],
- ['composites/choice-list.tsx', '“Purchase number”', '“Contract number”'],
- ['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.'],
- ['composites/example-list.states.tsx', 'const LEADS', 'const EXAMPLES'],
- ['composites/example-list.states.tsx', 'items: LEADS', 'items: EXAMPLES'],
- ['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'],
- ['composites/example-list.states.tsx', 'Find 50 clients in warehouse logistics', 'Summarize the meetings of the month'],
- ['composites/example-list.states.tsx', 'Count the funnel for November by direction', 'Count the tasks for November by section'],
- ['composites/step-list.states.tsx', 'Found 73 companies with purchases on the topic in the procurement portal.', 'Found 73 companies on the topic.'],
- ['composites/step-list.states.tsx', 'Prepared a new text in the style of the site.', 'Prepared a new text in the agreed style.'],
- ['composites/step-list.states.tsx', 'Found sites and contacts', 'Found contacts'],
- ['composites/step-list.states.tsx', 'Writing the leads to the CRM', 'Writing the contacts to a table'],
- // Radii outside the scale, written through the radius token so that KS-R02 holds (same pixels).
- ['primitives/tooltip.tsx', 'rounded-[2px]', 'rounded-[calc(var(--ds-radius-xs)/2)]'],
- ['primitives/checkbox.tsx', 'rounded-[4px]', 'rounded-[var(--ds-radius-xs)]'],
- ['primitives/input-group.states.tsx', 'import { BrandMark } from "./brand-mark";\n', ''],
- ['primitives/input-group.states.tsx', '<BrandMark size="sm" />', '<SearchIcon />'],
- ['primitives/input-group.states.tsx', 'Describe which clients to find', 'Describe the task'],
- ['primitives/toggle-group.tsx', '`{ "data-function": "leads" }`', '`{ "data-section": "tasks" }`'],
- ];
- rmSync(out,{ recursive: true, force: true });
- const ext = (p: string) => (p.startsWith('lib/') || p.startsWith('hooks/') ? '.ts' : '.tsx');
- const problems: string[] = [];
- const externals = new Set<string>();
- for (const f of files) {
- const from = join(src, f);
- if (!existsSync(from)) { problems.push(`missing ${f}`); continue; }
- let text = readFileSync(from, 'utf8');
- text = text.replace(/(from\s+|import\s+)(["'])@copilot\/ui\/([a-z-]+)\/([a-z.-]+)\2/g, (_m, kw, q, dir, name) => {
- const target = `${dir}/${name}`;
- if (!files.includes(target + ext(target)) && !files.includes(target + '.tsx') && !files.includes(target + '.ts')) problems.push(`${f}: import of ${target} not in the library`);
- let rel = relative(dirname(f), target);
- if (!rel.startsWith('.')) rel = './' + rel;
- return `${kw}${q}${rel}${q}`;
- });
- for (const m of text.matchAll(/from\s+["'](\.[^"']*)["']/g)) {
- const t2 = join(dirname(f), m[1]);
- 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`);
- }
- for (const m of text.matchAll(/from\s+["']([^"'.][^"']*)["']/g)) {
- if (m[1].startsWith('@copilot')) problems.push(`${f}: still ${m[1]}`);
- else externals.add(m[1].startsWith('@') ? m[1].split('/').slice(0, 2).join('/') : m[1].split('/')[0]);
- }
- for (const [file, a, b] of NEUTRAL) if (file === f) {
- if (!text.includes(a)) problems.push(`${f}: neutral text not found: ${a}`);
- text = text.split(a).join(b);
- }
- mkdirSync(dirname(join(out, f)), { recursive: true });
- writeFileSync(join(out, f), text);
- }
- // Styles: Tailwind theme over the keer-style tokens (the tokens import is filled in by `place`).
- const st = join(src, 'styles');
- mkdirSync(join(out, 'styles'), { recursive: true });
- const head = `/*
- * keer-ui: the Tailwind theme and the map of shadcn roles over the keer-style tokens.
- * There are no values here: only references to --ds-* from design/keer-style/tokens.css.
- * The @import line of the tokens is written by the place action: the path from this folder to the tokens of the project.
- * Source: the source app, packages/ui/src/styles/globals.css (28.11.2026); the app themes (themes.css) are not taken.
- */
- @import "tailwindcss";
- @import "tw-animate-css";
- @import "shadcn/tailwind.css";
- @import "{{tokens}}";
- @import "./typography.css";
- @import "./frame.css";
- @source "../**/*.{ts,tsx}";
- `;
- const g = readFileSync(join(st, 'globals.css'), 'utf8').split('\n');
- if (!g[8].startsWith('@source')) problems.push('globals.css: line 9 is not the last @source any more');
- writeFileSync(join(out, 'styles/keer-ui.css'), head + g.slice(9).join('\n'));
- for (const n of ['typography.css', 'frame.css']) writeFileSync(join(out, 'styles', n), readFileSync(join(st, n), 'utf8'));
- console.log('files', files.length);
- console.log('externals', [...externals].sort().join(' '));
- console.log(problems.join('\n') || 'no problems');