@collectui/cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/report.mjs ADDED
@@ -0,0 +1,222 @@
1
+ import * as p from "@clack/prompts";
2
+
3
+ /**
4
+ * 透明输出层:
5
+ * - TTY / 人类模式:@clack/prompts(p CLI 同款)的 intro/log/step/note/outro
6
+ * - 无头 / Agent 模式(--json 或非 TTY):逐行 JSON event,stdout 只出机器可读内容
7
+ *
8
+ * 所有输出都过 redact():PAT、CLI key、MCP key 永远不会出现在日志里。
9
+ */
10
+ export function createReporter({
11
+ json = false,
12
+ yes = false,
13
+ dryRun = false,
14
+ secrets = [],
15
+ verbose = false,
16
+ forceHeadless = false,
17
+ } = {}) {
18
+ let secretList = [...secrets].filter((s) => typeof s === "string" && s.length >= 4);
19
+ const headless = json || forceHeadless || !process.stdout.isTTY;
20
+
21
+ function redact(value) {
22
+ let out = typeof value === "string" ? value : String(value ?? "");
23
+ for (const secret of secretList) {
24
+ if (!secret) continue;
25
+ out = out.split(secret).join("[redacted]");
26
+ }
27
+ // 兜底:任何 Bearer 值 + 常见 key 形态
28
+ out = out.replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1[redacted]");
29
+ out = out.replace(/\b(dpat_|collectui_)[A-Za-z0-9_-]{6,}\b/g, "$1[redacted]");
30
+ return out;
31
+ }
32
+
33
+ function addSecrets(values) {
34
+ for (const v of values) {
35
+ if (typeof v === "string" && v.length >= 4 && !secretList.includes(v)) secretList.push(v);
36
+ }
37
+ }
38
+
39
+ function emit(obj) {
40
+ process.stdout.write(`${JSON.stringify(obj)}\n`);
41
+ }
42
+
43
+ function raw(msg, level = "info") {
44
+ if (json) return;
45
+ const text = redact(msg);
46
+ if (level === "error") p.log.error(text);
47
+ else if (level === "warn") p.log.warn(text);
48
+ else if (level === "success") p.log.success(text);
49
+ else p.log.info(text);
50
+ }
51
+
52
+ const reporter = {
53
+ json,
54
+ yes,
55
+ dryRun,
56
+ headless,
57
+ verbose,
58
+ addSecrets,
59
+ redact,
60
+ headlessMode: headless,
61
+
62
+ intro(title) {
63
+ if (json) emit({ event: "intro", title: redact(title) });
64
+ else p.intro(redact(title));
65
+ },
66
+
67
+ outro(title) {
68
+ if (json) emit({ event: "outro", title: redact(title) });
69
+ else p.outro(redact(title));
70
+ },
71
+
72
+ info(msg) {
73
+ if (json) emit({ event: "info", message: redact(msg) });
74
+ else raw(msg);
75
+ },
76
+
77
+ warn(msg) {
78
+ if (json) emit({ event: "warn", message: redact(msg) });
79
+ else raw(msg, "warn");
80
+ },
81
+
82
+ error(msg) {
83
+ if (json) emit({ event: "error", message: redact(msg) });
84
+ else raw(msg, "error");
85
+ },
86
+
87
+ success(msg) {
88
+ if (json) emit({ event: "success", message: redact(msg) });
89
+ else raw(msg, "success");
90
+ },
91
+
92
+ step(index, total, title) {
93
+ if (json) emit({ event: "step", index, total, title: redact(title) });
94
+ else if (typeof p.log.step === "function") p.log.step(redact(`[${index}/${total}] ${title}`));
95
+ else p.log.info(redact(`[${index}/${total}] ${title}`));
96
+ },
97
+
98
+ note(title, body) {
99
+ if (json) emit({ event: "note", title: redact(title), body: redact(body) });
100
+ else p.note(redact(body), redact(title));
101
+ },
102
+
103
+ http(payload) {
104
+ if (json) emit({ event: "http", ...payload, url: redact(payload.url) });
105
+ else if (verbose && payload.phase === "request") {
106
+ p.log.info(redact(` → ${payload.method} ${payload.url}${payload.attempt > 1 ? ` (retry ${payload.attempt})` : ""}`));
107
+ } else if (verbose && payload.phase === "response") {
108
+ p.log.info(redact(` ← ${payload.status} ${payload.url} (${payload.ms}ms)`));
109
+ }
110
+ },
111
+
112
+ /** 文件/命令动作。applied=false 表示 dry-run 预览。 */
113
+ action({ kind, path, summary, status = "planned", changes = [], command }) {
114
+ const payload = {
115
+ event: "action",
116
+ kind,
117
+ path: path ? redact(path) : undefined,
118
+ summary: summary ? redact(summary) : undefined,
119
+ status,
120
+ changes: changes.length ? changes.map(redact) : undefined,
121
+ command: command ? redact(command) : undefined,
122
+ };
123
+ if (json) {
124
+ emit(payload);
125
+ return;
126
+ }
127
+ const icon =
128
+ status === "created" ? "+" : status === "updated" ? "~" : status === "unchanged" ? "=" : "·";
129
+ const line = `${icon} ${summary ?? kind}${path ? ` ${path}` : ""}`;
130
+ if (dryRun || status === "planned") p.log.info(redact(line));
131
+ else p.log.success(redact(line));
132
+ if (!json && changes.length && verbose) {
133
+ for (const c of changes) p.log.info(redact(` · ${c}`));
134
+ }
135
+ },
136
+
137
+ preview(label, text) {
138
+ const body = redact(text);
139
+ if (json) emit({ event: "preview", label: redact(label), text: body });
140
+ else if (verbose || dryRun) p.note(body, redact(label));
141
+ },
142
+
143
+ result(data) {
144
+ if (json) emit({ event: "result", ...sanitize(data, redact) });
145
+ else {
146
+ const lines = flattenResult(data).map(redact);
147
+ if (lines.length) p.note(lines.join("\n"), "Result");
148
+ }
149
+ },
150
+
151
+ async confirm(message, { defaultValue = true } = {}) {
152
+ if (yes || headless) return true;
153
+ const answer = await p.confirm({ message: redact(message), initialValue: defaultValue });
154
+ if (p.isCancel(answer)) {
155
+ p.cancel("Cancelled.");
156
+ process.exit(0);
157
+ }
158
+ return Boolean(answer);
159
+ },
160
+
161
+ async select(message, options) {
162
+ if (headless) {
163
+ throw new Error(`Interactive selection required: ${message}. Pass flags instead.`);
164
+ }
165
+ const answer = await p.select({ message: redact(message), options });
166
+ if (p.isCancel(answer)) {
167
+ p.cancel("Cancelled.");
168
+ process.exit(0);
169
+ }
170
+ return answer;
171
+ },
172
+ };
173
+
174
+ return reporter;
175
+ }
176
+
177
+ function sanitize(value, redact) {
178
+ if (typeof value === "string") return redact(value);
179
+ if (Array.isArray(value)) return value.map((v) => sanitize(v, redact));
180
+ if (value && typeof value === "object") {
181
+ const out = {};
182
+ for (const [k, v] of Object.entries(value)) out[k] = sanitize(v, redact);
183
+ return out;
184
+ }
185
+ return value;
186
+ }
187
+
188
+ function flattenResult(data, prefix = "") {
189
+ const lines = [];
190
+ for (const [key, value] of Object.entries(data ?? {})) {
191
+ const label = prefix ? `${prefix}.${key}` : key;
192
+ if (value === null || value === undefined) continue;
193
+ if (Array.isArray(value)) {
194
+ if (value.length === 0) continue;
195
+ if (value.every((v) => typeof v !== "object")) {
196
+ lines.push(`- ${label}: ${value.join(", ")}`);
197
+ } else {
198
+ for (const [i, item] of value.entries()) {
199
+ lines.push(...flattenResult(item, `${label}[${i}]`));
200
+ }
201
+ }
202
+ } else if (typeof value === "object") {
203
+ lines.push(...flattenResult(value, label));
204
+ } else {
205
+ lines.push(`- ${label}: ${value}`);
206
+ }
207
+ }
208
+ return lines;
209
+ }
210
+
211
+ export function formatTable(rows, columns) {
212
+ if (rows.length === 0) return "";
213
+ const widths = columns.map((c) =>
214
+ Math.max(c.header.length, ...rows.map((r) => String(r[c.key] ?? "").length))
215
+ );
216
+ const line = (cells) =>
217
+ cells.map((cell, i) => String(cell ?? "").padEnd(widths[i])).join(" ").trimEnd();
218
+ const out = [line(columns.map((c) => c.header))];
219
+ out.push(widths.map((w) => "─".repeat(w)).join(" "));
220
+ for (const row of rows) out.push(line(columns.map((c) => row[c.key] ?? "")));
221
+ return out.join("\n");
222
+ }
@@ -0,0 +1,459 @@
1
+ import { join } from "node:path";
2
+ import { resolveLibKeys } from "./catalog.mjs";
3
+
4
+ /** 最小 Vite + React + TS + Tailwind v4 + shadcn 兼容脚手架(无网络也能先落盘)。 */
5
+ export function planScaffold(cs, { target, name, template = "vite", pm = "npm", install = false }) {
6
+ if (template === "none") return;
7
+
8
+ cs.mkdir(target);
9
+ const put = (path, content, options) => {
10
+ if (cs.exists(path)) return; // 已有项目里只补缺,不覆盖
11
+ cs.write(path, content, options);
12
+ };
13
+ const pkg = {
14
+ name: safeName(name),
15
+ private: true,
16
+ version: "0.0.0",
17
+ type: "module",
18
+ scripts: {
19
+ dev: "vite",
20
+ build: "vite build",
21
+ preview: "vite preview",
22
+ },
23
+ dependencies: {
24
+ "class-variance-authority": "^0.7.1",
25
+ clsx: "^2.1.1",
26
+ "lucide-react": "^0.468.0",
27
+ react: "^19.0.0",
28
+ "react-dom": "^19.0.0",
29
+ "tailwind-merge": "^3.0.0",
30
+ },
31
+ devDependencies: {
32
+ "@tailwindcss/vite": "^4.0.0",
33
+ "@types/react": "^19.0.0",
34
+ "@types/react-dom": "^19.0.0",
35
+ "@vitejs/plugin-react": "^4.3.4",
36
+ tailwindcss: "^4.0.0",
37
+ typescript: "~5.7.2",
38
+ vite: "^6.0.0",
39
+ },
40
+ };
41
+
42
+ put(join(target, "package.json"), `${JSON.stringify(pkg, null, 2)}\n`, {
43
+ summary: "create package.json (Vite + React + Tailwind v4)",
44
+ });
45
+ put(join(target, "vite.config.ts"), VITE_CONFIG, { summary: "create vite.config.ts" });
46
+ put(join(target, "tsconfig.json"), TSCONFIG, { summary: "create tsconfig.json" });
47
+ put(join(target, "tsconfig.node.json"), TSCONFIG_NODE, { summary: "create tsconfig.node.json" });
48
+ put(join(target, "index.html"), INDEX_HTML(name), { summary: "create index.html" });
49
+ put(join(target, "src/main.tsx"), MAIN_TSX, { summary: "create src/main.tsx" });
50
+ put(join(target, "src/App.tsx"), APP_TSX, { summary: "create src/App.tsx" });
51
+ put(join(target, "src/index.css"), INDEX_CSS, { summary: "create src/index.css (Tailwind v4 + shadcn tokens)" });
52
+ put(join(target, "src/vite-env.d.ts"), '/// <reference types="vite/client" />\n', {
53
+ summary: "create src/vite-env.d.ts",
54
+ });
55
+ put(join(target, "src/lib/utils.ts"), UTILS_TS, { summary: "create src/lib/utils.ts" });
56
+ put(join(target, "src/components/ui/button.tsx"), BUTTON_TSX, {
57
+ summary: "create src/components/ui/button.tsx (starter component)",
58
+ });
59
+ put(join(target, "components.json"), COMPONENTS_JSON, { summary: "create components.json (shadcn)" });
60
+ put(join(target, ".gitignore"), GITIGNORE, { summary: "create .gitignore" });
61
+ put(join(target, "README.md"), README(name), { summary: "create README.md" });
62
+
63
+ if (install) {
64
+ const args = pm === "yarn" ? [] : ["install"];
65
+ cs.run(pm, args, { cwd: target, summary: `install dependencies with ${pm}` });
66
+ }
67
+ cs.gitInit(target);
68
+ }
69
+
70
+ export function planManifest(cs, {
71
+ target,
72
+ units,
73
+ me,
74
+ registryBase,
75
+ dashBase,
76
+ clients,
77
+ mcpEntries,
78
+ cliVersion,
79
+ }) {
80
+ const libraries = units.map((unit) => {
81
+ const keys = resolveLibKeys(unit, me);
82
+ return {
83
+ site: unit.site,
84
+ name: unit.siteName,
85
+ source: unit.source ?? null,
86
+ registries: (unit.registries ?? []).map((r) => r.scope),
87
+ cliKeyBound: Boolean(keys.cli),
88
+ mcpKeyBound: Boolean(keys.mcp),
89
+ mcpServer: unit.mcp ?? null,
90
+ };
91
+ });
92
+
93
+ const manifestPath = join(target, ".collectui/project.json");
94
+ const existing = cs.exists(manifestPath) ? cs.readJson(manifestPath, null) : null;
95
+ const keyOf = (l) => l.site;
96
+ const libraryMap = new Map(
97
+ (existing?.libraries ?? []).map((lib) => [keyOf(lib), lib])
98
+ );
99
+ for (const lib of libraries) libraryMap.set(keyOf(lib), lib);
100
+ const manifest = {
101
+ cli: "collectui",
102
+ version: cliVersion,
103
+ generatedAt: existing?.generatedAt ?? new Date().toISOString(),
104
+ dash: dashBase,
105
+ registry: registryBase,
106
+ libraries: [...libraryMap.values()],
107
+ mcpClients: [...new Set([...(existing?.mcpClients ?? []), ...clients])],
108
+ mcpServers: [
109
+ ...new Set([...(existing?.mcpServers ?? []), ...(mcpEntries ?? []).map((e) => e.serverName)]),
110
+ ],
111
+ };
112
+
113
+ cs.mkdir(join(target, ".collectui"));
114
+ if (JSON.stringify(existing) !== JSON.stringify(manifest)) {
115
+ cs.write(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, {
116
+ summary: "write .collectui/project.json (machine-readable setup record)",
117
+ });
118
+ }
119
+ const envDoc = environmentDoc(manifest);
120
+ const envDocPath = join(target, ".collectui/environment.md");
121
+ if (cs.read(envDocPath) !== envDoc) {
122
+ cs.write(envDocPath, envDoc, {
123
+ summary: "write .collectui/environment.md (agent-readable setup)",
124
+ });
125
+ }
126
+ }
127
+
128
+ function environmentDoc(manifest) {
129
+ const libs = manifest.libraries
130
+ .map(
131
+ (l) =>
132
+ `- ${l.name} (\`${l.site}\`)\n` +
133
+ ` - registries: ${l.registries.length ? l.registries.map((s) => `\`${s}\``).join(", ") : "—"}\n` +
134
+ ` - CLI key: ${l.cliKeyBound ? "bound" : "missing"}; MCP key: ${l.mcpKeyBound ? "bound" : "missing"}\n` +
135
+ ` - MCP server: ${l.mcpServer ?? "—"}`
136
+ )
137
+ .join("\n");
138
+ return `# CollectUI environment
139
+
140
+ Generated by \`collectui\` ${manifest.version} on ${manifest.generatedAt}.
141
+
142
+ ## Libraries configured
143
+
144
+ ${libs || "- (none)"}
145
+
146
+ ## MCP clients
147
+
148
+ ${manifest.mcpClients.map((c) => `- ${c}`).join("\n") || "- (none)"}
149
+
150
+ ## Commands
151
+
152
+ - Configure another library: \`collectui configure . --libs <site>\`
153
+ - Install a component: \`collectui add <site> <component>\`
154
+ - Re-check setup: \`collectui doctor\`
155
+ - Dash account: \`collectui whoami\`
156
+
157
+ Secrets live in \`.env.local\` and the MCP config files (both are gitignored by
158
+ the scaffold). Never commit them.
159
+ `;
160
+ }
161
+
162
+ function safeName(name) {
163
+ return String(name || "collectui-app")
164
+ .toLowerCase()
165
+ .replace(/[^a-z0-9._-]+/g, "-")
166
+ .replace(/^-+|-+$/g, "") || "collectui-app";
167
+ }
168
+
169
+ const VITE_CONFIG = `import { fileURLToPath, URL } from "node:url";
170
+ import tailwindcss from "@tailwindcss/vite";
171
+ import react from "@vitejs/plugin-react";
172
+ import { defineConfig } from "vite";
173
+
174
+ export default defineConfig({
175
+ plugins: [react(), tailwindcss()],
176
+ resolve: {
177
+ alias: {
178
+ "@": fileURLToPath(new URL("./src", import.meta.url)),
179
+ },
180
+ },
181
+ });
182
+ `;
183
+
184
+ const TSCONFIG = `{
185
+ "compilerOptions": {
186
+ "target": "ES2022",
187
+ "useDefineForClassFields": true,
188
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
189
+ "module": "ESNext",
190
+ "skipLibCheck": true,
191
+ "moduleResolution": "bundler",
192
+ "allowImportingTsExtensions": true,
193
+ "resolveJsonModule": true,
194
+ "isolatedModules": true,
195
+ "noEmit": true,
196
+ "jsx": "react-jsx",
197
+ "strict": true,
198
+ "baseUrl": ".",
199
+ "paths": {
200
+ "@/*": ["./src/*"]
201
+ }
202
+ },
203
+ "include": ["src"],
204
+ "references": [{ "path": "./tsconfig.node.json" }]
205
+ }
206
+ `;
207
+
208
+ const TSCONFIG_NODE = `{
209
+ "compilerOptions": {
210
+ "composite": true,
211
+ "skipLibCheck": true,
212
+ "module": "ESNext",
213
+ "moduleResolution": "bundler",
214
+ "allowSyntheticDefaultImports": true
215
+ },
216
+ "include": ["vite.config.ts"]
217
+ }
218
+ `;
219
+
220
+ const INDEX_HTML = (name) => `<!doctype html>
221
+ <html lang="en">
222
+ <head>
223
+ <meta charset="UTF-8" />
224
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
225
+ <title>${escapeHtml(name)}</title>
226
+ </head>
227
+ <body>
228
+ <div id="root"></div>
229
+ <script type="module" src="/src/main.tsx"></script>
230
+ </body>
231
+ </html>
232
+ `;
233
+
234
+ const MAIN_TSX = `import { StrictMode } from "react";
235
+ import { createRoot } from "react-dom/client";
236
+ import App from "./App";
237
+ import "./index.css";
238
+
239
+ createRoot(document.getElementById("root")!).render(
240
+ <StrictMode>
241
+ <App />
242
+ </StrictMode>
243
+ );
244
+ `;
245
+
246
+ const APP_TSX = `import { Button } from "@/components/ui/button";
247
+
248
+ export default function App() {
249
+ return (
250
+ <main className="flex min-h-screen flex-col items-center justify-center gap-4 bg-background text-foreground">
251
+ <h1 className="font-semibold text-2xl">CollectUI project</h1>
252
+ <p className="text-muted-foreground text-sm">
253
+ Run <code className="font-mono">collectui add &lt;site&gt; &lt;component&gt;</code> to install components.
254
+ </p>
255
+ <Button>Ready</Button>
256
+ </main>
257
+ );
258
+ }
259
+ `;
260
+
261
+ const INDEX_CSS = `@import "tailwindcss";
262
+
263
+ @custom-variant dark (&:is(.dark *));
264
+
265
+ :root {
266
+ --background: oklch(1 0 0);
267
+ --foreground: oklch(0.145 0 0);
268
+ --card: oklch(1 0 0);
269
+ --card-foreground: oklch(0.145 0 0);
270
+ --popover: oklch(1 0 0);
271
+ --popover-foreground: oklch(0.145 0 0);
272
+ --primary: oklch(0.205 0 0);
273
+ --primary-foreground: oklch(0.985 0 0);
274
+ --secondary: oklch(0.97 0 0);
275
+ --secondary-foreground: oklch(0.205 0 0);
276
+ --muted: oklch(0.97 0 0);
277
+ --muted-foreground: oklch(0.556 0 0);
278
+ --accent: oklch(0.97 0 0);
279
+ --accent-foreground: oklch(0.205 0 0);
280
+ --destructive: oklch(0.577 0.245 27.325);
281
+ --destructive-foreground: oklch(0.985 0 0);
282
+ --border: oklch(0.922 0 0);
283
+ --input: oklch(0.922 0 0);
284
+ --ring: oklch(0.708 0 0);
285
+ --radius: 0.625rem;
286
+ }
287
+
288
+ .dark {
289
+ --background: oklch(0.145 0 0);
290
+ --foreground: oklch(0.985 0 0);
291
+ --card: oklch(0.205 0 0);
292
+ --card-foreground: oklch(0.985 0 0);
293
+ --popover: oklch(0.205 0 0);
294
+ --popover-foreground: oklch(0.985 0 0);
295
+ --primary: oklch(0.922 0 0);
296
+ --primary-foreground: oklch(0.205 0 0);
297
+ --secondary: oklch(0.269 0 0);
298
+ --secondary-foreground: oklch(0.985 0 0);
299
+ --muted: oklch(0.269 0 0);
300
+ --muted-foreground: oklch(0.708 0 0);
301
+ --accent: oklch(0.269 0 0);
302
+ --accent-foreground: oklch(0.985 0 0);
303
+ --destructive: oklch(0.704 0.191 22.216);
304
+ --destructive-foreground: oklch(0.985 0 0);
305
+ --border: oklch(1 0 0 / 10%);
306
+ --input: oklch(1 0 0 / 15%);
307
+ --ring: oklch(0.556 0 0);
308
+ }
309
+
310
+ @theme inline {
311
+ --color-background: var(--background);
312
+ --color-foreground: var(--foreground);
313
+ --color-card: var(--card);
314
+ --color-card-foreground: var(--card-foreground);
315
+ --color-popover: var(--popover);
316
+ --color-popover-foreground: var(--popover-foreground);
317
+ --color-primary: var(--primary);
318
+ --color-primary-foreground: var(--primary-foreground);
319
+ --color-secondary: var(--secondary);
320
+ --color-secondary-foreground: var(--secondary-foreground);
321
+ --color-muted: var(--muted);
322
+ --color-muted-foreground: var(--muted-foreground);
323
+ --color-accent: var(--accent);
324
+ --color-accent-foreground: var(--accent-foreground);
325
+ --color-destructive: var(--destructive);
326
+ --color-destructive-foreground: var(--destructive-foreground);
327
+ --color-border: var(--border);
328
+ --color-input: var(--input);
329
+ --color-ring: var(--ring);
330
+ --radius-sm: calc(var(--radius) - 4px);
331
+ --radius-md: calc(var(--radius) - 2px);
332
+ --radius-lg: var(--radius);
333
+ --radius-xl: calc(var(--radius) + 4px);
334
+ }
335
+
336
+ @layer base {
337
+ * {
338
+ @apply border-border outline-ring/50;
339
+ }
340
+ body {
341
+ @apply bg-background text-foreground;
342
+ }
343
+ }
344
+ `;
345
+
346
+ const UTILS_TS = `import { clsx, type ClassValue } from "clsx";
347
+ import { twMerge } from "tailwind-merge";
348
+
349
+ export function cn(...inputs: ClassValue[]) {
350
+ return twMerge(clsx(inputs));
351
+ }
352
+ `;
353
+
354
+ const BUTTON_TSX = `import { cva, type VariantProps } from "class-variance-authority";
355
+ import type { ButtonHTMLAttributes } from "react";
356
+ import { cn } from "@/lib/utils";
357
+
358
+ const buttonVariants = cva(
359
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md font-medium text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
360
+ {
361
+ variants: {
362
+ variant: {
363
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
364
+ outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
365
+ ghost: "hover:bg-accent hover:text-accent-foreground",
366
+ },
367
+ size: {
368
+ default: "h-9 px-4 py-2",
369
+ sm: "h-8 rounded-md px-3 text-xs",
370
+ lg: "h-10 rounded-md px-6",
371
+ },
372
+ },
373
+ defaultVariants: {
374
+ variant: "default",
375
+ size: "default",
376
+ },
377
+ }
378
+ );
379
+
380
+ export interface ButtonProps
381
+ extends ButtonHTMLAttributes<HTMLButtonElement>,
382
+ VariantProps<typeof buttonVariants> {}
383
+
384
+ export function Button({ className, variant, size, ...props }: ButtonProps) {
385
+ return <button className={cn(buttonVariants({ variant, size, className }))} {...props} />;
386
+ }
387
+
388
+ export { buttonVariants };
389
+ `;
390
+
391
+ const COMPONENTS_JSON = `{
392
+ "$schema": "https://ui.shadcn.com/schema.json",
393
+ "style": "new-york",
394
+ "rsc": false,
395
+ "tsx": true,
396
+ "tailwind": {
397
+ "config": "",
398
+ "css": "src/index.css",
399
+ "baseColor": "neutral",
400
+ "cssVariables": true,
401
+ "prefix": ""
402
+ },
403
+ "iconLibrary": "lucide",
404
+ "aliases": {
405
+ "components": "@/components",
406
+ "utils": "@/lib/utils",
407
+ "ui": "@/components/ui",
408
+ "lib": "@/lib",
409
+ "hooks": "@/hooks"
410
+ }
411
+ }
412
+ `;
413
+
414
+ const GITIGNORE = `node_modules/
415
+ dist/
416
+ .env.local
417
+ .env.*.local
418
+ .mcp.json
419
+ .cursor/mcp.json
420
+ .vscode/mcp.json
421
+ # MCP configs above may contain access tokens; regenerate them with \`collectui configure\`.
422
+ `;
423
+
424
+ const README = (name) => `# ${name}
425
+
426
+ Scaffolded by [\`collectui\`](https://dash.collectui.pro) — one CLI for every
427
+ shadcn library on your CollectUI Dash account.
428
+
429
+ ## Run
430
+
431
+ \`\`\`bash
432
+ npm install
433
+ npm run dev
434
+ \`\`\`
435
+
436
+ ## Install components
437
+
438
+ \`\`\`bash
439
+ collectui add <site> <component>
440
+ # e.g. collectui add reui data-grid
441
+ # or: npx shadcn@latest add @reui/data-grid
442
+ \`\`\`
443
+
444
+ ## Add another library
445
+
446
+ \`\`\`bash
447
+ collectui configure . --libs <site>
448
+ \`\`\`
449
+
450
+ See \`.collectui/environment.md\` for the machine-readable setup record.
451
+ `;
452
+
453
+ function escapeHtml(value) {
454
+ return String(value)
455
+ .replaceAll("&", "&amp;")
456
+ .replaceAll("<", "&lt;")
457
+ .replaceAll(">", "&gt;")
458
+ .replaceAll('"', "&quot;");
459
+ }