@tanstack/cli 0.0.8 → 0.48.2
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/dist/bin.js +7 -0
- package/dist/cli.js +481 -0
- package/dist/command-line.js +174 -0
- package/dist/dev-watch.js +290 -0
- package/dist/file-syncer.js +148 -0
- package/dist/index.js +1 -0
- package/dist/mcp/api.js +31 -0
- package/dist/mcp/tools.js +250 -0
- package/dist/mcp/types.js +37 -0
- package/dist/mcp.js +121 -0
- package/dist/options.js +162 -0
- package/dist/types/bin.d.ts +2 -0
- package/dist/types/cli.d.ts +16 -0
- package/dist/types/command-line.d.ts +10 -0
- package/dist/types/dev-watch.d.ts +27 -0
- package/dist/types/file-syncer.d.ts +18 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mcp/api.d.ts +4 -0
- package/dist/types/mcp/tools.d.ts +2 -0
- package/dist/types/mcp/types.d.ts +217 -0
- package/dist/types/mcp.d.ts +6 -0
- package/dist/types/options.d.ts +8 -0
- package/dist/types/types.d.ts +25 -0
- package/dist/types/ui-environment.d.ts +2 -0
- package/dist/types/ui-prompts.d.ts +12 -0
- package/dist/types/utils.d.ts +8 -0
- package/dist/types.js +1 -0
- package/dist/ui-environment.js +52 -0
- package/dist/ui-prompts.js +244 -0
- package/dist/utils.js +30 -0
- package/package.json +46 -46
- package/src/bin.ts +6 -93
- package/src/cli.ts +692 -0
- package/src/command-line.ts +236 -0
- package/src/dev-watch.ts +430 -0
- package/src/file-syncer.ts +205 -0
- package/src/index.ts +1 -85
- package/src/mcp.ts +190 -0
- package/src/options.ts +260 -0
- package/src/types.ts +27 -0
- package/src/ui-environment.ts +74 -0
- package/src/ui-prompts.ts +322 -0
- package/src/utils.ts +38 -0
- package/tests/command-line.test.ts +304 -0
- package/tests/index.test.ts +9 -0
- package/tests/mcp.test.ts +225 -0
- package/tests/options.test.ts +304 -0
- package/tests/setupVitest.ts +6 -0
- package/tests/ui-environment.test.ts +97 -0
- package/tests/ui-prompts.test.ts +238 -0
- package/tsconfig.json +17 -0
- package/vitest.config.js +7 -0
- package/dist/bin.cjs +0 -769
- package/dist/bin.d.cts +0 -1
- package/dist/bin.d.mts +0 -1
- package/dist/bin.mjs +0 -768
- package/dist/fetch-CbFFGJEw.cjs +0 -3
- package/dist/fetch-DG5dLrsb.cjs +0 -522
- package/dist/fetch-DhlVXS6S.mjs +0 -390
- package/dist/fetch-I_OVg8JX.mjs +0 -3
- package/dist/index.cjs +0 -37
- package/dist/index.d.cts +0 -1172
- package/dist/index.d.mts +0 -1172
- package/dist/index.mjs +0 -4
- package/dist/template-Szi7-AZJ.mjs +0 -2202
- package/dist/template-lWrIZhCQ.cjs +0 -2314
- package/src/api/fetch.test.ts +0 -114
- package/src/api/fetch.ts +0 -278
- package/src/cache/index.ts +0 -89
- package/src/commands/create.ts +0 -470
- package/src/commands/mcp.test.ts +0 -152
- package/src/commands/mcp.ts +0 -211
- package/src/engine/compile-with-addons.test.ts +0 -302
- package/src/engine/compile.test.ts +0 -404
- package/src/engine/compile.ts +0 -569
- package/src/engine/config-file.test.ts +0 -118
- package/src/engine/config-file.ts +0 -61
- package/src/engine/custom-addons/integration.ts +0 -323
- package/src/engine/custom-addons/shared.test.ts +0 -98
- package/src/engine/custom-addons/shared.ts +0 -281
- package/src/engine/custom-addons/template.test.ts +0 -288
- package/src/engine/custom-addons/template.ts +0 -124
- package/src/engine/template.test.ts +0 -256
- package/src/engine/template.ts +0 -269
- package/src/engine/types.ts +0 -336
- package/src/parse-gitignore.d.ts +0 -5
- package/src/templates/base.ts +0 -883
package/dist/bin.mjs
DELETED
|
@@ -1,768 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { a as initIntegration, i as compileIntegration, l as writeConfigFile, n as initTemplate, r as loadTemplate, t as compileTemplate, u as compile } from "./template-Szi7-AZJ.mjs";
|
|
3
|
-
import { a as fetchIntegrations, o as fetchManifest, t as BINARY_PREFIX } from "./fetch-DhlVXS6S.mjs";
|
|
4
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { resolve } from "node:path";
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
import { Command } from "commander";
|
|
8
|
-
import { cancel, confirm, intro, isCancel, log, multiselect, note, outro, select, spinner, text } from "@clack/prompts";
|
|
9
|
-
import chalk from "chalk";
|
|
10
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
12
|
-
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
13
|
-
import express from "express";
|
|
14
|
-
|
|
15
|
-
//#region src/commands/create.ts
|
|
16
|
-
const PACKAGE_MANAGERS = [
|
|
17
|
-
"pnpm",
|
|
18
|
-
"npm",
|
|
19
|
-
"yarn",
|
|
20
|
-
"bun",
|
|
21
|
-
"deno"
|
|
22
|
-
];
|
|
23
|
-
function detectPackageManager() {
|
|
24
|
-
const userAgent = process.env.npm_config_user_agent;
|
|
25
|
-
if (userAgent) {
|
|
26
|
-
if (userAgent.includes("pnpm")) return "pnpm";
|
|
27
|
-
if (userAgent.includes("yarn")) return "yarn";
|
|
28
|
-
if (userAgent.includes("bun")) return "bun";
|
|
29
|
-
if (userAgent.includes("deno")) return "deno";
|
|
30
|
-
}
|
|
31
|
-
return "npm";
|
|
32
|
-
}
|
|
33
|
-
function validateProjectName(name) {
|
|
34
|
-
if (!name) return {
|
|
35
|
-
valid: false,
|
|
36
|
-
error: "Project name is required"
|
|
37
|
-
};
|
|
38
|
-
if (!/^[a-z0-9-_]+$/.test(name)) return {
|
|
39
|
-
valid: false,
|
|
40
|
-
error: "Project name can only contain lowercase letters, numbers, hyphens, and underscores"
|
|
41
|
-
};
|
|
42
|
-
return { valid: true };
|
|
43
|
-
}
|
|
44
|
-
function groupIntegrationsByCategory(integrations) {
|
|
45
|
-
const groups = {};
|
|
46
|
-
for (const integration of integrations) {
|
|
47
|
-
const category = integration.category ?? "other";
|
|
48
|
-
groups[category] ??= [];
|
|
49
|
-
groups[category].push(integration);
|
|
50
|
-
}
|
|
51
|
-
return groups;
|
|
52
|
-
}
|
|
53
|
-
const CATEGORY_LABELS = {
|
|
54
|
-
tanstack: "TanStack",
|
|
55
|
-
database: "Database",
|
|
56
|
-
orm: "ORM",
|
|
57
|
-
auth: "Authentication",
|
|
58
|
-
deploy: "Deployment",
|
|
59
|
-
tooling: "Tooling",
|
|
60
|
-
monitoring: "Monitoring",
|
|
61
|
-
api: "API",
|
|
62
|
-
i18n: "Internationalization",
|
|
63
|
-
cms: "CMS",
|
|
64
|
-
other: "Other"
|
|
65
|
-
};
|
|
66
|
-
const CATEGORY_ORDER = [
|
|
67
|
-
"tanstack",
|
|
68
|
-
"database",
|
|
69
|
-
"orm",
|
|
70
|
-
"auth",
|
|
71
|
-
"deploy",
|
|
72
|
-
"api",
|
|
73
|
-
"monitoring",
|
|
74
|
-
"tooling",
|
|
75
|
-
"i18n",
|
|
76
|
-
"cms",
|
|
77
|
-
"other"
|
|
78
|
-
];
|
|
79
|
-
async function runCreate(projectName, options) {
|
|
80
|
-
intro(chalk.bgCyan(chalk.black(" TanStack Start ")));
|
|
81
|
-
const s = spinner();
|
|
82
|
-
const integrationsPath = options.integrationsPath;
|
|
83
|
-
s.start("Fetching available integrations...");
|
|
84
|
-
let manifest;
|
|
85
|
-
try {
|
|
86
|
-
manifest = await fetchManifest(integrationsPath);
|
|
87
|
-
s.stop("Integrations loaded");
|
|
88
|
-
} catch (error$1) {
|
|
89
|
-
s.stop("Failed to fetch integrations");
|
|
90
|
-
log.error("Could not fetch integration manifest. Check your internet connection.");
|
|
91
|
-
process.exit(1);
|
|
92
|
-
}
|
|
93
|
-
let name = projectName;
|
|
94
|
-
if (!name && !options.yes) {
|
|
95
|
-
const nameInput = await text({
|
|
96
|
-
message: "Project name:",
|
|
97
|
-
placeholder: "my-tanstack-app",
|
|
98
|
-
defaultValue: "my-tanstack-app",
|
|
99
|
-
validate: (value) => {
|
|
100
|
-
const result = validateProjectName(value);
|
|
101
|
-
return result.valid ? void 0 : result.error;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
if (isCancel(nameInput)) {
|
|
105
|
-
cancel("Operation cancelled.");
|
|
106
|
-
process.exit(0);
|
|
107
|
-
}
|
|
108
|
-
name = nameInput;
|
|
109
|
-
}
|
|
110
|
-
name = name ?? "my-tanstack-app";
|
|
111
|
-
const { valid, error } = validateProjectName(name);
|
|
112
|
-
if (!valid) {
|
|
113
|
-
log.error(error ?? "Invalid project name");
|
|
114
|
-
process.exit(1);
|
|
115
|
-
}
|
|
116
|
-
const targetDir = options.targetDir ? resolve(options.targetDir) : resolve(process.cwd(), name);
|
|
117
|
-
if (existsSync(targetDir)) {
|
|
118
|
-
if (!options.yes) {
|
|
119
|
-
const overwrite = await confirm({
|
|
120
|
-
message: `Directory ${chalk.cyan(name)} already exists. Overwrite?`,
|
|
121
|
-
initialValue: false
|
|
122
|
-
});
|
|
123
|
-
if (isCancel(overwrite) || !overwrite) {
|
|
124
|
-
cancel("Operation cancelled.");
|
|
125
|
-
process.exit(0);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
let packageManager = options.packageManager ?? detectPackageManager();
|
|
130
|
-
if (!options.packageManager && !options.yes) {
|
|
131
|
-
const pmChoice = await select({
|
|
132
|
-
message: "Package manager:",
|
|
133
|
-
options: PACKAGE_MANAGERS.map((pm) => ({
|
|
134
|
-
value: pm,
|
|
135
|
-
label: pm
|
|
136
|
-
})),
|
|
137
|
-
initialValue: packageManager
|
|
138
|
-
});
|
|
139
|
-
if (isCancel(pmChoice)) {
|
|
140
|
-
cancel("Operation cancelled.");
|
|
141
|
-
process.exit(0);
|
|
142
|
-
}
|
|
143
|
-
packageManager = pmChoice;
|
|
144
|
-
}
|
|
145
|
-
let tailwind = options.tailwind ?? true;
|
|
146
|
-
if (options.tailwind === void 0 && !options.yes) {
|
|
147
|
-
const twChoice = await confirm({
|
|
148
|
-
message: "Include Tailwind CSS?",
|
|
149
|
-
initialValue: true
|
|
150
|
-
});
|
|
151
|
-
if (isCancel(twChoice)) {
|
|
152
|
-
cancel("Operation cancelled.");
|
|
153
|
-
process.exit(0);
|
|
154
|
-
}
|
|
155
|
-
tailwind = twChoice;
|
|
156
|
-
}
|
|
157
|
-
let selectedIntegrationIds = [];
|
|
158
|
-
if (options.integrations) selectedIntegrationIds = options.integrations.split(",").map((s$1) => s$1.trim());
|
|
159
|
-
else if (!options.yes) {
|
|
160
|
-
const grouped = groupIntegrationsByCategory(manifest.integrations.filter((a) => a.type === "integration" && a.modes.includes("file-router")));
|
|
161
|
-
const categoryOptions = CATEGORY_ORDER.filter((cat) => grouped[cat]?.length).map((cat) => ({
|
|
162
|
-
value: cat,
|
|
163
|
-
label: CATEGORY_LABELS[cat] ?? cat,
|
|
164
|
-
hint: `${grouped[cat].length} integrations`
|
|
165
|
-
}));
|
|
166
|
-
note("Use arrow keys to navigate, space to select/deselect, enter to confirm.", "Integration Selection");
|
|
167
|
-
const selectedCategories = await multiselect({
|
|
168
|
-
message: "Which categories would you like to explore?",
|
|
169
|
-
options: categoryOptions,
|
|
170
|
-
required: false
|
|
171
|
-
});
|
|
172
|
-
if (isCancel(selectedCategories)) {
|
|
173
|
-
cancel("Operation cancelled.");
|
|
174
|
-
process.exit(0);
|
|
175
|
-
}
|
|
176
|
-
for (const category of selectedCategories) {
|
|
177
|
-
const categoryIntegrations = grouped[category];
|
|
178
|
-
if (!categoryIntegrations?.length) continue;
|
|
179
|
-
const integrationChoices = await multiselect({
|
|
180
|
-
message: `Select ${CATEGORY_LABELS[category]} integrations:`,
|
|
181
|
-
options: categoryIntegrations.map((integration) => ({
|
|
182
|
-
value: integration.id,
|
|
183
|
-
label: integration.name,
|
|
184
|
-
hint: integration.description
|
|
185
|
-
})),
|
|
186
|
-
required: false
|
|
187
|
-
});
|
|
188
|
-
if (isCancel(integrationChoices)) {
|
|
189
|
-
cancel("Operation cancelled.");
|
|
190
|
-
process.exit(0);
|
|
191
|
-
}
|
|
192
|
-
selectedIntegrationIds.push(...integrationChoices);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
const integrationMap = new Map(manifest.integrations.map((a) => [a.id, a]));
|
|
196
|
-
const resolvedIds = new Set(selectedIntegrationIds);
|
|
197
|
-
for (const id of selectedIntegrationIds) {
|
|
198
|
-
const integration = integrationMap.get(id);
|
|
199
|
-
if (integration?.dependsOn) for (const dep of integration.dependsOn) resolvedIds.add(dep);
|
|
200
|
-
}
|
|
201
|
-
if (resolvedIds.size > 0) note(Array.from(resolvedIds).map((id) => {
|
|
202
|
-
const integration = integrationMap.get(id);
|
|
203
|
-
return ` ${!selectedIntegrationIds.includes(id) && resolvedIds.has(id) ? chalk.dim("(auto)") : chalk.green("+")} ${integration?.name ?? id}`;
|
|
204
|
-
}).join("\n"), "Selected Integrations");
|
|
205
|
-
if (!options.yes) {
|
|
206
|
-
const proceed = await confirm({
|
|
207
|
-
message: "Create project?",
|
|
208
|
-
initialValue: true
|
|
209
|
-
});
|
|
210
|
-
if (isCancel(proceed) || !proceed) {
|
|
211
|
-
cancel("Operation cancelled.");
|
|
212
|
-
process.exit(0);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
s.start("Preparing project...");
|
|
216
|
-
let customTemplate;
|
|
217
|
-
if (options.template) try {
|
|
218
|
-
customTemplate = await loadTemplate(options.template);
|
|
219
|
-
for (const integrationId of customTemplate.integrations) resolvedIds.add(integrationId);
|
|
220
|
-
tailwind = customTemplate.tailwind;
|
|
221
|
-
} catch (error$1) {
|
|
222
|
-
s.stop("Failed to load template");
|
|
223
|
-
log.error(error$1 instanceof Error ? error$1.message : "Could not load template from URL.");
|
|
224
|
-
process.exit(1);
|
|
225
|
-
}
|
|
226
|
-
let chosenIntegrations = [];
|
|
227
|
-
if (resolvedIds.size > 0) try {
|
|
228
|
-
chosenIntegrations = await fetchIntegrations(Array.from(resolvedIds), integrationsPath);
|
|
229
|
-
} catch (error$1) {
|
|
230
|
-
s.stop("Failed to fetch integration details");
|
|
231
|
-
log.error("Could not fetch integration definitions.");
|
|
232
|
-
process.exit(1);
|
|
233
|
-
}
|
|
234
|
-
const compileOptions = {
|
|
235
|
-
projectName: name,
|
|
236
|
-
framework: customTemplate?.framework ?? "react",
|
|
237
|
-
mode: customTemplate?.mode ?? "file-router",
|
|
238
|
-
typescript: customTemplate?.typescript ?? true,
|
|
239
|
-
tailwind,
|
|
240
|
-
packageManager,
|
|
241
|
-
chosenIntegrations,
|
|
242
|
-
integrationOptions: customTemplate?.integrationOptions ?? {},
|
|
243
|
-
customTemplate
|
|
244
|
-
};
|
|
245
|
-
const output = compile(compileOptions);
|
|
246
|
-
s.stop("Project prepared");
|
|
247
|
-
s.start("Writing files...");
|
|
248
|
-
mkdirSync(targetDir, { recursive: true });
|
|
249
|
-
for (const [filePath, content] of Object.entries(output.files)) {
|
|
250
|
-
const fullPath = resolve(targetDir, filePath);
|
|
251
|
-
mkdirSync(resolve(fullPath, ".."), { recursive: true });
|
|
252
|
-
if (content.startsWith(BINARY_PREFIX)) {
|
|
253
|
-
const base64Data = content.slice(BINARY_PREFIX.length);
|
|
254
|
-
writeFileSync(fullPath, Buffer.from(base64Data, "base64"));
|
|
255
|
-
} else writeFileSync(fullPath, content, "utf-8");
|
|
256
|
-
}
|
|
257
|
-
await writeConfigFile(targetDir, compileOptions);
|
|
258
|
-
s.stop("Files written");
|
|
259
|
-
if (options.git !== false) {
|
|
260
|
-
s.start("Initializing git repository...");
|
|
261
|
-
try {
|
|
262
|
-
const { execSync } = await import("node:child_process");
|
|
263
|
-
execSync("git init", {
|
|
264
|
-
cwd: targetDir,
|
|
265
|
-
stdio: "ignore"
|
|
266
|
-
});
|
|
267
|
-
s.stop("Git initialized");
|
|
268
|
-
} catch {
|
|
269
|
-
s.stop("Git initialization skipped");
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (options.install !== false) {
|
|
273
|
-
s.start(`Installing dependencies with ${packageManager}...`);
|
|
274
|
-
const startTime = Date.now();
|
|
275
|
-
const interval = setInterval(() => {
|
|
276
|
-
const elapsed = Math.floor((Date.now() - startTime) / 1e3);
|
|
277
|
-
s.message(`Installing dependencies with ${packageManager}... (${elapsed}s)`);
|
|
278
|
-
}, 1e3);
|
|
279
|
-
try {
|
|
280
|
-
const { execSync } = await import("node:child_process");
|
|
281
|
-
execSync(packageManager === "yarn" ? "yarn" : `${packageManager} install`, {
|
|
282
|
-
cwd: targetDir,
|
|
283
|
-
stdio: "ignore"
|
|
284
|
-
});
|
|
285
|
-
clearInterval(interval);
|
|
286
|
-
const total = Math.floor((Date.now() - startTime) / 1e3);
|
|
287
|
-
s.stop(`Dependencies installed (${total}s)`);
|
|
288
|
-
} catch {
|
|
289
|
-
clearInterval(interval);
|
|
290
|
-
s.stop("Dependency installation failed");
|
|
291
|
-
log.warning(`Run "${packageManager} install" manually to install dependencies.`);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
const relativePath = resolve(process.cwd()) === targetDir ? "." : name;
|
|
295
|
-
outro(chalk.green("Project created successfully!"));
|
|
296
|
-
console.log();
|
|
297
|
-
console.log("Next steps:");
|
|
298
|
-
console.log();
|
|
299
|
-
if (relativePath !== ".") console.log(` ${chalk.cyan("cd")} ${relativePath}`);
|
|
300
|
-
if (options.install === false) console.log(` ${chalk.cyan(packageManager)} install`);
|
|
301
|
-
console.log(` ${chalk.cyan(packageManager)} ${packageManager === "npm" ? "run " : ""}dev`);
|
|
302
|
-
console.log();
|
|
303
|
-
if (output.envVars.length > 0) {
|
|
304
|
-
console.log(chalk.yellow("Environment variables needed:"));
|
|
305
|
-
console.log();
|
|
306
|
-
for (const envVar of output.envVars) console.log(` ${chalk.cyan(envVar.name)} - ${envVar.description}`);
|
|
307
|
-
console.log();
|
|
308
|
-
console.log(` Add these to your ${chalk.cyan(".env.local")} file.`);
|
|
309
|
-
console.log();
|
|
310
|
-
}
|
|
311
|
-
for (const warning of output.warnings) log.warning(warning);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
//#endregion
|
|
315
|
-
//#region src/mcp/types.ts
|
|
316
|
-
const LibrarySchema = z.object({
|
|
317
|
-
id: z.string(),
|
|
318
|
-
name: z.string(),
|
|
319
|
-
tagline: z.string(),
|
|
320
|
-
description: z.string().optional(),
|
|
321
|
-
frameworks: z.array(z.string()),
|
|
322
|
-
latestVersion: z.string(),
|
|
323
|
-
latestBranch: z.string().optional(),
|
|
324
|
-
availableVersions: z.array(z.string()),
|
|
325
|
-
repo: z.string(),
|
|
326
|
-
docsRoot: z.string().optional(),
|
|
327
|
-
defaultDocs: z.string().optional(),
|
|
328
|
-
docsUrl: z.string().optional(),
|
|
329
|
-
githubUrl: z.string().optional()
|
|
330
|
-
});
|
|
331
|
-
const LibrariesResponseSchema = z.object({
|
|
332
|
-
libraries: z.array(LibrarySchema),
|
|
333
|
-
groups: z.record(z.array(z.string())),
|
|
334
|
-
groupNames: z.record(z.string())
|
|
335
|
-
});
|
|
336
|
-
const PartnerSchema = z.object({
|
|
337
|
-
id: z.string(),
|
|
338
|
-
name: z.string(),
|
|
339
|
-
tagline: z.string().optional(),
|
|
340
|
-
description: z.string(),
|
|
341
|
-
category: z.string(),
|
|
342
|
-
categoryLabel: z.string(),
|
|
343
|
-
libraries: z.array(z.string()),
|
|
344
|
-
url: z.string()
|
|
345
|
-
});
|
|
346
|
-
const PartnersResponseSchema = z.object({
|
|
347
|
-
partners: z.array(PartnerSchema),
|
|
348
|
-
categories: z.array(z.string()),
|
|
349
|
-
categoryLabels: z.record(z.string())
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
//#endregion
|
|
353
|
-
//#region src/mcp/api.ts
|
|
354
|
-
const TANSTACK_API_BASE = "https://tanstack.com/api/data";
|
|
355
|
-
async function fetchLibraries() {
|
|
356
|
-
const response = await fetch(`${TANSTACK_API_BASE}/libraries`);
|
|
357
|
-
if (!response.ok) throw new Error(`Failed to fetch libraries: ${response.statusText}`);
|
|
358
|
-
const data = await response.json();
|
|
359
|
-
return LibrariesResponseSchema.parse(data);
|
|
360
|
-
}
|
|
361
|
-
async function fetchPartners() {
|
|
362
|
-
const response = await fetch(`${TANSTACK_API_BASE}/partners`);
|
|
363
|
-
if (!response.ok) throw new Error(`Failed to fetch partners: ${response.statusText}`);
|
|
364
|
-
const data = await response.json();
|
|
365
|
-
return PartnersResponseSchema.parse(data);
|
|
366
|
-
}
|
|
367
|
-
async function fetchDocContent(repo, branch, filePath) {
|
|
368
|
-
const url = `https://raw.githubusercontent.com/${repo}/${branch}/${filePath}`;
|
|
369
|
-
const response = await fetch(url, { headers: { "User-Agent": "tanstack-cli" } });
|
|
370
|
-
if (!response.ok) {
|
|
371
|
-
if (response.status === 404) return null;
|
|
372
|
-
throw new Error(`Failed to fetch doc: ${response.statusText}`);
|
|
373
|
-
}
|
|
374
|
-
return response.text();
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
//#endregion
|
|
378
|
-
//#region src/mcp/tools.ts
|
|
379
|
-
const ALGOLIA_APP_ID = "FQ0DQ6MA3C";
|
|
380
|
-
const ALGOLIA_API_KEY = "10c34d6a5c89f6048cf644d601e65172";
|
|
381
|
-
const ALGOLIA_INDEX = "tanstack-test";
|
|
382
|
-
const GROUP_KEYS = [
|
|
383
|
-
"state",
|
|
384
|
-
"headlessUI",
|
|
385
|
-
"performance",
|
|
386
|
-
"tooling"
|
|
387
|
-
];
|
|
388
|
-
function jsonResult(data) {
|
|
389
|
-
return { content: [{
|
|
390
|
-
type: "text",
|
|
391
|
-
text: JSON.stringify(data, null, 2)
|
|
392
|
-
}] };
|
|
393
|
-
}
|
|
394
|
-
function errorResult(error) {
|
|
395
|
-
return {
|
|
396
|
-
content: [{
|
|
397
|
-
type: "text",
|
|
398
|
-
text: `Error: ${error}`
|
|
399
|
-
}],
|
|
400
|
-
isError: true
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
function registerDocTools(server) {
|
|
404
|
-
server.tool("tanstack_list_libraries", "List TanStack libraries with metadata, frameworks, and docs URLs.", { group: z.enum(GROUP_KEYS).optional().describe("Filter libraries by group. Options: state, headlessUI, performance, tooling") }, async ({ group }) => {
|
|
405
|
-
try {
|
|
406
|
-
const data = await fetchLibraries();
|
|
407
|
-
let libraries = data.libraries;
|
|
408
|
-
if (group && data.groups[group]) {
|
|
409
|
-
const groupIds = data.groups[group];
|
|
410
|
-
libraries = libraries.filter((lib) => groupIds.includes(lib.id));
|
|
411
|
-
}
|
|
412
|
-
return jsonResult({
|
|
413
|
-
group: group ? data.groupNames[group] || group : "All Libraries",
|
|
414
|
-
count: libraries.length,
|
|
415
|
-
libraries: libraries.map((lib) => ({
|
|
416
|
-
id: lib.id,
|
|
417
|
-
name: lib.name,
|
|
418
|
-
tagline: lib.tagline,
|
|
419
|
-
description: lib.description,
|
|
420
|
-
frameworks: lib.frameworks,
|
|
421
|
-
latestVersion: lib.latestVersion,
|
|
422
|
-
docsUrl: lib.docsUrl,
|
|
423
|
-
githubUrl: lib.githubUrl
|
|
424
|
-
}))
|
|
425
|
-
});
|
|
426
|
-
} catch (error) {
|
|
427
|
-
return errorResult(String(error));
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
server.tool("tanstack_doc", "Fetch a TanStack documentation page by library and path.", {
|
|
431
|
-
library: z.string().describe("Library ID (e.g., query, router, table, form)"),
|
|
432
|
-
path: z.string().describe("Documentation path (e.g., framework/react/overview)"),
|
|
433
|
-
version: z.string().optional().describe("Version (e.g., v5, v1). Defaults to latest")
|
|
434
|
-
}, async ({ library: libraryId, path, version = "latest" }) => {
|
|
435
|
-
try {
|
|
436
|
-
const library = (await fetchLibraries()).libraries.find((l) => l.id === libraryId);
|
|
437
|
-
if (!library) return errorResult(`Library "${libraryId}" not found. Use tanstack_list_libraries to see available libraries.`);
|
|
438
|
-
if (version !== "latest" && !library.availableVersions.includes(version)) return errorResult(`Version "${version}" not found for ${library.name}. Available: ${library.availableVersions.join(", ")}`);
|
|
439
|
-
const branch = version === "latest" || version === library.latestVersion ? library.latestBranch || "main" : version;
|
|
440
|
-
const filePath = `${library.docsRoot || "docs"}/${path}.md`;
|
|
441
|
-
const content = await fetchDocContent(library.repo, branch, filePath);
|
|
442
|
-
if (!content) return errorResult(`Document not found: ${library.name} / ${path} (version: ${version})`);
|
|
443
|
-
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
|
|
444
|
-
let title = path.split("/").pop() || "Untitled";
|
|
445
|
-
let docContent = content;
|
|
446
|
-
if (frontmatterMatch && frontmatterMatch[1]) {
|
|
447
|
-
const titleMatch = frontmatterMatch[1].match(/title:\s*['"]?([^'"\n]+)['"]?/);
|
|
448
|
-
if (titleMatch && titleMatch[1]) title = titleMatch[1];
|
|
449
|
-
docContent = content.slice(frontmatterMatch[0].length).trim();
|
|
450
|
-
}
|
|
451
|
-
return jsonResult({
|
|
452
|
-
title,
|
|
453
|
-
content: docContent,
|
|
454
|
-
url: `https://tanstack.com/${libraryId}/${version}/docs/${path}`,
|
|
455
|
-
library: library.name,
|
|
456
|
-
version: version === "latest" ? library.latestVersion : version
|
|
457
|
-
});
|
|
458
|
-
} catch (error) {
|
|
459
|
-
return errorResult(String(error));
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
server.tool("tanstack_search_docs", "Search TanStack documentation. Returns matching pages with snippets.", {
|
|
463
|
-
query: z.string().describe("Search query"),
|
|
464
|
-
library: z.string().optional().describe("Filter to specific library (e.g., query, router)"),
|
|
465
|
-
framework: z.string().optional().describe("Filter to specific framework (e.g., react, vue, solid)"),
|
|
466
|
-
limit: z.number().min(1).max(50).optional().describe("Maximum number of results (default: 10, max: 50)")
|
|
467
|
-
}, async ({ query, library, framework, limit = 10 }) => {
|
|
468
|
-
try {
|
|
469
|
-
const ALL_LIBRARIES = [
|
|
470
|
-
"config",
|
|
471
|
-
"form",
|
|
472
|
-
"optimistic",
|
|
473
|
-
"pacer",
|
|
474
|
-
"query",
|
|
475
|
-
"ranger",
|
|
476
|
-
"react-charts",
|
|
477
|
-
"router",
|
|
478
|
-
"start",
|
|
479
|
-
"store",
|
|
480
|
-
"table",
|
|
481
|
-
"virtual",
|
|
482
|
-
"db",
|
|
483
|
-
"devtools"
|
|
484
|
-
];
|
|
485
|
-
const ALL_FRAMEWORKS = [
|
|
486
|
-
"react",
|
|
487
|
-
"vue",
|
|
488
|
-
"solid",
|
|
489
|
-
"svelte",
|
|
490
|
-
"angular"
|
|
491
|
-
];
|
|
492
|
-
const filterParts = ["version:latest"];
|
|
493
|
-
if (library) {
|
|
494
|
-
const exclusions = ALL_LIBRARIES.filter((l) => l !== library).map((l) => `NOT library:${l}`).join(" AND ");
|
|
495
|
-
if (exclusions) filterParts.push(`(${exclusions})`);
|
|
496
|
-
}
|
|
497
|
-
if (framework) {
|
|
498
|
-
const exclusions = ALL_FRAMEWORKS.filter((f) => f !== framework).map((f) => `NOT framework:${f}`).join(" AND ");
|
|
499
|
-
if (exclusions) filterParts.push(`(${exclusions})`);
|
|
500
|
-
}
|
|
501
|
-
const searchParams = { requests: [{
|
|
502
|
-
indexName: ALGOLIA_INDEX,
|
|
503
|
-
query,
|
|
504
|
-
hitsPerPage: Math.min(limit, 50),
|
|
505
|
-
filters: filterParts.join(" AND "),
|
|
506
|
-
attributesToRetrieve: [
|
|
507
|
-
"hierarchy",
|
|
508
|
-
"url",
|
|
509
|
-
"content",
|
|
510
|
-
"library"
|
|
511
|
-
],
|
|
512
|
-
attributesToSnippet: ["content:80"]
|
|
513
|
-
}] };
|
|
514
|
-
const response = await fetch(`https://${ALGOLIA_APP_ID}-dsn.algolia.net/1/indexes/*/queries`, {
|
|
515
|
-
method: "POST",
|
|
516
|
-
headers: {
|
|
517
|
-
"Content-Type": "application/json",
|
|
518
|
-
"X-Algolia-Application-Id": ALGOLIA_APP_ID,
|
|
519
|
-
"X-Algolia-API-Key": ALGOLIA_API_KEY
|
|
520
|
-
},
|
|
521
|
-
body: JSON.stringify(searchParams)
|
|
522
|
-
});
|
|
523
|
-
if (!response.ok) return errorResult(`Algolia search failed: ${response.statusText}`);
|
|
524
|
-
const searchResult = (await response.json()).results[0];
|
|
525
|
-
if (!searchResult) return jsonResult({
|
|
526
|
-
query,
|
|
527
|
-
totalHits: 0,
|
|
528
|
-
results: []
|
|
529
|
-
});
|
|
530
|
-
const results = searchResult.hits.map((hit) => {
|
|
531
|
-
const breadcrumb = Object.values(hit.hierarchy).filter((v) => Boolean(v));
|
|
532
|
-
return {
|
|
533
|
-
title: hit.hierarchy.lvl1 || hit.hierarchy.lvl0 || "Untitled",
|
|
534
|
-
url: hit.url,
|
|
535
|
-
snippet: hit._snippetResult?.content?.value || hit.content || "",
|
|
536
|
-
library: hit.library || "unknown",
|
|
537
|
-
breadcrumb
|
|
538
|
-
};
|
|
539
|
-
});
|
|
540
|
-
return jsonResult({
|
|
541
|
-
query,
|
|
542
|
-
totalHits: searchResult.nbHits || results.length,
|
|
543
|
-
results
|
|
544
|
-
});
|
|
545
|
-
} catch (error) {
|
|
546
|
-
return errorResult(String(error));
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
server.tool("tanstack_ecosystem", "Ecosystem partner recommendations. Filter by category (database, auth, deployment, monitoring, cms, api, data-grid) or library.", {
|
|
550
|
-
category: z.string().optional().describe("Filter by category: database, auth, deployment, monitoring, cms, api, data-grid, code-review, learning"),
|
|
551
|
-
library: z.string().optional().describe("Filter by TanStack library (e.g., start, router, query, table)")
|
|
552
|
-
}, async ({ category, library }) => {
|
|
553
|
-
try {
|
|
554
|
-
const data = await fetchPartners();
|
|
555
|
-
const categoryAliases = {
|
|
556
|
-
db: "database",
|
|
557
|
-
postgres: "database",
|
|
558
|
-
sql: "database",
|
|
559
|
-
login: "auth",
|
|
560
|
-
authentication: "auth",
|
|
561
|
-
hosting: "deployment",
|
|
562
|
-
deploy: "deployment",
|
|
563
|
-
serverless: "deployment",
|
|
564
|
-
errors: "monitoring",
|
|
565
|
-
logging: "monitoring",
|
|
566
|
-
content: "cms",
|
|
567
|
-
"api-keys": "api",
|
|
568
|
-
grid: "data-grid",
|
|
569
|
-
review: "code-review",
|
|
570
|
-
courses: "learning"
|
|
571
|
-
};
|
|
572
|
-
let resolvedCategory;
|
|
573
|
-
if (category) {
|
|
574
|
-
const normalized = category.toLowerCase().trim();
|
|
575
|
-
resolvedCategory = categoryAliases[normalized] || normalized;
|
|
576
|
-
if (!data.categories.includes(resolvedCategory)) resolvedCategory = void 0;
|
|
577
|
-
}
|
|
578
|
-
const lib = library?.toLowerCase().trim();
|
|
579
|
-
const partners = data.partners.filter((p) => !resolvedCategory || p.category === resolvedCategory).filter((p) => !lib || p.libraries.some((l) => l === lib)).map((p) => ({
|
|
580
|
-
id: p.id,
|
|
581
|
-
name: p.name,
|
|
582
|
-
tagline: p.tagline,
|
|
583
|
-
description: p.description,
|
|
584
|
-
category: p.category,
|
|
585
|
-
categoryLabel: p.categoryLabel,
|
|
586
|
-
url: p.url,
|
|
587
|
-
libraries: p.libraries
|
|
588
|
-
}));
|
|
589
|
-
return jsonResult({
|
|
590
|
-
query: {
|
|
591
|
-
category,
|
|
592
|
-
categoryResolved: resolvedCategory,
|
|
593
|
-
library
|
|
594
|
-
},
|
|
595
|
-
count: partners.length,
|
|
596
|
-
partners
|
|
597
|
-
});
|
|
598
|
-
} catch (error) {
|
|
599
|
-
return errorResult(String(error));
|
|
600
|
-
}
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
//#endregion
|
|
605
|
-
//#region src/commands/mcp.ts
|
|
606
|
-
function createServer() {
|
|
607
|
-
const server = new McpServer({
|
|
608
|
-
name: "TanStack CLI",
|
|
609
|
-
version: "0.0.1"
|
|
610
|
-
});
|
|
611
|
-
server.tool("listTanStackIntegrations", "List available integrations for creating TanStack applications", {}, async () => {
|
|
612
|
-
try {
|
|
613
|
-
const integrations = (await fetchManifest()).integrations.filter((a) => a.modes.includes("file-router")).map((integration) => ({
|
|
614
|
-
id: integration.id,
|
|
615
|
-
name: integration.name,
|
|
616
|
-
description: integration.description,
|
|
617
|
-
category: integration.category,
|
|
618
|
-
dependsOn: integration.dependsOn,
|
|
619
|
-
exclusive: integration.exclusive,
|
|
620
|
-
hasOptions: integration.hasOptions
|
|
621
|
-
}));
|
|
622
|
-
return { content: [{
|
|
623
|
-
type: "text",
|
|
624
|
-
text: JSON.stringify(integrations, null, 2)
|
|
625
|
-
}] };
|
|
626
|
-
} catch (error) {
|
|
627
|
-
return { content: [{
|
|
628
|
-
type: "text",
|
|
629
|
-
text: `Error fetching integrations: ${error}`
|
|
630
|
-
}] };
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
registerDocTools(server);
|
|
634
|
-
server.tool("createTanStackApplication", "Create a new TanStack Start application", {
|
|
635
|
-
projectName: z.string().describe("The name of the project (will be the directory name)"),
|
|
636
|
-
targetDir: z.string().describe("Absolute path where the project should be created"),
|
|
637
|
-
integrations: z.array(z.string()).optional().describe("Array of integration IDs to include. Use listTanStackIntegrations to see available options."),
|
|
638
|
-
integrationOptions: z.record(z.record(z.unknown())).optional().describe("Configuration for integrations. Format: {\"integrationId\": {\"optionName\": \"value\"}}"),
|
|
639
|
-
tailwind: z.boolean().optional().describe("Include Tailwind CSS (default: true)"),
|
|
640
|
-
packageManager: z.enum([
|
|
641
|
-
"npm",
|
|
642
|
-
"pnpm",
|
|
643
|
-
"yarn",
|
|
644
|
-
"bun",
|
|
645
|
-
"deno"
|
|
646
|
-
]).optional().describe("Package manager to use (default: pnpm)")
|
|
647
|
-
}, async ({ projectName, targetDir, integrations, integrationOptions, tailwind, packageManager }) => {
|
|
648
|
-
try {
|
|
649
|
-
const { mkdirSync: mkdirSync$1, writeFileSync: writeFileSync$1 } = await import("node:fs");
|
|
650
|
-
const { resolve: resolve$1 } = await import("node:path");
|
|
651
|
-
const { BINARY_PREFIX: BINARY_PREFIX$1 } = await import("./fetch-I_OVg8JX.mjs");
|
|
652
|
-
const { execSync } = await import("node:child_process");
|
|
653
|
-
let chosenIntegrations = [];
|
|
654
|
-
if (integrations?.length) chosenIntegrations = await fetchIntegrations(integrations);
|
|
655
|
-
const output = compile({
|
|
656
|
-
projectName,
|
|
657
|
-
framework: "react",
|
|
658
|
-
mode: "file-router",
|
|
659
|
-
typescript: true,
|
|
660
|
-
tailwind: tailwind ?? true,
|
|
661
|
-
packageManager: packageManager ?? "pnpm",
|
|
662
|
-
chosenIntegrations,
|
|
663
|
-
integrationOptions: integrationOptions ?? {}
|
|
664
|
-
});
|
|
665
|
-
mkdirSync$1(targetDir, { recursive: true });
|
|
666
|
-
for (const [filePath, content] of Object.entries(output.files)) {
|
|
667
|
-
const fullPath = resolve$1(targetDir, filePath);
|
|
668
|
-
mkdirSync$1(resolve$1(fullPath, ".."), { recursive: true });
|
|
669
|
-
if (content.startsWith(BINARY_PREFIX$1)) {
|
|
670
|
-
const base64Data = content.slice(BINARY_PREFIX$1.length);
|
|
671
|
-
writeFileSync$1(fullPath, Buffer.from(base64Data, "base64"));
|
|
672
|
-
} else writeFileSync$1(fullPath, content, "utf-8");
|
|
673
|
-
}
|
|
674
|
-
try {
|
|
675
|
-
execSync("git init", {
|
|
676
|
-
cwd: targetDir,
|
|
677
|
-
stdio: "ignore"
|
|
678
|
-
});
|
|
679
|
-
} catch {}
|
|
680
|
-
const envVarList = output.envVars.length > 0 ? `\n\nRequired environment variables:\n${output.envVars.map((e) => `- ${e.name}: ${e.description}`).join("\n")}` : "";
|
|
681
|
-
const warnings = output.warnings.length > 0 ? `\n\nWarnings:\n${output.warnings.map((w) => `- ${w}`).join("\n")}` : "";
|
|
682
|
-
return { content: [{
|
|
683
|
-
type: "text",
|
|
684
|
-
text: `Project "${projectName}" created successfully at ${targetDir}
|
|
685
|
-
|
|
686
|
-
Files created: ${Object.keys(output.files).length}
|
|
687
|
-
Integrations included: ${chosenIntegrations.map((a) => a.name).join(", ") || "none"}${envVarList}${warnings}
|
|
688
|
-
|
|
689
|
-
Next steps:
|
|
690
|
-
1. cd ${targetDir}
|
|
691
|
-
2. ${packageManager ?? "pnpm"} install
|
|
692
|
-
3. ${packageManager ?? "pnpm"} dev`
|
|
693
|
-
}] };
|
|
694
|
-
} catch (error) {
|
|
695
|
-
return { content: [{
|
|
696
|
-
type: "text",
|
|
697
|
-
text: `Error creating application: ${error}`
|
|
698
|
-
}] };
|
|
699
|
-
}
|
|
700
|
-
});
|
|
701
|
-
return server;
|
|
702
|
-
}
|
|
703
|
-
async function runMcp(options) {
|
|
704
|
-
const server = createServer();
|
|
705
|
-
if (options.sse) {
|
|
706
|
-
const app = express();
|
|
707
|
-
let transport = null;
|
|
708
|
-
app.get("/sse", (_req, res) => {
|
|
709
|
-
transport = new SSEServerTransport("/messages", res);
|
|
710
|
-
server.connect(transport);
|
|
711
|
-
});
|
|
712
|
-
app.post("/messages", (req, res) => {
|
|
713
|
-
if (transport) transport.handlePostMessage(req, res);
|
|
714
|
-
});
|
|
715
|
-
const port = parseInt(options.port ?? "8080", 10);
|
|
716
|
-
app.listen(port, () => {
|
|
717
|
-
console.log(`MCP server running at http://localhost:${port}/sse`);
|
|
718
|
-
});
|
|
719
|
-
} else {
|
|
720
|
-
const transport = new StdioServerTransport();
|
|
721
|
-
await server.connect(transport);
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
//#endregion
|
|
726
|
-
//#region src/bin.ts
|
|
727
|
-
const program = new Command();
|
|
728
|
-
program.name("tanstack").description("TanStack CLI for scaffolding and tooling").version("0.0.1");
|
|
729
|
-
program.command("create").argument("[project-name]", "name of the project").option("--template <template>", "URL to a custom template JSON file").option("--package-manager <pm>", "package manager (npm, pnpm, yarn, bun)").option("--integrations <integrations>", "comma-separated list of integration IDs").option("--no-install", "skip installing dependencies").option("--no-git", "skip initializing git repository").option("--no-tailwind", "skip tailwind CSS").option("-y, --yes", "skip prompts and use defaults").option("--target-dir <path>", "target directory for the project").option("--integrations-path <path>", "local path to integrations directory (for development)").description("Create a new TanStack Start project").action(runCreate);
|
|
730
|
-
program.command("mcp").option("--sse", "run in SSE mode (for HTTP transport)").option("--port <port>", "port for SSE server", "8080").description("Start the MCP server for AI agents").action(runMcp);
|
|
731
|
-
const integrationCommand = program.command("integration");
|
|
732
|
-
integrationCommand.command("init").option("--integrations-path <path>", "local path to integrations directory (for development)").description("Initialize an integration from the current project").action(async (options) => {
|
|
733
|
-
try {
|
|
734
|
-
await initIntegration(resolve(process.cwd()), options.integrationsPath);
|
|
735
|
-
} catch (error) {
|
|
736
|
-
console.error(error instanceof Error ? error.message : "An error occurred");
|
|
737
|
-
process.exit(1);
|
|
738
|
-
}
|
|
739
|
-
});
|
|
740
|
-
integrationCommand.command("compile").option("--integrations-path <path>", "local path to integrations directory (for development)").description("Compile/update the integration from the current project").action(async (options) => {
|
|
741
|
-
try {
|
|
742
|
-
await compileIntegration(resolve(process.cwd()), options.integrationsPath);
|
|
743
|
-
} catch (error) {
|
|
744
|
-
console.error(error instanceof Error ? error.message : "An error occurred");
|
|
745
|
-
process.exit(1);
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
const templateCommand = program.command("template");
|
|
749
|
-
templateCommand.command("init").description("Initialize a custom template from the current project").action(async () => {
|
|
750
|
-
try {
|
|
751
|
-
await initTemplate(resolve(process.cwd()));
|
|
752
|
-
} catch (error) {
|
|
753
|
-
console.error(error instanceof Error ? error.message : "An error occurred");
|
|
754
|
-
process.exit(1);
|
|
755
|
-
}
|
|
756
|
-
});
|
|
757
|
-
templateCommand.command("compile").description("Compile/update the custom template from the current project").action(async () => {
|
|
758
|
-
try {
|
|
759
|
-
await compileTemplate(resolve(process.cwd()));
|
|
760
|
-
} catch (error) {
|
|
761
|
-
console.error(error instanceof Error ? error.message : "An error occurred");
|
|
762
|
-
process.exit(1);
|
|
763
|
-
}
|
|
764
|
-
});
|
|
765
|
-
program.parse();
|
|
766
|
-
|
|
767
|
-
//#endregion
|
|
768
|
-
export { };
|