@tanstack/cli 0.0.1

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.
@@ -0,0 +1,2496 @@
1
+ import { render } from "ejs";
2
+ import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
3
+ import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
4
+ import { basename, dirname, extname, join, resolve } from "node:path";
5
+ import { z } from "zod";
6
+ import ignore from "ignore";
7
+ import parseGitignore from "parse-gitignore";
8
+
9
+ //#region src/engine/template.ts
10
+ /**
11
+ * Convert _dot_ prefixes to actual dots (for dotfiles)
12
+ */
13
+ function convertDotFiles(path) {
14
+ return path.split("/").map((segment) => segment.replace(/^_dot_/, ".")).join("/");
15
+ }
16
+ /**
17
+ * Strip option prefixes from filename
18
+ * e.g., __postgres__schema.prisma -> schema.prisma
19
+ */
20
+ function stripOptionPrefix(path) {
21
+ const match = path.match(/^(.+\/)?__([^_]+)__(.+)$/);
22
+ if (match) {
23
+ const [, directory, , filename] = match;
24
+ return (directory || "") + filename;
25
+ }
26
+ return path;
27
+ }
28
+ /**
29
+ * Calculate relative path between two file paths
30
+ */
31
+ function relativePath(from, to, stripExtension = false) {
32
+ const fromParts = from.split("/").slice(0, -1);
33
+ const toParts = to.split("/");
34
+ let commonLength = 0;
35
+ while (commonLength < fromParts.length && commonLength < toParts.length && fromParts[commonLength] === toParts[commonLength]) commonLength++;
36
+ const upCount = fromParts.length - commonLength;
37
+ const ups = Array(upCount).fill("..");
38
+ const remainder = toParts.slice(commonLength);
39
+ let result = [...ups, ...remainder].join("/");
40
+ if (!result.startsWith(".")) result = "./" + result;
41
+ if (stripExtension) result = result.replace(/\.[^/.]+$/, "");
42
+ return result;
43
+ }
44
+ /**
45
+ * Error thrown when ignoreFile() is called in a template
46
+ */
47
+ var IgnoreFileError = class extends Error {
48
+ constructor() {
49
+ super("ignoreFile");
50
+ this.name = "IgnoreFileError";
51
+ }
52
+ };
53
+ /**
54
+ * Create template context from compile options
55
+ */
56
+ function createTemplateContext(options, currentFile) {
57
+ const hooks = [];
58
+ for (const integration of options.chosenIntegrations) if (integration.hooks) hooks.push(...integration.hooks);
59
+ const routes = [];
60
+ for (const integration of options.chosenIntegrations) if (integration.routes) routes.push(...integration.routes);
61
+ const integrationEnabled = {};
62
+ for (const integration of options.chosenIntegrations) integrationEnabled[integration.id] = true;
63
+ const localRelativePath = (to, stripExt = false) => relativePath(currentFile, to, stripExt);
64
+ const hookImportContent = (hook) => hook.import || `import ${hook.jsName} from '${localRelativePath(hook.path || "")}'`;
65
+ const hookImportCode = (hook) => hook.code || hook.jsName || "";
66
+ return {
67
+ packageManager: options.packageManager,
68
+ projectName: options.projectName,
69
+ typescript: options.typescript,
70
+ tailwind: options.tailwind,
71
+ js: options.typescript ? "ts" : "js",
72
+ jsx: options.typescript ? "tsx" : "jsx",
73
+ fileRouter: options.mode === "file-router",
74
+ codeRouter: options.mode === "code-router",
75
+ integrationEnabled,
76
+ integrationOption: options.integrationOptions,
77
+ integrations: options.chosenIntegrations,
78
+ hooks,
79
+ routes,
80
+ getPackageManagerAddScript: (pkg, isDev = false) => {
81
+ const pm = options.packageManager;
82
+ if (pm === "npm") return `npm install ${isDev ? "-D " : ""}${pkg}`;
83
+ if (pm === "yarn") return `yarn add ${isDev ? "-D " : ""}${pkg}`;
84
+ if (pm === "pnpm") return `pnpm add ${isDev ? "-D " : ""}${pkg}`;
85
+ if (pm === "bun") return `bun add ${isDev ? "-d " : ""}${pkg}`;
86
+ if (pm === "deno") return `deno add ${pkg}`;
87
+ return `npm install ${isDev ? "-D " : ""}${pkg}`;
88
+ },
89
+ getPackageManagerRunScript: (script, args = []) => {
90
+ const pm = options.packageManager;
91
+ const argsStr = args.length ? " " + args.join(" ") : "";
92
+ if (pm === "npm") return `npm run ${script}${argsStr}`;
93
+ if (pm === "yarn") return `yarn ${script}${argsStr}`;
94
+ if (pm === "pnpm") return `pnpm ${script}${argsStr}`;
95
+ if (pm === "bun") return `bun run ${script}${argsStr}`;
96
+ if (pm === "deno") return `deno task ${script}${argsStr}`;
97
+ return `npm run ${script}${argsStr}`;
98
+ },
99
+ relativePath: localRelativePath,
100
+ hookImportContent,
101
+ hookImportCode,
102
+ ignoreFile: () => {
103
+ throw new IgnoreFileError();
104
+ }
105
+ };
106
+ }
107
+ /**
108
+ * Process a template file with EJS
109
+ */
110
+ function processTemplateFile(filePath, content, options) {
111
+ const context = createTemplateContext(options, filePath);
112
+ let processedContent = content;
113
+ let shouldIgnore = false;
114
+ if (filePath.endsWith(".ejs")) try {
115
+ processedContent = render(content, context);
116
+ } catch (error) {
117
+ if (error instanceof IgnoreFileError) shouldIgnore = true;
118
+ else throw new Error(`EJS error in file ${filePath}: ${error}`);
119
+ }
120
+ if (shouldIgnore) return null;
121
+ let outputPath = filePath;
122
+ outputPath = outputPath.replace(/\.ejs$/, "");
123
+ outputPath = convertDotFiles(outputPath);
124
+ outputPath = stripOptionPrefix(outputPath);
125
+ let append = false;
126
+ if (outputPath.endsWith(".append")) {
127
+ append = true;
128
+ outputPath = outputPath.replace(/\.append$/, "");
129
+ }
130
+ if (!options.typescript) outputPath = outputPath.replace(/\.tsx$/, ".jsx").replace(/\.ts$/, ".js");
131
+ return {
132
+ path: outputPath,
133
+ content: processedContent,
134
+ append
135
+ };
136
+ }
137
+
138
+ //#endregion
139
+ //#region src/templates/base.ts
140
+ /**
141
+ * Base TanStack Start template files
142
+ * These provide the foundation for every project
143
+ */
144
+ /**
145
+ * Collect all hooks from integrations, grouped by type
146
+ */
147
+ function collectHooks(options) {
148
+ const hooks = [];
149
+ for (const integration of options.chosenIntegrations) if (integration.hooks) for (const hook of integration.hooks) hooks.push({
150
+ ...hook,
151
+ integrationId: integration.id
152
+ });
153
+ return {
154
+ vitePlugins: hooks.filter((i) => i.type === "vite-plugin"),
155
+ rootProviders: hooks.filter((i) => i.type === "root-provider"),
156
+ devtoolsPlugins: hooks.filter((i) => i.type === "devtools"),
157
+ entryClientInits: hooks.filter((i) => i.type === "entry-client")
158
+ };
159
+ }
160
+ /**
161
+ * Generate vite.config.ts content with line attribution
162
+ */
163
+ function generateViteConfig(options, vitePlugins) {
164
+ const { tailwind } = options;
165
+ const lines = [];
166
+ lines.push({
167
+ text: `import { defineConfig } from 'vite'`,
168
+ integrationId: "base"
169
+ });
170
+ lines.push({
171
+ text: `import { tanstackStart } from '@tanstack/react-start/plugin/vite'`,
172
+ integrationId: "base"
173
+ });
174
+ lines.push({
175
+ text: `import viteReact from '@vitejs/plugin-react'`,
176
+ integrationId: "base"
177
+ });
178
+ lines.push({
179
+ text: `import viteTsConfigPaths from 'vite-tsconfig-paths'`,
180
+ integrationId: "base"
181
+ });
182
+ if (tailwind) lines.push({
183
+ text: `import tailwindcss from '@tailwindcss/vite'`,
184
+ integrationId: "base"
185
+ });
186
+ for (const plugin of vitePlugins) if (plugin.import) lines.push({
187
+ text: plugin.import,
188
+ integrationId: plugin.integrationId
189
+ });
190
+ else {
191
+ const importPath = relativePath("vite.config.ts", plugin.path || `src/integrations/${plugin.integrationId}/vite-plugin.ts`, true);
192
+ lines.push({
193
+ text: `import ${plugin.jsName} from '${importPath}'`,
194
+ integrationId: plugin.integrationId
195
+ });
196
+ }
197
+ lines.push({
198
+ text: "",
199
+ integrationId: "base"
200
+ });
201
+ lines.push({
202
+ text: `export default defineConfig({`,
203
+ integrationId: "base"
204
+ });
205
+ lines.push({
206
+ text: ` plugins: [`,
207
+ integrationId: "base"
208
+ });
209
+ lines.push({
210
+ text: ` viteTsConfigPaths({`,
211
+ integrationId: "base"
212
+ });
213
+ lines.push({
214
+ text: ` projects: ['./tsconfig.json'],`,
215
+ integrationId: "base"
216
+ });
217
+ lines.push({
218
+ text: ` }),`,
219
+ integrationId: "base"
220
+ });
221
+ if (tailwind) lines.push({
222
+ text: ` tailwindcss(),`,
223
+ integrationId: "base"
224
+ });
225
+ lines.push({
226
+ text: ` tanstackStart(),`,
227
+ integrationId: "base"
228
+ });
229
+ lines.push({
230
+ text: ` viteReact(),`,
231
+ integrationId: "base"
232
+ });
233
+ for (const plugin of vitePlugins) {
234
+ const pluginCall = plugin.code || `${plugin.jsName}()`;
235
+ lines.push({
236
+ text: ` ${pluginCall},`,
237
+ integrationId: plugin.integrationId
238
+ });
239
+ }
240
+ lines.push({
241
+ text: ` ],`,
242
+ integrationId: "base"
243
+ });
244
+ lines.push({
245
+ text: `})`,
246
+ integrationId: "base"
247
+ });
248
+ return {
249
+ content: lines.map((l) => l.text).join("\n"),
250
+ lineAttributions: lines.map((l, i) => ({
251
+ line: i + 1,
252
+ integrationId: l.integrationId
253
+ }))
254
+ };
255
+ }
256
+ /**
257
+ * Generate entry-client.tsx content with line attribution
258
+ */
259
+ function generateEntryClient(_options, entryClientInits) {
260
+ const lines = [];
261
+ lines.push({
262
+ text: `import { hydrateRoot } from 'react-dom/client'`,
263
+ integrationId: "base"
264
+ });
265
+ lines.push({
266
+ text: `import { StartClient } from '@tanstack/react-start'`,
267
+ integrationId: "base"
268
+ });
269
+ lines.push({
270
+ text: `import { getRouter } from './router'`,
271
+ integrationId: "base"
272
+ });
273
+ for (const init of entryClientInits) {
274
+ const importPath = relativePath("src/entry-client.tsx", init.path || `src/integrations/${init.integrationId}/client.ts`, true);
275
+ lines.push({
276
+ text: `import { ${init.jsName} } from '${importPath}'`,
277
+ integrationId: init.integrationId
278
+ });
279
+ }
280
+ lines.push({
281
+ text: "",
282
+ integrationId: "base"
283
+ });
284
+ if (entryClientInits.length > 0) {
285
+ lines.push({
286
+ text: `// Initialize integrations`,
287
+ integrationId: "base"
288
+ });
289
+ for (const init of entryClientInits) lines.push({
290
+ text: `${init.jsName}()`,
291
+ integrationId: init.integrationId
292
+ });
293
+ lines.push({
294
+ text: "",
295
+ integrationId: "base"
296
+ });
297
+ }
298
+ lines.push({
299
+ text: `const router = getRouter()`,
300
+ integrationId: "base"
301
+ });
302
+ lines.push({
303
+ text: "",
304
+ integrationId: "base"
305
+ });
306
+ lines.push({
307
+ text: `hydrateRoot(document.getElementById('root')!, <StartClient router={router} />)`,
308
+ integrationId: "base"
309
+ });
310
+ return {
311
+ content: lines.map((l) => l.text).join("\n"),
312
+ lineAttributions: lines.map((l, i) => ({
313
+ line: i + 1,
314
+ integrationId: l.integrationId
315
+ }))
316
+ };
317
+ }
318
+ /**
319
+ * Generate __root.tsx content with line attribution
320
+ * This generates a full document route with shellComponent for proper SSR
321
+ */
322
+ function generateRootRoute(options, rootProviders, devtoolsPlugins) {
323
+ const lines = [];
324
+ const hasHeader = options.chosenIntegrations.length > 0;
325
+ if (devtoolsPlugins.length > 0) lines.push({
326
+ text: `import React from 'react'`,
327
+ integrationId: "base"
328
+ });
329
+ lines.push({
330
+ text: `import { HeadContent, Scripts, createRootRoute } from '@tanstack/react-router'`,
331
+ integrationId: "base"
332
+ });
333
+ lines.push({
334
+ text: `import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'`,
335
+ integrationId: "base"
336
+ });
337
+ lines.push({
338
+ text: `import appCss from '../styles.css?url'`,
339
+ integrationId: "base"
340
+ });
341
+ if (hasHeader) lines.push({
342
+ text: `import { Header } from '../components/Header'`,
343
+ integrationId: "base"
344
+ });
345
+ for (const provider of rootProviders) {
346
+ const importPath = relativePath("src/routes/__root.tsx", provider.path || `src/integrations/${provider.integrationId}/provider.tsx`, true);
347
+ lines.push({
348
+ text: `import { ${provider.jsName} } from '${importPath}'`,
349
+ integrationId: provider.integrationId
350
+ });
351
+ }
352
+ for (const devtools of devtoolsPlugins) {
353
+ const importPath = relativePath("src/routes/__root.tsx", devtools.path || `src/integrations/${devtools.integrationId}/devtools.tsx`, true);
354
+ lines.push({
355
+ text: `import { ${devtools.jsName} } from '${importPath}'`,
356
+ integrationId: devtools.integrationId
357
+ });
358
+ }
359
+ if (devtoolsPlugins.length > 0) {
360
+ lines.push({
361
+ text: "",
362
+ integrationId: "base"
363
+ });
364
+ lines.push({
365
+ text: `const devtoolsPlugins = [`,
366
+ integrationId: "base"
367
+ });
368
+ for (const devtools of devtoolsPlugins) lines.push({
369
+ text: ` ${devtools.jsName},`,
370
+ integrationId: devtools.integrationId
371
+ });
372
+ lines.push({
373
+ text: `]`,
374
+ integrationId: "base"
375
+ });
376
+ }
377
+ lines.push({
378
+ text: "",
379
+ integrationId: "base"
380
+ });
381
+ lines.push({
382
+ text: `export const Route = createRootRoute({`,
383
+ integrationId: "base"
384
+ });
385
+ lines.push({
386
+ text: ` head: () => ({`,
387
+ integrationId: "base"
388
+ });
389
+ lines.push({
390
+ text: ` meta: [`,
391
+ integrationId: "base"
392
+ });
393
+ lines.push({
394
+ text: ` { charSet: 'utf-8' },`,
395
+ integrationId: "base"
396
+ });
397
+ lines.push({
398
+ text: ` { name: 'viewport', content: 'width=device-width, initial-scale=1' },`,
399
+ integrationId: "base"
400
+ });
401
+ lines.push({
402
+ text: ` { title: 'TanStack Start Starter' },`,
403
+ integrationId: "base"
404
+ });
405
+ lines.push({
406
+ text: ` ],`,
407
+ integrationId: "base"
408
+ });
409
+ lines.push({
410
+ text: ` links: [{ rel: 'stylesheet', href: appCss }],`,
411
+ integrationId: "base"
412
+ });
413
+ lines.push({
414
+ text: ` }),`,
415
+ integrationId: "base"
416
+ });
417
+ lines.push({
418
+ text: ` shellComponent: RootDocument,`,
419
+ integrationId: "base"
420
+ });
421
+ lines.push({
422
+ text: `})`,
423
+ integrationId: "base"
424
+ });
425
+ lines.push({
426
+ text: "",
427
+ integrationId: "base"
428
+ });
429
+ lines.push({
430
+ text: `function RootDocument({ children }: { children: React.ReactNode }) {`,
431
+ integrationId: "base"
432
+ });
433
+ lines.push({
434
+ text: ` return (`,
435
+ integrationId: "base"
436
+ });
437
+ lines.push({
438
+ text: ` <html lang="en">`,
439
+ integrationId: "base"
440
+ });
441
+ lines.push({
442
+ text: ` <head>`,
443
+ integrationId: "base"
444
+ });
445
+ lines.push({
446
+ text: ` <HeadContent />`,
447
+ integrationId: "base"
448
+ });
449
+ lines.push({
450
+ text: ` </head>`,
451
+ integrationId: "base"
452
+ });
453
+ lines.push({
454
+ text: ` <body>`,
455
+ integrationId: "base"
456
+ });
457
+ let currentIndent = " ";
458
+ for (const provider of rootProviders) {
459
+ lines.push({
460
+ text: `${currentIndent}<${provider.jsName}>`,
461
+ integrationId: provider.integrationId
462
+ });
463
+ currentIndent += " ";
464
+ }
465
+ if (hasHeader) lines.push({
466
+ text: `${currentIndent}<Header />`,
467
+ integrationId: "base"
468
+ });
469
+ lines.push({
470
+ text: `${currentIndent}{children}`,
471
+ integrationId: "base"
472
+ });
473
+ lines.push({
474
+ text: `${currentIndent}<TanStackRouterDevtools />`,
475
+ integrationId: "base"
476
+ });
477
+ if (devtoolsPlugins.length > 0) {
478
+ lines.push({
479
+ text: `${currentIndent}{devtoolsPlugins.map((plugin, i) => (`,
480
+ integrationId: "base"
481
+ });
482
+ lines.push({
483
+ text: `${currentIndent} <React.Fragment key={i}>{plugin.render}</React.Fragment>`,
484
+ integrationId: "base"
485
+ });
486
+ lines.push({
487
+ text: `${currentIndent}))}`,
488
+ integrationId: "base"
489
+ });
490
+ }
491
+ for (const provider of [...rootProviders].reverse()) {
492
+ currentIndent = currentIndent.slice(0, -2);
493
+ lines.push({
494
+ text: `${currentIndent}</${provider.jsName}>`,
495
+ integrationId: provider.integrationId
496
+ });
497
+ }
498
+ lines.push({
499
+ text: ` <Scripts />`,
500
+ integrationId: "base"
501
+ });
502
+ lines.push({
503
+ text: ` </body>`,
504
+ integrationId: "base"
505
+ });
506
+ lines.push({
507
+ text: ` </html>`,
508
+ integrationId: "base"
509
+ });
510
+ lines.push({
511
+ text: ` )`,
512
+ integrationId: "base"
513
+ });
514
+ lines.push({
515
+ text: `}`,
516
+ integrationId: "base"
517
+ });
518
+ return {
519
+ content: lines.map((l) => l.text).join("\n"),
520
+ lineAttributions: lines.map((l, i) => ({
521
+ line: i + 1,
522
+ integrationId: l.integrationId
523
+ }))
524
+ };
525
+ }
526
+ /**
527
+ * Collect routes from integrations for navigation
528
+ */
529
+ function collectRoutes(options) {
530
+ const routes = [];
531
+ for (const integration of options.chosenIntegrations) if (integration.routes) {
532
+ for (const route of integration.routes) if (route.url && route.name) routes.push({
533
+ url: route.url,
534
+ name: route.name,
535
+ icon: route.icon || "Globe"
536
+ });
537
+ }
538
+ return routes;
539
+ }
540
+ /**
541
+ * Generate Header component with slide-out drawer navigation
542
+ */
543
+ function generateHeader(options) {
544
+ const lines = [];
545
+ const routes = collectRoutes(options);
546
+ const icons = new Set([
547
+ "Menu",
548
+ "X",
549
+ "Home"
550
+ ]);
551
+ for (const route of routes) icons.add(route.icon);
552
+ lines.push({
553
+ text: `import { useState } from 'react'`,
554
+ integrationId: "base"
555
+ });
556
+ lines.push({
557
+ text: `import { Link } from '@tanstack/react-router'`,
558
+ integrationId: "base"
559
+ });
560
+ lines.push({
561
+ text: `import { ${Array.from(icons).sort().join(", ")} } from 'lucide-react'`,
562
+ integrationId: "base"
563
+ });
564
+ lines.push({
565
+ text: "",
566
+ integrationId: "base"
567
+ });
568
+ lines.push({
569
+ text: `export function Header() {`,
570
+ integrationId: "base"
571
+ });
572
+ lines.push({
573
+ text: ` const [isOpen, setIsOpen] = useState(false)`,
574
+ integrationId: "base"
575
+ });
576
+ lines.push({
577
+ text: "",
578
+ integrationId: "base"
579
+ });
580
+ lines.push({
581
+ text: ` return (`,
582
+ integrationId: "base"
583
+ });
584
+ lines.push({
585
+ text: ` <>`,
586
+ integrationId: "base"
587
+ });
588
+ lines.push({
589
+ text: ` <header className="p-4 flex items-center bg-gray-800 text-white shadow-lg">`,
590
+ integrationId: "base"
591
+ });
592
+ lines.push({
593
+ text: ` <button`,
594
+ integrationId: "base"
595
+ });
596
+ lines.push({
597
+ text: ` onClick={() => setIsOpen(true)}`,
598
+ integrationId: "base"
599
+ });
600
+ lines.push({
601
+ text: ` className="p-2 hover:bg-gray-700 rounded-lg transition-colors"`,
602
+ integrationId: "base"
603
+ });
604
+ lines.push({
605
+ text: ` aria-label="Open menu"`,
606
+ integrationId: "base"
607
+ });
608
+ lines.push({
609
+ text: ` >`,
610
+ integrationId: "base"
611
+ });
612
+ lines.push({
613
+ text: ` <Menu size={24} />`,
614
+ integrationId: "base"
615
+ });
616
+ lines.push({
617
+ text: ` </button>`,
618
+ integrationId: "base"
619
+ });
620
+ lines.push({
621
+ text: ` <h1 className="ml-4 text-xl font-semibold">`,
622
+ integrationId: "base"
623
+ });
624
+ lines.push({
625
+ text: ` <Link to="/">`,
626
+ integrationId: "base"
627
+ });
628
+ lines.push({
629
+ text: ` <img`,
630
+ integrationId: "base"
631
+ });
632
+ lines.push({
633
+ text: ` src="/tanstack-logo-light.svg"`,
634
+ integrationId: "base"
635
+ });
636
+ lines.push({
637
+ text: ` alt="TanStack Logo"`,
638
+ integrationId: "base"
639
+ });
640
+ lines.push({
641
+ text: ` className="h-10"`,
642
+ integrationId: "base"
643
+ });
644
+ lines.push({
645
+ text: ` />`,
646
+ integrationId: "base"
647
+ });
648
+ lines.push({
649
+ text: ` </Link>`,
650
+ integrationId: "base"
651
+ });
652
+ lines.push({
653
+ text: ` </h1>`,
654
+ integrationId: "base"
655
+ });
656
+ lines.push({
657
+ text: ` </header>`,
658
+ integrationId: "base"
659
+ });
660
+ lines.push({
661
+ text: "",
662
+ integrationId: "base"
663
+ });
664
+ lines.push({
665
+ text: ` <aside`,
666
+ integrationId: "base"
667
+ });
668
+ lines.push({
669
+ text: ` className={\`fixed top-0 left-0 h-full w-80 bg-gray-900 text-white shadow-2xl z-50 transform transition-transform duration-300 ease-in-out flex flex-col \${`,
670
+ integrationId: "base"
671
+ });
672
+ lines.push({
673
+ text: ` isOpen ? 'translate-x-0' : '-translate-x-full'`,
674
+ integrationId: "base"
675
+ });
676
+ lines.push({
677
+ text: ` }\`}`,
678
+ integrationId: "base"
679
+ });
680
+ lines.push({
681
+ text: ` >`,
682
+ integrationId: "base"
683
+ });
684
+ lines.push({
685
+ text: ` <div className="flex items-center justify-between p-4 border-b border-gray-700">`,
686
+ integrationId: "base"
687
+ });
688
+ lines.push({
689
+ text: ` <h2 className="text-xl font-bold">Navigation</h2>`,
690
+ integrationId: "base"
691
+ });
692
+ lines.push({
693
+ text: ` <button`,
694
+ integrationId: "base"
695
+ });
696
+ lines.push({
697
+ text: ` onClick={() => setIsOpen(false)}`,
698
+ integrationId: "base"
699
+ });
700
+ lines.push({
701
+ text: ` className="p-2 hover:bg-gray-800 rounded-lg transition-colors"`,
702
+ integrationId: "base"
703
+ });
704
+ lines.push({
705
+ text: ` aria-label="Close menu"`,
706
+ integrationId: "base"
707
+ });
708
+ lines.push({
709
+ text: ` >`,
710
+ integrationId: "base"
711
+ });
712
+ lines.push({
713
+ text: ` <X size={24} />`,
714
+ integrationId: "base"
715
+ });
716
+ lines.push({
717
+ text: ` </button>`,
718
+ integrationId: "base"
719
+ });
720
+ lines.push({
721
+ text: ` </div>`,
722
+ integrationId: "base"
723
+ });
724
+ lines.push({
725
+ text: "",
726
+ integrationId: "base"
727
+ });
728
+ lines.push({
729
+ text: ` <nav className="flex-1 p-4 overflow-y-auto">`,
730
+ integrationId: "base"
731
+ });
732
+ lines.push({
733
+ text: ` <Link`,
734
+ integrationId: "base"
735
+ });
736
+ lines.push({
737
+ text: ` to="/"`,
738
+ integrationId: "base"
739
+ });
740
+ lines.push({
741
+ text: ` onClick={() => setIsOpen(false)}`,
742
+ integrationId: "base"
743
+ });
744
+ lines.push({
745
+ text: ` className="flex items-center gap-3 p-3 rounded-lg hover:bg-gray-800 transition-colors mb-2"`,
746
+ integrationId: "base"
747
+ });
748
+ lines.push({
749
+ text: ` activeProps={{`,
750
+ integrationId: "base"
751
+ });
752
+ lines.push({
753
+ text: ` className: 'flex items-center gap-3 p-3 rounded-lg bg-cyan-600 hover:bg-cyan-700 transition-colors mb-2',`,
754
+ integrationId: "base"
755
+ });
756
+ lines.push({
757
+ text: ` }}`,
758
+ integrationId: "base"
759
+ });
760
+ lines.push({
761
+ text: ` >`,
762
+ integrationId: "base"
763
+ });
764
+ lines.push({
765
+ text: ` <Home size={20} />`,
766
+ integrationId: "base"
767
+ });
768
+ lines.push({
769
+ text: ` <span className="font-medium">Home</span>`,
770
+ integrationId: "base"
771
+ });
772
+ lines.push({
773
+ text: ` </Link>`,
774
+ integrationId: "base"
775
+ });
776
+ for (const route of routes) {
777
+ const integrationId = options.chosenIntegrations.find((i) => i.routes?.some((r) => r.url === route.url))?.id || "base";
778
+ lines.push({
779
+ text: "",
780
+ integrationId
781
+ });
782
+ lines.push({
783
+ text: ` <Link`,
784
+ integrationId
785
+ });
786
+ lines.push({
787
+ text: ` to="${route.url}"`,
788
+ integrationId
789
+ });
790
+ lines.push({
791
+ text: ` onClick={() => setIsOpen(false)}`,
792
+ integrationId
793
+ });
794
+ lines.push({
795
+ text: ` className="flex items-center gap-3 p-3 rounded-lg hover:bg-gray-800 transition-colors mb-2"`,
796
+ integrationId
797
+ });
798
+ lines.push({
799
+ text: ` activeProps={{`,
800
+ integrationId
801
+ });
802
+ lines.push({
803
+ text: ` className: 'flex items-center gap-3 p-3 rounded-lg bg-cyan-600 hover:bg-cyan-700 transition-colors mb-2',`,
804
+ integrationId
805
+ });
806
+ lines.push({
807
+ text: ` }}`,
808
+ integrationId
809
+ });
810
+ lines.push({
811
+ text: ` >`,
812
+ integrationId
813
+ });
814
+ lines.push({
815
+ text: ` <${route.icon} size={20} />`,
816
+ integrationId
817
+ });
818
+ lines.push({
819
+ text: ` <span className="font-medium">${route.name}</span>`,
820
+ integrationId
821
+ });
822
+ lines.push({
823
+ text: ` </Link>`,
824
+ integrationId
825
+ });
826
+ }
827
+ lines.push({
828
+ text: ` </nav>`,
829
+ integrationId: "base"
830
+ });
831
+ lines.push({
832
+ text: ` </aside>`,
833
+ integrationId: "base"
834
+ });
835
+ lines.push({
836
+ text: "",
837
+ integrationId: "base"
838
+ });
839
+ lines.push({
840
+ text: ` {isOpen && (`,
841
+ integrationId: "base"
842
+ });
843
+ lines.push({
844
+ text: ` <div`,
845
+ integrationId: "base"
846
+ });
847
+ lines.push({
848
+ text: ` className="fixed inset-0 bg-black/50 z-40"`,
849
+ integrationId: "base"
850
+ });
851
+ lines.push({
852
+ text: ` onClick={() => setIsOpen(false)}`,
853
+ integrationId: "base"
854
+ });
855
+ lines.push({
856
+ text: ` />`,
857
+ integrationId: "base"
858
+ });
859
+ lines.push({
860
+ text: ` )}`,
861
+ integrationId: "base"
862
+ });
863
+ lines.push({
864
+ text: ` </>`,
865
+ integrationId: "base"
866
+ });
867
+ lines.push({
868
+ text: ` )`,
869
+ integrationId: "base"
870
+ });
871
+ lines.push({
872
+ text: `}`,
873
+ integrationId: "base"
874
+ });
875
+ return {
876
+ content: lines.map((l) => l.text).join("\n"),
877
+ lineAttributions: lines.map((l, i) => ({
878
+ line: i + 1,
879
+ integrationId: l.integrationId
880
+ }))
881
+ };
882
+ }
883
+ /**
884
+ * Generate .gitignore content with line attribution
885
+ */
886
+ function generateGitignore(integrationPatterns) {
887
+ const lines = [];
888
+ lines.push({
889
+ text: "# Dependencies",
890
+ integrationId: "base"
891
+ });
892
+ lines.push({
893
+ text: "node_modules/",
894
+ integrationId: "base"
895
+ });
896
+ lines.push({
897
+ text: ".pnpm-store/",
898
+ integrationId: "base"
899
+ });
900
+ lines.push({
901
+ text: "",
902
+ integrationId: "base"
903
+ });
904
+ lines.push({
905
+ text: "# Build outputs",
906
+ integrationId: "base"
907
+ });
908
+ lines.push({
909
+ text: "dist/",
910
+ integrationId: "base"
911
+ });
912
+ lines.push({
913
+ text: ".output/",
914
+ integrationId: "base"
915
+ });
916
+ lines.push({
917
+ text: ".vinxi/",
918
+ integrationId: "base"
919
+ });
920
+ lines.push({
921
+ text: ".vercel/",
922
+ integrationId: "base"
923
+ });
924
+ lines.push({
925
+ text: ".netlify/",
926
+ integrationId: "base"
927
+ });
928
+ lines.push({
929
+ text: "",
930
+ integrationId: "base"
931
+ });
932
+ lines.push({
933
+ text: "# Environment",
934
+ integrationId: "base"
935
+ });
936
+ lines.push({
937
+ text: ".env",
938
+ integrationId: "base"
939
+ });
940
+ lines.push({
941
+ text: ".env.*",
942
+ integrationId: "base"
943
+ });
944
+ lines.push({
945
+ text: "!.env.example",
946
+ integrationId: "base"
947
+ });
948
+ lines.push({
949
+ text: "",
950
+ integrationId: "base"
951
+ });
952
+ lines.push({
953
+ text: "# IDE",
954
+ integrationId: "base"
955
+ });
956
+ lines.push({
957
+ text: ".idea/",
958
+ integrationId: "base"
959
+ });
960
+ lines.push({
961
+ text: ".vscode/",
962
+ integrationId: "base"
963
+ });
964
+ lines.push({
965
+ text: "*.swp",
966
+ integrationId: "base"
967
+ });
968
+ lines.push({
969
+ text: "*.swo",
970
+ integrationId: "base"
971
+ });
972
+ lines.push({
973
+ text: "",
974
+ integrationId: "base"
975
+ });
976
+ lines.push({
977
+ text: "# OS",
978
+ integrationId: "base"
979
+ });
980
+ lines.push({
981
+ text: ".DS_Store",
982
+ integrationId: "base"
983
+ });
984
+ lines.push({
985
+ text: "Thumbs.db",
986
+ integrationId: "base"
987
+ });
988
+ lines.push({
989
+ text: "",
990
+ integrationId: "base"
991
+ });
992
+ lines.push({
993
+ text: "# Logs",
994
+ integrationId: "base"
995
+ });
996
+ lines.push({
997
+ text: "*.log",
998
+ integrationId: "base"
999
+ });
1000
+ lines.push({
1001
+ text: "npm-debug.log*",
1002
+ integrationId: "base"
1003
+ });
1004
+ lines.push({
1005
+ text: "pnpm-debug.log*",
1006
+ integrationId: "base"
1007
+ });
1008
+ lines.push({
1009
+ text: "",
1010
+ integrationId: "base"
1011
+ });
1012
+ lines.push({
1013
+ text: "# Generated",
1014
+ integrationId: "base"
1015
+ });
1016
+ lines.push({
1017
+ text: "src/routeTree.gen.ts",
1018
+ integrationId: "base"
1019
+ });
1020
+ if (integrationPatterns.length > 0) {
1021
+ lines.push({
1022
+ text: "",
1023
+ integrationId: "base"
1024
+ });
1025
+ lines.push({
1026
+ text: "# Integration-specific",
1027
+ integrationId: "base"
1028
+ });
1029
+ for (const { pattern, integrationId } of integrationPatterns) lines.push({
1030
+ text: pattern,
1031
+ integrationId
1032
+ });
1033
+ }
1034
+ return {
1035
+ content: lines.map((l) => l.text).join("\n"),
1036
+ lineAttributions: lines.map((l, i) => ({
1037
+ line: i + 1,
1038
+ integrationId: l.integrationId
1039
+ }))
1040
+ };
1041
+ }
1042
+ /**
1043
+ * Get base template files (static files without hook injection)
1044
+ */
1045
+ function getBaseFiles(options) {
1046
+ const { projectName, typescript, tailwind, packageManager } = options;
1047
+ const files = {};
1048
+ const { vitePlugins, rootProviders, devtoolsPlugins, entryClientInits } = collectHooks(options);
1049
+ if (typescript) files["tsconfig.json"] = JSON.stringify({
1050
+ compilerOptions: {
1051
+ target: "ES2022",
1052
+ lib: [
1053
+ "ES2022",
1054
+ "DOM",
1055
+ "DOM.Iterable"
1056
+ ],
1057
+ module: "ESNext",
1058
+ skipLibCheck: true,
1059
+ moduleResolution: "bundler",
1060
+ allowImportingTsExtensions: true,
1061
+ resolveJsonModule: true,
1062
+ isolatedModules: true,
1063
+ moduleDetection: "force",
1064
+ noEmit: true,
1065
+ jsx: "react-jsx",
1066
+ strict: true,
1067
+ noUnusedLocals: true,
1068
+ noUnusedParameters: true,
1069
+ noFallthroughCasesInSwitch: true,
1070
+ noUncheckedIndexedAccess: true,
1071
+ paths: { "~/*": ["./src/*"] }
1072
+ },
1073
+ include: ["src"]
1074
+ }, null, 2);
1075
+ files[typescript ? "vite.config.ts" : "vite.config.js"] = generateViteConfig(options, vitePlugins).content;
1076
+ if (entryClientInits.length > 0) files[`src/entry-client.${typescript ? "tsx" : "jsx"}`] = generateEntryClient(options, entryClientInits).content;
1077
+ files[`src/router.${typescript ? "tsx" : "jsx"}`] = `import { createRouter as createTanStackRouter } from '@tanstack/react-router'
1078
+ import { routeTree } from './routeTree.gen'
1079
+
1080
+ export function getRouter() {
1081
+ const router = createTanStackRouter({
1082
+ routeTree,
1083
+ defaultPreload: 'intent',
1084
+ scrollRestoration: true,
1085
+ })
1086
+
1087
+ return router
1088
+ }
1089
+
1090
+ declare module '@tanstack/react-router' {
1091
+ interface Register {
1092
+ router: ReturnType<typeof getRouter>
1093
+ }
1094
+ }
1095
+ `;
1096
+ files[`src/routes/__root.${typescript ? "tsx" : "jsx"}`] = generateRootRoute(options, rootProviders, devtoolsPlugins).content;
1097
+ const hasHeader = options.chosenIntegrations.length > 0;
1098
+ if (hasHeader && tailwind) files[`src/components/Header.${typescript ? "tsx" : "jsx"}`] = generateHeader(options).content;
1099
+ const indexRouteWithHeader = `import { createFileRoute } from '@tanstack/react-router'
1100
+
1101
+ export const Route = createFileRoute('/')({
1102
+ component: Home,
1103
+ })
1104
+
1105
+ function Home() {
1106
+ return (
1107
+ <div className="min-h-[calc(100vh-72px)] bg-gradient-to-br from-gray-900 to-gray-800 flex items-center justify-center">
1108
+ <div className="text-center px-4">
1109
+ <img
1110
+ src="/tanstack-logo-dark.svg"
1111
+ alt="TanStack Logo"
1112
+ className="h-24 mx-auto mb-8"
1113
+ />
1114
+ <h1 className="text-5xl font-bold text-white mb-4">
1115
+ Welcome to TanStack Start
1116
+ </h1>
1117
+ <p className="text-xl text-gray-300 mb-8">
1118
+ Full-stack React framework powered by TanStack Router
1119
+ </p>
1120
+ <div className="flex gap-4 justify-center flex-wrap">
1121
+ <a
1122
+ href="https://tanstack.com/start"
1123
+ target="_blank"
1124
+ rel="noopener noreferrer"
1125
+ className="px-6 py-3 bg-cyan-500 text-white rounded-lg font-medium hover:bg-cyan-600 transition-colors"
1126
+ >
1127
+ Documentation
1128
+ </a>
1129
+ <a
1130
+ href="https://github.com/tanstack/router"
1131
+ target="_blank"
1132
+ rel="noopener noreferrer"
1133
+ className="px-6 py-3 bg-gray-700 text-white rounded-lg font-medium hover:bg-gray-600 transition-colors"
1134
+ >
1135
+ GitHub
1136
+ </a>
1137
+ </div>
1138
+ </div>
1139
+ </div>
1140
+ )
1141
+ }
1142
+ `;
1143
+ const indexRouteNoHeader = `import { createFileRoute } from '@tanstack/react-router'
1144
+
1145
+ export const Route = createFileRoute('/')({
1146
+ component: Home,
1147
+ })
1148
+
1149
+ function Home() {
1150
+ return (
1151
+ <div className="min-h-screen bg-gradient-to-br from-gray-900 to-gray-800 flex items-center justify-center">
1152
+ <div className="text-center px-4">
1153
+ <img
1154
+ src="/tanstack-logo-dark.svg"
1155
+ alt="TanStack Logo"
1156
+ className="h-24 mx-auto mb-8"
1157
+ />
1158
+ <h1 className="text-5xl font-bold text-white mb-4">
1159
+ Welcome to TanStack Start
1160
+ </h1>
1161
+ <p className="text-xl text-gray-300 mb-8">
1162
+ Full-stack React framework powered by TanStack Router
1163
+ </p>
1164
+ <div className="flex gap-4 justify-center flex-wrap">
1165
+ <a
1166
+ href="https://tanstack.com/start"
1167
+ target="_blank"
1168
+ rel="noopener noreferrer"
1169
+ className="px-6 py-3 bg-cyan-500 text-white rounded-lg font-medium hover:bg-cyan-600 transition-colors"
1170
+ >
1171
+ Documentation
1172
+ </a>
1173
+ <a
1174
+ href="https://github.com/tanstack/router"
1175
+ target="_blank"
1176
+ rel="noopener noreferrer"
1177
+ className="px-6 py-3 bg-gray-700 text-white rounded-lg font-medium hover:bg-gray-600 transition-colors"
1178
+ >
1179
+ GitHub
1180
+ </a>
1181
+ </div>
1182
+ </div>
1183
+ </div>
1184
+ )
1185
+ }
1186
+ `;
1187
+ const indexRouteNoTailwind = `import { createFileRoute } from '@tanstack/react-router'
1188
+
1189
+ export const Route = createFileRoute('/')({
1190
+ component: Home,
1191
+ })
1192
+
1193
+ function Home() {
1194
+ return (
1195
+ <div style={styles.container}>
1196
+ <div style={styles.content}>
1197
+ <img
1198
+ src="/tanstack-logo-dark.svg"
1199
+ alt="TanStack Logo"
1200
+ style={styles.logo}
1201
+ />
1202
+ <h1 style={styles.title}>Welcome to TanStack Start</h1>
1203
+ <p style={styles.subtitle}>
1204
+ Full-stack React framework powered by TanStack Router
1205
+ </p>
1206
+ <div style={styles.buttons}>
1207
+ <a
1208
+ href="https://tanstack.com/start"
1209
+ target="_blank"
1210
+ rel="noopener noreferrer"
1211
+ style={styles.primaryButton}
1212
+ >
1213
+ Documentation
1214
+ </a>
1215
+ <a
1216
+ href="https://github.com/tanstack/router"
1217
+ target="_blank"
1218
+ rel="noopener noreferrer"
1219
+ style={styles.secondaryButton}
1220
+ >
1221
+ GitHub
1222
+ </a>
1223
+ </div>
1224
+ </div>
1225
+ </div>
1226
+ )
1227
+ }
1228
+
1229
+ const styles = {
1230
+ container: {
1231
+ minHeight: '100vh',
1232
+ background: 'linear-gradient(to bottom right, #111827, #1f2937)',
1233
+ display: 'flex',
1234
+ alignItems: 'center',
1235
+ justifyContent: 'center',
1236
+ },
1237
+ content: {
1238
+ textAlign: 'center' as const,
1239
+ padding: '0 1rem',
1240
+ },
1241
+ logo: {
1242
+ height: '6rem',
1243
+ marginBottom: '2rem',
1244
+ },
1245
+ title: {
1246
+ fontSize: '3rem',
1247
+ fontWeight: 'bold',
1248
+ color: 'white',
1249
+ marginBottom: '1rem',
1250
+ },
1251
+ subtitle: {
1252
+ fontSize: '1.25rem',
1253
+ color: '#d1d5db',
1254
+ marginBottom: '2rem',
1255
+ },
1256
+ buttons: {
1257
+ display: 'flex',
1258
+ gap: '1rem',
1259
+ justifyContent: 'center',
1260
+ flexWrap: 'wrap' as const,
1261
+ },
1262
+ primaryButton: {
1263
+ padding: '0.75rem 1.5rem',
1264
+ backgroundColor: '#06b6d4',
1265
+ color: 'white',
1266
+ borderRadius: '0.5rem',
1267
+ fontWeight: 500,
1268
+ textDecoration: 'none',
1269
+ },
1270
+ secondaryButton: {
1271
+ padding: '0.75rem 1.5rem',
1272
+ backgroundColor: '#374151',
1273
+ color: 'white',
1274
+ borderRadius: '0.5rem',
1275
+ fontWeight: 500,
1276
+ textDecoration: 'none',
1277
+ },
1278
+ }
1279
+ `;
1280
+ if (tailwind) files[`src/routes/index.${typescript ? "tsx" : "jsx"}`] = hasHeader ? indexRouteWithHeader : indexRouteNoHeader;
1281
+ else files[`src/routes/index.${typescript ? "tsx" : "jsx"}`] = indexRouteNoTailwind;
1282
+ if (tailwind) files["src/styles.css"] = `@import 'tailwindcss';
1283
+
1284
+ body {
1285
+ @apply m-0;
1286
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
1287
+ 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
1288
+ sans-serif;
1289
+ -webkit-font-smoothing: antialiased;
1290
+ -moz-osx-font-smoothing: grayscale;
1291
+ }
1292
+
1293
+ code {
1294
+ font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
1295
+ monospace;
1296
+ }
1297
+ `;
1298
+ else files["src/styles.css"] = `* {
1299
+ box-sizing: border-box;
1300
+ margin: 0;
1301
+ padding: 0;
1302
+ }
1303
+
1304
+ body {
1305
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
1306
+ 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
1307
+ sans-serif;
1308
+ -webkit-font-smoothing: antialiased;
1309
+ -moz-osx-font-smoothing: grayscale;
1310
+ line-height: 1.5;
1311
+ }
1312
+
1313
+ code {
1314
+ font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
1315
+ monospace;
1316
+ }
1317
+ `;
1318
+ files["public/tanstack-logo-light.svg"] = `<svg height="660" viewBox="0 0 663 660" width="663" xmlns="http://www.w3.org/2000/svg"><path d="m305.114318.62443771c8.717817-1.14462121 17.926803-.36545135 26.712694-.36545135 32.548987 0 64.505987 5.05339923 95.64868 14.63098274 39.74418 12.2236582 76.762804 31.7666864 109.435876 57.477568 40.046637 31.5132839 73.228974 72.8472109 94.520714 119.2362609 39.836383 86.790386 39.544267 191.973146-1.268422 278.398081-26.388695 55.880442-68.724007 102.650458-119.964986 136.75724-41.808813 27.828603-90.706831 44.862601-140.45707 50.89341-63.325458 7.677926-131.784923-3.541603-188.712259-32.729444-106.868873-54.795293-179.52309291-165.076271-180.9604082-285.932068-.27660564-23.300971.08616998-46.74071 4.69884909-69.814998 7.51316071-37.57857 20.61272131-73.903917 40.28618971-106.877282 21.2814003-35.670293 48.7704861-67.1473767 81.6882804-92.5255597 38.602429-29.7610135 83.467691-51.1674988 130.978372-62.05777669 11.473831-2.62966514 22.9946-4.0869914 34.57273-5.4964306l3.658171-.44480576c3.050084-.37153079 6.104217-.74794222 9.162589-1.14972654zm-110.555861 549.44131429c-14.716752 1.577863-30.238964 4.25635-42.869928 12.522173 2.84343.683658 6.102369.004954 9.068638 0 7.124652-.011559 14.317732-.279903 21.434964.032202 17.817402.781913 36.381729 3.63214 53.58741 8.350042 22.029372 6.040631 41.432961 17.928687 62.656049 25.945156 22.389644 8.456554 44.67706 11.084675 68.427 11.084675 11.96813 0 23.845573-.035504 35.450133-3.302696-6.056202-3.225083-14.72582-2.619864-21.434964-3.963236-14.556814-2.915455-28.868774-6.474936-42.869928-11.470264-10.304996-3.676672-20.230803-8.214291-30.11097-12.848661l-6.348531-2.985046c-9.1705-4.309263-18.363277-8.560752-27.845391-12.142608-24.932161-9.418465-52.560181-14.071964-79.144482-11.221737zm22.259385-62.614168c-29.163917 0-58.660076 5.137344-84.915434 18.369597-6.361238 3.206092-12.407546 7.02566-18.137277 11.258891-1.746125 1.290529-4.841829 2.948483-5.487351 5.191839-.654591 2.275558 1.685942 4.182039 3.014086 5.637703 6.562396-3.497556 12.797498-7.199878 19.78612-9.855246 45.19892-17.169893 99.992458-13.570779 145.098218 2.172348 22.494346 7.851335 43.219483 19.592421 65.129314 28.800338 24.503461 10.297807 49.53043 16.975034 75.846795 20.399104 31.04195 4.037546 66.433549.7654 94.808495-13.242161 9.970556-4.921843 23.814245-12.422267 28.030337-23.320339-5.207047.454947-9.892236 2.685918-14.83959 4.224149-7.866632 2.445646-15.827248 4.51974-23.908229 6.138887-27.388113 5.486604-56.512458 6.619429-84.091013 1.639788-25.991939-4.693152-50.142596-14.119246-74.179513-24.03502l-3.068058-1.268177c-2.045137-.846788-4.089983-1.695816-6.135603-2.544467l-3.069142-1.272366c-12.279956-5.085721-24.606928-10.110797-37.210937-14.51024-24.485325-8.546552-50.726667-13.784628-76.671218-13.784628zm51.114145-447.9909432c-34.959602 7.7225298-66.276908 22.7605319-96.457338 41.7180089-17.521434 11.0054099-34.281927 22.2799893-49.465301 36.4444283-22.5792616 21.065423-39.8360564 46.668751-54.8866988 73.411509-15.507372 27.55357-25.4498976 59.665686-30.2554517 90.824149-4.7140432 30.568106-5.4906485 62.70747-.0906864 93.301172 6.7503648 38.248526 19.5989769 74.140579 39.8896436 107.337631 6.8187918-3.184625 11.659796-10.445603 17.3128555-15.336896 11.4149428-9.875888 23.3995608-19.029311 36.2745548-26.928535 4.765981-2.923712 9.662222-5.194315 14.83959-7.275014 1.953055-.785216 5.14604-1.502727 6.06527-3.647828 1.460876-3.406732-1.240754-9.335897-1.704904-12.865654-1.324845-10.095517-2.124534-20.362774-1.874735-30.549941.725492-29.668947 6.269727-59.751557 16.825623-87.521453 7.954845-20.924233 20.10682-39.922168 34.502872-56.971512 4.884699-5.785498 10.077731-11.170545 15.437296-16.512656 3.167428-3.157378 7.098271-5.858983 9.068639-9.908915-10.336599.006606-20.674847 2.987289-30.503603 6.013385-21.174447 6.519522-41.801477 16.19312-59.358362 29.841512-8.008432 6.226409-13.873368 14.387371-21.44733 20.939921-2.32322 2.010516-6.484901 4.704691-9.695199 3.187928-4.8500728-2.29042-4.1014979-11.835213-4.6571581-16.222019-2.1369011-16.873476 4.2548401-38.216325 12.3778671-52.843142 13.039878-23.479694 37.150915-43.528712 65.467327-42.82854 12.228647.302197 22.934587 4.551115 34.625711 7.324555-2.964621-4.211764-6.939158-7.28162-10.717482-10.733763-9.257431-8.459031-19.382979-16.184864-30.503603-22.028985-4.474136-2.350694-9.291232-3.77911-14.015169-5.506421-2.375159-.867783-5.36616-2.062533-6.259834-4.702213-1.654614-4.888817 7.148561-9.416813 10.381943-11.478522 12.499882-7.969406 27.826705-14.525258 42.869928-14.894334 23.509209-.577147 46.479246 12.467678 56.162903 34.665926 3.404469 7.803171 4.411273 16.054969 5.079109 24.382907l.121749 1.56229.174325 2.345587c.01913.260708.038244.521433.057403.782164l.11601 1.56437.120128 1.563971c7.38352-6.019164 12.576553-14.876995 19.78612-21.323859 16.861073-15.07846 39.936636-21.7722 61.831627-14.984333 19.786945 6.133107 36.984382 19.788105 47.105807 37.959541 2.648042 4.754231 10.035685 16.373942 4.698379 21.109183-4.177345 3.707277-9.475079.818243-13.880788-.719162-3.33605-1.16376-6.782939-1.90214-10.241828-2.585698l-1.887262-.369639c-.629089-.122886-1.257979-.246187-1.886079-.372129-11.980496-2.401886-25.91652-2.152533-37.923398-.041284-7.762754 1.364839-15.349083 4.127545-23.083807 5.271929v1.651348c21.149714.175043 41.608563 12.240618 52.043268 30.549941 4.323267 7.585468 6.482428 16.267431 8.138691 24.770223 2.047864 10.50918.608423 21.958802-2.263037 32.201289-.962925 3.433979-2.710699 9.255807-6.817143 10.046802-2.902789.558982-5.36781-2.330878-7.024898-4.279468-4.343878-5.10762-8.475879-9.96341-13.573278-14.374161-12.895604-11.157333-26.530715-21.449361-40.396663-31.373138-7.362086-5.269452-15.425755-12.12007-23.908229-15.340199 2.385052 5.745041 4.721463 11.086326 5.532694 17.339156 2.385876 18.392716-5.314223 35.704625-16.87179 49.540445-3.526876 4.222498-7.29943 8.475545-11.744712 11.755948-1.843407 1.360711-4.156734 3.137561-6.595373 2.752797-7.645687-1.207961-8.555849-12.73272-9.728176-18.637115-3.970415-19.998652-2.375984-39.861068 3.132802-59.448534-4.901187 2.485279-8.443727 7.923994-11.521293 12.385111-6.770975 9.816439-12.645804 20.199291-16.858599 31.375615-16.777806 44.519521-16.616219 96.664142 5.118834 139.523233 2.427098 4.786433 6.110614 4.144058 10.894733 4.144058.720854 0 1.44257-.004515 2.164851-.010924l2.168232-.022283c4.338648-.045438 8.686803-.064635 12.979772.508795 2.227588.297243 5.320818.032202 7.084256 1.673642 2.111344 1.966755.986008 5.338808.4996 7.758859-1.358647 6.765574-1.812904 12.914369-1.812904 19.816178 9.02412-1.398692 11.525415-15.866153 14.724172-23.118874 3.624982-8.216283 7.313444-16.440823 10.667192-24.770223 1.648843-4.093692 3.854171-8.671229 3.275427-13.210785-.649644-5.10184-4.335633-10.510831-6.904531-14.862134-4.86244-8.234447-10.389363-16.70834-13.969002-25.595896-2.861567-7.104926-.197036-15.983399 7.871579-18.521521 4.450228-1.400344 9.198073 1.345848 12.094266 4.562675 6.07269 6.74328 9.992815 16.777697 14.401823 24.692609l34.394873 61.925556c2.920926 5.243856 5.848447 10.481933 8.836976 15.687808 1.165732 2.031158 2.352075 5.167068 4.740424 6.0332 2.127008.77118 5.033095-.325315 7.148561-.748886 5.492297-1.099798 10.97635-2.287117 16.488434-3.28288 6.605266-1.193099 16.673928-.969342 21.434964-6.129805-6.963066-2.205375-15.011895-2.074919-22.259386-1.577863-4.352947.298894-9.178287 1.856116-13.178381-.686135-5.953149-3.783239-9.910373-12.522173-13.552668-18.377854-8.980425-14.439388-17.441465-29.095929-26.041008-43.760726l-1.376261-2.335014-2.765943-4.665258c-1.380597-2.334387-2.750786-4.67476-4.079753-7.036188-1.02723-1.826391-2.549937-4.233231-1.078344-6.24705 1.545791-2.114476 4.91472-2.239146 7.956473-2.243117l.603351.000261c1.195428.001526 2.315572.002427 3.222811-.11692 12.27399-1.615019 24.718635-2.952611 37.098976-2.952611-.963749-3.352237-3.719791-7.141255-2.838484-10.73046 1.972017-8.030506 13.526287-10.543033 18.899867-4.780653 3.60767 3.868283 5.704174 9.192229 8.051303 13.859765 3.097352 6.162006 6.624228 12.118418 9.940876 18.16483 5.805578 10.585967 12.146205 20.881297 18.116667 31.375615.49237.865561.999687 1.726685 1.512269 2.587098l.771613 1.290552c2.577138 4.303168 5.164895 8.635123 6.553094 13.461506-20.735854-.9487-36.30176-25.018751-45.343193-41.283704-.721369 2.604176.450959 4.928448 1.388326 7.431066 1.948109 5.197619 4.276275 10.147535 7.20627 14.862134 4.184765 6.732546 8.982075 13.665732 15.313633 18.553722 11.236043 8.673707 26.05255 8.721596 39.572241 7.794364 8.669619-.595311 19.50252-4.542034 28.030338-1.864372 8.513803 2.673532 11.940924 12.063098 6.884745 19.276187-3.787393 5.403211-8.842747 7.443452-15.128962 8.257566 4.445282 9.53571 10.268996 18.385285 14.490036 28.072919 1.758491 4.035895 3.59118 10.22102 7.8048 12.350433 2.805507 1.416857 6.824562.09743 9.85761.034678-3.043765-8.053625-8.742992-14.887729-11.541904-23.118874 8.533589.390544 16.786875 4.843404 24.732651 7.685374 15.630376 5.590144 31.063836 11.701854 46.475333 17.86913l7.112077 2.848685c6.338978 2.538947 12.71588 5.052299 18.961699 7.812528 2.285297 1.009799 5.449427 3.370401 7.975455 1.917215 2.061054-1.186494 3.394144-4.015253 4.665403-5.931643 3.55573-5.361927 6.775921-10.928622 9.965609-16.513481 12.774414-22.36586 22.143967-46.872692 28.402976-71.833646 20.645168-82.323009 2.934117-173.156241-46.677107-241.922507-19.061454-26.420745-43.033164-49.262193-69.46165-68.1783861-66.13923-47.336721-152.911262-66.294198-232.486917-48.7172481zm135.205158 410.5292842c-17.532977 4.570931-35.601827 8.714164-53.58741 11.040088 2.365265 8.052799 8.145286 15.885969 12.376218 23.118874 1.635653 2.796558 3.3859 6.541816 6.618457 7.755557 3.651364 1.370619 8.063669-.853747 11.508927-1.975838-1.595256-4.364513-4.279573-8.292245-6.476657-12.385112-.905215-1.687677-2.305907-3.685809-1.559805-5.68972 1.410585-3.786541 7.266452-3.563609 10.509727-4.221671 8.54678-1.733916 17.004522-3.898008 25.557073-5.611281 3.150939-.631641 7.538512-2.342438 10.705115-1.285575 2.371037.791232 3.800147 2.744743 5.152304 4.781948l.606196.918752c.80912 1.222827 1.637246 2.41754 2.671212 3.351165 3.457625 3.121874 8.628398 3.60159 13.017619 4.453686-2.678546-6.027421-7.130424-11.301001-9.984571-17.339156-1.659561-3.511592-3.023155-8.677834-6.656381-10.707341-5.005064-2.795733-15.341663 2.461334-20.458024 3.795624zm-110.472507-40.151706c-.825246 10.467897-4.036369 18.984725-9.068639 28.072919 5.76683.729896 11.649079.989984 17.312856 2.39363 4.244947 1.051908 8.156828 3.058296 12.366325 4.211763-2.250671-6.157877-6.426367-11.651913-9.661398-17.339156-3.266358-5.740912-6.189758-12.717032-10.949144-17.339156z" fill="#fff" transform="translate(.9778)"/></svg>`;
1319
+ files["public/tanstack-logo-dark.svg"] = `<svg height="660" viewBox="0 0 663 660" width="663" xmlns="http://www.w3.org/2000/svg"><path d="m305.114318.62443771c8.717817-1.14462121 17.926803-.36545135 26.712694-.36545135 32.548987 0 64.505987 5.05339923 95.64868 14.63098274 39.74418 12.2236582 76.762804 31.7666864 109.435876 57.477568 40.046637 31.5132839 73.228974 72.8472109 94.520714 119.2362609 39.836383 86.790386 39.544267 191.973146-1.268422 278.398081-26.388695 55.880442-68.724007 102.650458-119.964986 136.75724-41.808813 27.828603-90.706831 44.862601-140.45707 50.89341-63.325458 7.677926-131.784923-3.541603-188.712259-32.729444-106.868873-54.795293-179.52309291-165.076271-180.9604082-285.932068-.27660564-23.300971.08616998-46.74071 4.69884909-69.814998 7.51316071-37.57857 20.61272131-73.903917 40.28618971-106.877282 21.2814003-35.670293 48.7704861-67.1473767 81.6882804-92.5255597 38.602429-29.7610135 83.467691-51.1674988 130.978372-62.05777669 11.473831-2.62966514 22.9946-4.0869914 34.57273-5.4964306l3.658171-.44480576c3.050084-.37153079 6.104217-.74794222 9.162589-1.14972654zm-110.555861 549.44131429c-14.716752 1.577863-30.238964 4.25635-42.869928 12.522173 2.84343.683658 6.102369.004954 9.068638 0 7.124652-.011559 14.317732-.279903 21.434964.032202 17.817402.781913 36.381729 3.63214 53.58741 8.350042 22.029372 6.040631 41.432961 17.928687 62.656049 25.945156 22.389644 8.456554 44.67706 11.084675 68.427 11.084675 11.96813 0 23.845573-.035504 35.450133-3.302696-6.056202-3.225083-14.72582-2.619864-21.434964-3.963236-14.556814-2.915455-28.868774-6.474936-42.869928-11.470264-10.304996-3.676672-20.230803-8.214291-30.11097-12.848661l-6.348531-2.985046c-9.1705-4.309263-18.363277-8.560752-27.845391-12.142608-24.932161-9.418465-52.560181-14.071964-79.144482-11.221737zm22.259385-62.614168c-29.163917 0-58.660076 5.137344-84.915434 18.369597-6.361238 3.206092-12.407546 7.02566-18.137277 11.258891-1.746125 1.290529-4.841829 2.948483-5.487351 5.191839-.654591 2.275558 1.685942 4.182039 3.014086 5.637703 6.562396-3.497556 12.797498-7.199878 19.78612-9.855246 45.19892-17.169893 99.992458-13.570779 145.098218 2.172348 22.494346 7.851335 43.219483 19.592421 65.129314 28.800338 24.503461 10.297807 49.53043 16.975034 75.846795 20.399104 31.04195 4.037546 66.433549.7654 94.808495-13.242161 9.970556-4.921843 23.814245-12.422267 28.030337-23.320339-5.207047.454947-9.892236 2.685918-14.83959 4.224149-7.866632 2.445646-15.827248 4.51974-23.908229 6.138887-27.388113 5.486604-56.512458 6.619429-84.091013 1.639788-25.991939-4.693152-50.142596-14.119246-74.179513-24.03502l-3.068058-1.268177c-2.045137-.846788-4.089983-1.695816-6.135603-2.544467l-3.069142-1.272366c-12.279956-5.085721-24.606928-10.110797-37.210937-14.51024-24.485325-8.546552-50.726667-13.784628-76.671218-13.784628zm51.114145-447.9909432c-34.959602 7.7225298-66.276908 22.7605319-96.457338 41.7180089-17.521434 11.0054099-34.281927 22.2799893-49.465301 36.4444283-22.5792616 21.065423-39.8360564 46.668751-54.8866988 73.411509-15.507372 27.55357-25.4498976 59.665686-30.2554517 90.824149-4.7140432 30.568106-5.4906485 62.70747-.0906864 93.301172 6.7503648 38.248526 19.5989769 74.140579 39.8896436 107.337631 6.8187918-3.184625 11.659796-10.445603 17.3128555-15.336896 11.4149428-9.875888 23.3995608-19.029311 36.2745548-26.928535 4.765981-2.923712 9.662222-5.194315 14.83959-7.275014 1.953055-.785216 5.14604-1.502727 6.06527-3.647828 1.460876-3.406732-1.240754-9.335897-1.704904-12.865654-1.324845-10.095517-2.124534-20.362774-1.874735-30.549941.725492-29.668947 6.269727-59.751557 16.825623-87.521453 7.954845-20.924233 20.10682-39.922168 34.502872-56.971512 4.884699-5.785498 10.077731-11.170545 15.437296-16.512656 3.167428-3.157378 7.098271-5.858983 9.068639-9.908915-10.336599.006606-20.674847 2.987289-30.503603 6.013385-21.174447 6.519522-41.801477 16.19312-59.358362 29.841512-8.008432 6.226409-13.873368 14.387371-21.44733 20.939921-2.32322 2.010516-6.484901 4.704691-9.695199 3.187928-4.8500728-2.29042-4.1014979-11.835213-4.6571581-16.222019-2.1369011-16.873476 4.2548401-38.216325 12.3778671-52.843142 13.039878-23.479694 37.150915-43.528712 65.467327-42.82854 12.228647.302197 22.934587 4.551115 34.625711 7.324555-2.964621-4.211764-6.939158-7.28162-10.717482-10.733763-9.257431-8.459031-19.382979-16.184864-30.503603-22.028985-4.474136-2.350694-9.291232-3.77911-14.015169-5.506421-2.375159-.867783-5.36616-2.062533-6.259834-4.702213-1.654614-4.888817 7.148561-9.416813 10.381943-11.478522 12.499882-7.969406 27.826705-14.525258 42.869928-14.894334 23.509209-.577147 46.479246 12.467678 56.162903 34.665926 3.404469 7.803171 4.411273 16.054969 5.079109 24.382907l.121749 1.56229.174325 2.345587c.01913.260708.038244.521433.057403.782164l.11601 1.56437.120128 1.563971c7.38352-6.019164 12.576553-14.876995 19.78612-21.323859 16.861073-15.07846 39.936636-21.7722 61.831627-14.984333 19.786945 6.133107 36.984382 19.788105 47.105807 37.959541 2.648042 4.754231 10.035685 16.373942 4.698379 21.109183-4.177345 3.707277-9.475079.818243-13.880788-.719162-3.33605-1.16376-6.782939-1.90214-10.241828-2.585698l-1.887262-.369639c-.629089-.122886-1.257979-.246187-1.886079-.372129-11.980496-2.401886-25.91652-2.152533-37.923398-.041284-7.762754 1.364839-15.349083 4.127545-23.083807 5.271929v1.651348c21.149714.175043 41.608563 12.240618 52.043268 30.549941 4.323267 7.585468 6.482428 16.267431 8.138691 24.770223 2.047864 10.50918.608423 21.958802-2.263037 32.201289-.962925 3.433979-2.710699 9.255807-6.817143 10.046802-2.902789.558982-5.36781-2.330878-7.024898-4.279468-4.343878-5.10762-8.475879-9.96341-13.573278-14.374161-12.895604-11.157333-26.530715-21.449361-40.396663-31.373138-7.362086-5.269452-15.425755-12.12007-23.908229-15.340199 2.385052 5.745041 4.721463 11.086326 5.532694 17.339156 2.385876 18.392716-5.314223 35.704625-16.87179 49.540445-3.526876 4.222498-7.29943 8.475545-11.744712 11.755948-1.843407 1.360711-4.156734 3.137561-6.595373 2.752797-7.645687-1.207961-8.555849-12.73272-9.728176-18.637115-3.970415-19.998652-2.375984-39.861068 3.132802-59.448534-4.901187 2.485279-8.443727 7.923994-11.521293 12.385111-6.770975 9.816439-12.645804 20.199291-16.858599 31.375615-16.777806 44.519521-16.616219 96.664142 5.118834 139.523233 2.427098 4.786433 6.110614 4.144058 10.894733 4.144058.720854 0 1.44257-.004515 2.164851-.010924l2.168232-.022283c4.338648-.045438 8.686803-.064635 12.979772.508795 2.227588.297243 5.320818.032202 7.084256 1.673642 2.111344 1.966755.986008 5.338808.4996 7.758859-1.358647 6.765574-1.812904 12.914369-1.812904 19.816178 9.02412-1.398692 11.525415-15.866153 14.724172-23.118874 3.624982-8.216283 7.313444-16.440823 10.667192-24.770223 1.648843-4.093692 3.854171-8.671229 3.275427-13.210785-.649644-5.10184-4.335633-10.510831-6.904531-14.862134-4.86244-8.234447-10.389363-16.70834-13.969002-25.595896-2.861567-7.104926-.197036-15.983399 7.871579-18.521521 4.450228-1.400344 9.198073 1.345848 12.094266 4.562675 6.07269 6.74328 9.992815 16.777697 14.401823 24.692609l34.394873 61.925556c2.920926 5.243856 5.848447 10.481933 8.836976 15.687808 1.165732 2.031158 2.352075 5.167068 4.740424 6.0332 2.127008.77118 5.033095-.325315 7.148561-.748886 5.492297-1.099798 10.97635-2.287117 16.488434-3.28288 6.605266-1.193099 16.673928-.969342 21.434964-6.129805-6.963066-2.205375-15.011895-2.074919-22.259386-1.577863-4.352947.298894-9.178287 1.856116-13.178381-.686135-5.953149-3.783239-9.910373-12.522173-13.552668-18.377854-8.980425-14.439388-17.441465-29.095929-26.041008-43.760726l-1.376261-2.335014-2.765943-4.665258c-1.380597-2.334387-2.750786-4.67476-4.079753-7.036188-1.02723-1.826391-2.549937-4.233231-1.078344-6.24705 1.545791-2.114476 4.91472-2.239146 7.956473-2.243117l.603351.000261c1.195428.001526 2.315572.002427 3.222811-.11692 12.27399-1.615019 24.718635-2.952611 37.098976-2.952611-.963749-3.352237-3.719791-7.141255-2.838484-10.73046 1.972017-8.030506 13.526287-10.543033 18.899867-4.780653 3.60767 3.868283 5.704174 9.192229 8.051303 13.859765 3.097352 6.162006 6.624228 12.118418 9.940876 18.16483 5.805578 10.585967 12.146205 20.881297 18.116667 31.375615.49237.865561.999687 1.726685 1.512269 2.587098l.771613 1.290552c2.577138 4.303168 5.164895 8.635123 6.553094 13.461506-20.735854-.9487-36.30176-25.018751-45.343193-41.283704-.721369 2.604176.450959 4.928448 1.388326 7.431066 1.948109 5.197619 4.276275 10.147535 7.20627 14.862134 4.184765 6.732546 8.982075 13.665732 15.313633 18.553722 11.236043 8.673707 26.05255 8.721596 39.572241 7.794364 8.669619-.595311 19.50252-4.542034 28.030338-1.864372 8.513803 2.673532 11.940924 12.063098 6.884745 19.276187-3.787393 5.403211-8.842747 7.443452-15.128962 8.257566 4.445282 9.53571 10.268996 18.385285 14.490036 28.072919 1.758491 4.035895 3.59118 10.22102 7.8048 12.350433 2.805507 1.416857 6.824562.09743 9.85761.034678-3.043765-8.053625-8.742992-14.887729-11.541904-23.118874 8.533589.390544 16.786875 4.843404 24.732651 7.685374 15.630376 5.590144 31.063836 11.701854 46.475333 17.86913l7.112077 2.848685c6.338978 2.538947 12.71588 5.052299 18.961699 7.812528 2.285297 1.009799 5.449427 3.370401 7.975455 1.917215 2.061054-1.186494 3.394144-4.015253 4.665403-5.931643 3.55573-5.361927 6.775921-10.928622 9.965609-16.513481 12.774414-22.36586 22.143967-46.872692 28.402976-71.833646 20.645168-82.323009 2.934117-173.156241-46.677107-241.922507-19.061454-26.420745-43.033164-49.262193-69.46165-68.1783861-66.13923-47.336721-152.911262-66.294198-232.486917-48.7172481zm135.205158 410.5292842c-17.532977 4.570931-35.601827 8.714164-53.58741 11.040088 2.365265 8.052799 8.145286 15.885969 12.376218 23.118874 1.635653 2.796558 3.3859 6.541816 6.618457 7.755557 3.651364 1.370619 8.063669-.853747 11.508927-1.975838-1.595256-4.364513-4.279573-8.292245-6.476657-12.385112-.905215-1.687677-2.305907-3.685809-1.559805-5.68972 1.410585-3.786541 7.266452-3.563609 10.509727-4.221671 8.54678-1.733916 17.004522-3.898008 25.557073-5.611281 3.150939-.631641 7.538512-2.342438 10.705115-1.285575 2.371037.791232 3.800147 2.744743 5.152304 4.781948l.606196.918752c.80912 1.222827 1.637246 2.41754 2.671212 3.351165 3.457625 3.121874 8.628398 3.60159 13.017619 4.453686-2.678546-6.027421-7.130424-11.301001-9.984571-17.339156-1.659561-3.511592-3.023155-8.677834-6.656381-10.707341-5.005064-2.795733-15.341663 2.461334-20.458024 3.795624zm-110.472507-40.151706c-.825246 10.467897-4.036369 18.984725-9.068639 28.072919 5.76683.729896 11.649079.989984 17.312856 2.39363 4.244947 1.051908 8.156828 3.058296 12.366325 4.211763-2.250671-6.157877-6.426367-11.651913-9.661398-17.339156-3.266358-5.740912-6.189758-12.717032-10.949144-17.339156z" fill="#1f2937" transform="translate(.9778)"/></svg>`;
1320
+ const gitignorePatterns = [];
1321
+ for (const integration of options.chosenIntegrations) if (integration.gitignorePatterns) for (const pattern of integration.gitignorePatterns) gitignorePatterns.push({
1322
+ pattern,
1323
+ integrationId: integration.id
1324
+ });
1325
+ files[".gitignore"] = generateGitignore(gitignorePatterns).content;
1326
+ files[".env.example"] = `# Add your environment variables here
1327
+ # Copy this file to .env.local and fill in your values
1328
+
1329
+ # Example:
1330
+ # DATABASE_URL=postgresql://user:password@localhost:5432/db
1331
+ `;
1332
+ files["README.md"] = `# ${projectName}
1333
+
1334
+ A full-stack React application built with [TanStack Start](https://tanstack.com/start).
1335
+
1336
+ ## Getting Started
1337
+
1338
+ \`\`\`bash
1339
+ # Install dependencies
1340
+ ${packageManager} install
1341
+
1342
+ # Start development server
1343
+ ${packageManager}${packageManager === "npm" ? " run" : ""} dev
1344
+ \`\`\`
1345
+
1346
+ ## Scripts
1347
+
1348
+ - \`dev\` - Start development server
1349
+ - \`build\` - Build for production
1350
+ - \`start\` - Start production server
1351
+
1352
+ ## Learn More
1353
+
1354
+ - [TanStack Start Documentation](https://tanstack.com/start)
1355
+ - [TanStack Router Documentation](https://tanstack.com/router)
1356
+ `;
1357
+ return files;
1358
+ }
1359
+ /**
1360
+ * Get base files WITH line-by-line attribution for files that have hooks
1361
+ */
1362
+ function getBaseFilesWithAttribution(options) {
1363
+ const { typescript } = options;
1364
+ const files = getBaseFiles(options);
1365
+ const attributions = {};
1366
+ const { vitePlugins, rootProviders, devtoolsPlugins, entryClientInits } = collectHooks(options);
1367
+ attributions[typescript ? "vite.config.ts" : "vite.config.js"] = generateViteConfig(options, vitePlugins).lineAttributions;
1368
+ if (entryClientInits.length > 0) attributions[`src/entry-client.${typescript ? "tsx" : "jsx"}`] = generateEntryClient(options, entryClientInits).lineAttributions;
1369
+ attributions[`src/routes/__root.${typescript ? "tsx" : "jsx"}`] = generateRootRoute(options, rootProviders, devtoolsPlugins).lineAttributions;
1370
+ const gitignorePatterns = [];
1371
+ for (const integration of options.chosenIntegrations) if (integration.gitignorePatterns) for (const pattern of integration.gitignorePatterns) gitignorePatterns.push({
1372
+ pattern,
1373
+ integrationId: integration.id
1374
+ });
1375
+ attributions[".gitignore"] = generateGitignore(gitignorePatterns).lineAttributions;
1376
+ return {
1377
+ files,
1378
+ attributions
1379
+ };
1380
+ }
1381
+
1382
+ //#endregion
1383
+ //#region src/engine/compile.ts
1384
+ /**
1385
+ * Merge package contributions from integrations
1386
+ */
1387
+ function mergePackages(target, source) {
1388
+ if (!source) return;
1389
+ if (source.dependencies) target.dependencies = {
1390
+ ...target.dependencies,
1391
+ ...source.dependencies
1392
+ };
1393
+ if (source.devDependencies) target.devDependencies = {
1394
+ ...target.devDependencies,
1395
+ ...source.devDependencies
1396
+ };
1397
+ if (source.scripts) target.scripts = {
1398
+ ...target.scripts,
1399
+ ...source.scripts
1400
+ };
1401
+ }
1402
+ function mergePackagesWithAttribution(target, source, integrationId, attribution) {
1403
+ if (!source) return;
1404
+ if (source.dependencies) {
1405
+ for (const pkg of Object.keys(source.dependencies)) attribution.dependencies.set(pkg, integrationId);
1406
+ target.dependencies = {
1407
+ ...target.dependencies,
1408
+ ...source.dependencies
1409
+ };
1410
+ }
1411
+ if (source.devDependencies) {
1412
+ for (const pkg of Object.keys(source.devDependencies)) attribution.devDependencies.set(pkg, integrationId);
1413
+ target.devDependencies = {
1414
+ ...target.devDependencies,
1415
+ ...source.devDependencies
1416
+ };
1417
+ }
1418
+ if (source.scripts) {
1419
+ for (const script of Object.keys(source.scripts)) attribution.scripts.set(script, integrationId);
1420
+ target.scripts = {
1421
+ ...target.scripts,
1422
+ ...source.scripts
1423
+ };
1424
+ }
1425
+ }
1426
+ /**
1427
+ * Process all files from an integration
1428
+ */
1429
+ function processIntegrationFiles(integration, options, files, appendFiles) {
1430
+ for (const [filePath, content] of Object.entries(integration.files)) {
1431
+ const processed = processTemplateFile(filePath, content, options);
1432
+ if (!processed) continue;
1433
+ if (processed.append) {
1434
+ if (!appendFiles.has(processed.path)) appendFiles.set(processed.path, []);
1435
+ appendFiles.get(processed.path).push({
1436
+ content: processed.content,
1437
+ integrationId: integration.id
1438
+ });
1439
+ } else files.set(processed.path, {
1440
+ content: processed.content,
1441
+ integrationId: integration.id
1442
+ });
1443
+ }
1444
+ }
1445
+ /**
1446
+ * Build the package.json content
1447
+ */
1448
+ function buildPackageJson(options, packages) {
1449
+ const hasHeader = options.chosenIntegrations.length > 0 && options.tailwind;
1450
+ const pkg = {
1451
+ name: options.projectName,
1452
+ private: true,
1453
+ type: "module",
1454
+ scripts: {
1455
+ dev: "vite dev --port 3000",
1456
+ build: "vite build",
1457
+ start: "node .output/server/index.mjs",
1458
+ ...packages.scripts
1459
+ },
1460
+ dependencies: {
1461
+ "@tanstack/react-router": "^1.132.0",
1462
+ "@tanstack/react-router-devtools": "^1.132.0",
1463
+ "@tanstack/react-start": "^1.132.0",
1464
+ react: "^19.0.0",
1465
+ "react-dom": "^19.0.0",
1466
+ "vite-tsconfig-paths": "^5.1.4",
1467
+ ...hasHeader ? { "lucide-react": "^0.468.0" } : {},
1468
+ ...packages.dependencies
1469
+ },
1470
+ devDependencies: {
1471
+ "@vitejs/plugin-react": "^4.4.1",
1472
+ vite: "^7.0.0",
1473
+ ...options.typescript ? {
1474
+ "@types/react": "^19.0.0",
1475
+ "@types/react-dom": "^19.0.0",
1476
+ typescript: "^5.7.0"
1477
+ } : {},
1478
+ ...options.tailwind ? {
1479
+ "@tailwindcss/vite": "^4.0.0",
1480
+ tailwindcss: "^4.0.0"
1481
+ } : {},
1482
+ ...packages.devDependencies
1483
+ }
1484
+ };
1485
+ return JSON.stringify(pkg, null, 2);
1486
+ }
1487
+ /**
1488
+ * Compile a project from options
1489
+ */
1490
+ function compile(options) {
1491
+ const files = /* @__PURE__ */ new Map();
1492
+ const appendFiles = /* @__PURE__ */ new Map();
1493
+ const packages = {
1494
+ dependencies: {},
1495
+ devDependencies: {},
1496
+ scripts: {}
1497
+ };
1498
+ const envVars = [];
1499
+ const warnings = [];
1500
+ const baseFiles = getBaseFiles(options);
1501
+ for (const [path, content] of Object.entries(baseFiles)) files.set(path, {
1502
+ content,
1503
+ integrationId: "base"
1504
+ });
1505
+ const sortedIntegrations = [...options.chosenIntegrations].sort((a, b) => {
1506
+ const phaseOrder = {
1507
+ setup: 0,
1508
+ integration: 1,
1509
+ example: 2
1510
+ };
1511
+ const phaseA = phaseOrder[a.phase];
1512
+ const phaseB = phaseOrder[b.phase];
1513
+ if (phaseA !== phaseB) return phaseA - phaseB;
1514
+ return (a.priority ?? 100) - (b.priority ?? 100);
1515
+ });
1516
+ for (const integration of sortedIntegrations) {
1517
+ processIntegrationFiles(integration, options, files, appendFiles);
1518
+ mergePackages(packages, integration.packageAdditions);
1519
+ if (integration.envVars) envVars.push(...integration.envVars);
1520
+ if (integration.warning) warnings.push(`${integration.name}: ${integration.warning}`);
1521
+ }
1522
+ for (const [path, appends] of appendFiles) {
1523
+ const existing = files.get(path);
1524
+ if (existing) {
1525
+ const appendContent = appends.map((a) => a.content).join("\n");
1526
+ existing.content = existing.content + "\n" + appendContent;
1527
+ } else files.set(path, {
1528
+ content: appends.map((a) => a.content).join("\n"),
1529
+ integrationId: appends[0]?.integrationId ?? "base"
1530
+ });
1531
+ }
1532
+ const outputFiles = {};
1533
+ for (const [path, { content }] of files) outputFiles[path] = content;
1534
+ outputFiles["package.json"] = buildPackageJson(options, packages);
1535
+ const seenEnvVars = /* @__PURE__ */ new Set();
1536
+ return {
1537
+ files: outputFiles,
1538
+ packages,
1539
+ envVars: envVars.filter((v) => {
1540
+ if (seenEnvVars.has(v.name)) return false;
1541
+ seenEnvVars.add(v.name);
1542
+ return true;
1543
+ }),
1544
+ warnings
1545
+ };
1546
+ }
1547
+ /**
1548
+ * Compile with line-by-line attribution tracking
1549
+ */
1550
+ function compileWithAttribution(options) {
1551
+ const files = /* @__PURE__ */ new Map();
1552
+ const appendFiles = /* @__PURE__ */ new Map();
1553
+ const packages = {
1554
+ dependencies: {},
1555
+ devDependencies: {},
1556
+ scripts: {}
1557
+ };
1558
+ const packageAttribution = {
1559
+ dependencies: /* @__PURE__ */ new Map(),
1560
+ devDependencies: /* @__PURE__ */ new Map(),
1561
+ scripts: /* @__PURE__ */ new Map()
1562
+ };
1563
+ const envVars = [];
1564
+ const warnings = [];
1565
+ const fileOwnership = /* @__PURE__ */ new Map();
1566
+ const { files: baseFiles, attributions: baseAttributions } = getBaseFilesWithAttribution(options);
1567
+ for (const [path, content] of Object.entries(baseFiles)) {
1568
+ files.set(path, {
1569
+ content,
1570
+ integrationId: "base"
1571
+ });
1572
+ fileOwnership.set(path, "base");
1573
+ }
1574
+ const hookAttributions = /* @__PURE__ */ new Map();
1575
+ for (const [path, attrs] of Object.entries(baseAttributions)) hookAttributions.set(path, attrs);
1576
+ const sortedIntegrations = [...options.chosenIntegrations].sort((a, b) => {
1577
+ const phaseOrder = {
1578
+ setup: 0,
1579
+ integration: 1,
1580
+ example: 2
1581
+ };
1582
+ const phaseA = phaseOrder[a.phase];
1583
+ const phaseB = phaseOrder[b.phase];
1584
+ if (phaseA !== phaseB) return phaseA - phaseB;
1585
+ return (a.priority ?? 100) - (b.priority ?? 100);
1586
+ });
1587
+ const integrationNames = /* @__PURE__ */ new Map();
1588
+ integrationNames.set("base", "Base Template");
1589
+ if (options.customTemplate) integrationNames.set(options.customTemplate.id, options.customTemplate.name);
1590
+ for (const integration of sortedIntegrations) integrationNames.set(integration.id, integration.name);
1591
+ for (const integration of sortedIntegrations) {
1592
+ for (const [filePath, content] of Object.entries(integration.files)) {
1593
+ const processed = processTemplateFile(filePath, content, options);
1594
+ if (!processed) continue;
1595
+ if (processed.append) {
1596
+ if (!appendFiles.has(processed.path)) appendFiles.set(processed.path, []);
1597
+ appendFiles.get(processed.path).push({
1598
+ content: processed.content,
1599
+ integrationId: integration.id
1600
+ });
1601
+ } else {
1602
+ files.set(processed.path, {
1603
+ content: processed.content,
1604
+ integrationId: integration.id
1605
+ });
1606
+ fileOwnership.set(processed.path, integration.id);
1607
+ }
1608
+ }
1609
+ mergePackagesWithAttribution(packages, integration.packageAdditions, integration.id, packageAttribution);
1610
+ if (integration.envVars) for (const envVar of integration.envVars) envVars.push({
1611
+ ...envVar,
1612
+ integrationId: integration.id
1613
+ });
1614
+ if (integration.warning) warnings.push(`${integration.name}: ${integration.warning}`);
1615
+ }
1616
+ const appendOwnership = /* @__PURE__ */ new Map();
1617
+ for (const [path, appends] of appendFiles) {
1618
+ const existing = files.get(path);
1619
+ if (existing) {
1620
+ const existingLines = existing.content.split("\n").length;
1621
+ const lineMap = /* @__PURE__ */ new Map();
1622
+ let currentLine = existingLines + 1;
1623
+ for (const append of appends) {
1624
+ const appendLines = append.content.split("\n").length;
1625
+ for (let i = 0; i < appendLines; i++) lineMap.set(currentLine + i, append.integrationId);
1626
+ currentLine += appendLines + 1;
1627
+ }
1628
+ appendOwnership.set(path, lineMap);
1629
+ const appendContent = appends.map((a) => a.content).join("\n");
1630
+ existing.content = existing.content + "\n" + appendContent;
1631
+ } else {
1632
+ files.set(path, {
1633
+ content: appends.map((a) => a.content).join("\n"),
1634
+ integrationId: appends[0]?.integrationId ?? "base"
1635
+ });
1636
+ fileOwnership.set(path, appends[0]?.integrationId ?? "base");
1637
+ }
1638
+ }
1639
+ const outputFiles = {};
1640
+ const attributedFiles = {};
1641
+ for (const [path, { content, integrationId }] of files) {
1642
+ outputFiles[path] = content;
1643
+ const lines = content.split("\n");
1644
+ const attributions = [];
1645
+ const appendLineMap = appendOwnership.get(path);
1646
+ const hookAttrMap = hookAttributions.get(path);
1647
+ for (let i = 0; i < lines.length; i++) {
1648
+ const lineNumber = i + 1;
1649
+ let owningIntegrationId = integrationId;
1650
+ const appendIntegrationId = appendLineMap?.get(lineNumber);
1651
+ const hookAttr = hookAttrMap?.find((a) => a.line === lineNumber);
1652
+ if (appendIntegrationId) owningIntegrationId = appendIntegrationId;
1653
+ else if (hookAttr) owningIntegrationId = hookAttr.integrationId;
1654
+ attributions.push({
1655
+ lineNumber,
1656
+ featureId: owningIntegrationId,
1657
+ featureName: integrationNames.get(owningIntegrationId) || owningIntegrationId
1658
+ });
1659
+ }
1660
+ attributedFiles[path] = {
1661
+ path,
1662
+ content,
1663
+ attributions
1664
+ };
1665
+ }
1666
+ outputFiles["package.json"] = buildPackageJson(options, packages);
1667
+ const pkgJsonLines = outputFiles["package.json"].split("\n");
1668
+ const pkgJsonAttributions = [];
1669
+ for (let i = 0; i < pkgJsonLines.length; i++) {
1670
+ const line = pkgJsonLines[i];
1671
+ const lineNumber = i + 1;
1672
+ let integrationId = "base";
1673
+ const match = line.match(/^\s*"([^"]+)":\s*"[^"]+"/);
1674
+ if (match) {
1675
+ const pkgName = match[1];
1676
+ const depIntegration = packageAttribution.dependencies.get(pkgName);
1677
+ const devDepIntegration = packageAttribution.devDependencies.get(pkgName);
1678
+ const scriptIntegration = packageAttribution.scripts.get(pkgName);
1679
+ if (depIntegration) integrationId = depIntegration;
1680
+ else if (devDepIntegration) integrationId = devDepIntegration;
1681
+ else if (scriptIntegration) integrationId = scriptIntegration;
1682
+ }
1683
+ pkgJsonAttributions.push({
1684
+ lineNumber,
1685
+ featureId: integrationId,
1686
+ featureName: integrationNames.get(integrationId) || integrationId
1687
+ });
1688
+ }
1689
+ attributedFiles["package.json"] = {
1690
+ path: "package.json",
1691
+ content: outputFiles["package.json"],
1692
+ attributions: pkgJsonAttributions
1693
+ };
1694
+ const seenEnvVars = /* @__PURE__ */ new Set();
1695
+ const uniqueEnvVars = envVars.filter((v) => {
1696
+ if (seenEnvVars.has(v.name)) return false;
1697
+ seenEnvVars.add(v.name);
1698
+ return true;
1699
+ });
1700
+ if (uniqueEnvVars.length > 0) {
1701
+ const envLines = [];
1702
+ envLines.push({
1703
+ text: "# Environment Variables",
1704
+ integrationId: "base"
1705
+ });
1706
+ envLines.push({
1707
+ text: "# Copy this file to .env.local and fill in your values",
1708
+ integrationId: "base"
1709
+ });
1710
+ envLines.push({
1711
+ text: "",
1712
+ integrationId: "base"
1713
+ });
1714
+ const envByIntegration = /* @__PURE__ */ new Map();
1715
+ for (const envVar of uniqueEnvVars) {
1716
+ const id = envVar.integrationId;
1717
+ if (!envByIntegration.has(id)) envByIntegration.set(id, []);
1718
+ envByIntegration.get(id).push(envVar);
1719
+ }
1720
+ for (const [integrationId, vars] of envByIntegration) {
1721
+ const integrationName = integrationNames.get(integrationId) || integrationId;
1722
+ envLines.push({
1723
+ text: `# ${integrationName}`,
1724
+ integrationId
1725
+ });
1726
+ for (const v of vars) {
1727
+ envLines.push({
1728
+ text: `# ${v.description}${v.required ? " (required)" : ""}`,
1729
+ integrationId
1730
+ });
1731
+ envLines.push({
1732
+ text: `${v.name}=${v.example || ""}`,
1733
+ integrationId
1734
+ });
1735
+ }
1736
+ envLines.push({
1737
+ text: "",
1738
+ integrationId: "base"
1739
+ });
1740
+ }
1741
+ const envContent = envLines.map((l) => l.text).join("\n");
1742
+ outputFiles[".env.example"] = envContent;
1743
+ attributedFiles[".env.example"] = {
1744
+ path: ".env.example",
1745
+ content: envContent,
1746
+ attributions: envLines.map((l, i) => ({
1747
+ lineNumber: i + 1,
1748
+ featureId: l.integrationId,
1749
+ featureName: integrationNames.get(l.integrationId) || l.integrationId
1750
+ }))
1751
+ };
1752
+ }
1753
+ return {
1754
+ files: outputFiles,
1755
+ packages,
1756
+ envVars: uniqueEnvVars.map(({ integrationId, ...rest }) => rest),
1757
+ warnings,
1758
+ attributedFiles
1759
+ };
1760
+ }
1761
+
1762
+ //#endregion
1763
+ //#region src/engine/config-file.ts
1764
+ const CONFIG_FILE = ".tanstack.json";
1765
+ function createPersistedOptions(options) {
1766
+ return {
1767
+ version: 1,
1768
+ projectName: options.projectName,
1769
+ framework: options.framework,
1770
+ mode: options.mode,
1771
+ typescript: options.typescript,
1772
+ tailwind: options.tailwind,
1773
+ packageManager: options.packageManager,
1774
+ chosenIntegrations: options.chosenIntegrations.map((integration) => integration.id),
1775
+ customTemplate: options.customTemplate?.id
1776
+ };
1777
+ }
1778
+ async function writeConfigFile(targetDir, options) {
1779
+ await writeFile(resolve(targetDir, CONFIG_FILE), JSON.stringify(createPersistedOptions(options), null, 2));
1780
+ }
1781
+ async function readConfigFile(targetDir) {
1782
+ const configPath = resolve(targetDir, CONFIG_FILE);
1783
+ if (!existsSync(configPath)) return null;
1784
+ try {
1785
+ const content = await readFile(configPath, "utf-8");
1786
+ return JSON.parse(content);
1787
+ } catch {
1788
+ return null;
1789
+ }
1790
+ }
1791
+
1792
+ //#endregion
1793
+ //#region src/engine/types.ts
1794
+ const CategorySchema = z.enum([
1795
+ "tanstack",
1796
+ "database",
1797
+ "orm",
1798
+ "auth",
1799
+ "deploy",
1800
+ "tooling",
1801
+ "monitoring",
1802
+ "api",
1803
+ "i18n",
1804
+ "cms",
1805
+ "other"
1806
+ ]);
1807
+ const IntegrationTypeSchema = z.enum([
1808
+ "integration",
1809
+ "example",
1810
+ "toolchain",
1811
+ "deployment"
1812
+ ]);
1813
+ const IntegrationPhaseSchema = z.enum([
1814
+ "setup",
1815
+ "integration",
1816
+ "example"
1817
+ ]);
1818
+ const RouterModeSchema = z.enum(["file-router", "code-router"]);
1819
+ const SelectOptionSchema = z.object({
1820
+ type: z.literal("select"),
1821
+ label: z.string(),
1822
+ description: z.string().optional(),
1823
+ default: z.string(),
1824
+ options: z.array(z.object({
1825
+ value: z.string(),
1826
+ label: z.string()
1827
+ }))
1828
+ });
1829
+ const BooleanOptionSchema = z.object({
1830
+ type: z.literal("boolean"),
1831
+ label: z.string(),
1832
+ description: z.string().optional(),
1833
+ default: z.boolean()
1834
+ });
1835
+ const StringOptionSchema = z.object({
1836
+ type: z.literal("string"),
1837
+ label: z.string(),
1838
+ description: z.string().optional(),
1839
+ default: z.string()
1840
+ });
1841
+ const IntegrationOptionSchema = z.discriminatedUnion("type", [
1842
+ SelectOptionSchema,
1843
+ BooleanOptionSchema,
1844
+ StringOptionSchema
1845
+ ]);
1846
+ const IntegrationOptionsSchema = z.record(z.string(), IntegrationOptionSchema);
1847
+ const HookTypeSchema = z.enum([
1848
+ "header-user",
1849
+ "provider",
1850
+ "root-provider",
1851
+ "layout",
1852
+ "vite-plugin",
1853
+ "devtools",
1854
+ "entry-client"
1855
+ ]);
1856
+ const HookSchema = z.object({
1857
+ type: HookTypeSchema.optional(),
1858
+ path: z.string().optional(),
1859
+ jsName: z.string().optional(),
1860
+ import: z.string().optional(),
1861
+ code: z.string().optional()
1862
+ });
1863
+ const RouteSchema = z.object({
1864
+ url: z.string().optional(),
1865
+ name: z.string().optional(),
1866
+ icon: z.string().optional(),
1867
+ path: z.string(),
1868
+ jsName: z.string(),
1869
+ children: z.array(z.lazy(() => RouteSchema)).optional()
1870
+ });
1871
+ const EnvVarSchema = z.object({
1872
+ name: z.string(),
1873
+ description: z.string(),
1874
+ required: z.boolean().optional(),
1875
+ example: z.string().optional()
1876
+ });
1877
+ const CommandSchema = z.object({
1878
+ command: z.string(),
1879
+ args: z.array(z.string()).optional()
1880
+ });
1881
+ const IntegrationInfoSchema = z.object({
1882
+ id: z.string().optional(),
1883
+ name: z.string(),
1884
+ description: z.string(),
1885
+ author: z.string().optional(),
1886
+ version: z.string().optional(),
1887
+ link: z.string().optional(),
1888
+ license: z.string().optional(),
1889
+ warning: z.string().optional(),
1890
+ type: IntegrationTypeSchema,
1891
+ phase: IntegrationPhaseSchema,
1892
+ category: CategorySchema.optional(),
1893
+ modes: z.array(RouterModeSchema),
1894
+ priority: z.number().optional(),
1895
+ default: z.boolean().optional(),
1896
+ requiresTailwind: z.boolean().optional(),
1897
+ demoRequiresTailwind: z.boolean().optional(),
1898
+ dependsOn: z.array(z.string()).optional(),
1899
+ conflicts: z.array(z.string()).optional(),
1900
+ partnerId: z.string().optional(),
1901
+ options: IntegrationOptionsSchema.optional(),
1902
+ hooks: z.array(HookSchema).optional(),
1903
+ routes: z.array(RouteSchema).optional(),
1904
+ packageAdditions: z.object({
1905
+ dependencies: z.record(z.string(), z.string()).optional(),
1906
+ devDependencies: z.record(z.string(), z.string()).optional(),
1907
+ scripts: z.record(z.string(), z.string()).optional()
1908
+ }).optional(),
1909
+ shadcnComponents: z.array(z.string()).optional(),
1910
+ gitignorePatterns: z.array(z.string()).optional(),
1911
+ envVars: z.array(EnvVarSchema).optional(),
1912
+ command: CommandSchema.optional(),
1913
+ integrationSpecialSteps: z.array(z.string()).optional(),
1914
+ createSpecialSteps: z.array(z.string()).optional(),
1915
+ postInitSpecialSteps: z.array(z.string()).optional(),
1916
+ smallLogo: z.string().optional(),
1917
+ logo: z.string().optional(),
1918
+ readme: z.string().optional()
1919
+ });
1920
+ const IntegrationCompiledSchema = IntegrationInfoSchema.extend({
1921
+ id: z.string(),
1922
+ files: z.record(z.string(), z.string()),
1923
+ deletedFiles: z.array(z.string()).optional()
1924
+ });
1925
+ const CustomTemplateInfoSchema = z.object({
1926
+ id: z.string().optional(),
1927
+ name: z.string(),
1928
+ description: z.string(),
1929
+ framework: z.string(),
1930
+ mode: RouterModeSchema,
1931
+ typescript: z.boolean(),
1932
+ tailwind: z.boolean(),
1933
+ integrations: z.array(z.string()),
1934
+ integrationOptions: z.record(z.string(), z.record(z.string(), z.unknown())).optional(),
1935
+ banner: z.string().optional()
1936
+ });
1937
+ const CustomTemplateCompiledSchema = CustomTemplateInfoSchema.extend({ id: z.string() });
1938
+ const ManifestIntegrationSchema = z.object({
1939
+ id: z.string(),
1940
+ name: z.string(),
1941
+ description: z.string(),
1942
+ type: IntegrationTypeSchema,
1943
+ category: CategorySchema.optional(),
1944
+ modes: z.array(RouterModeSchema),
1945
+ dependsOn: z.array(z.string()).optional(),
1946
+ conflicts: z.array(z.string()).optional(),
1947
+ partnerId: z.string().optional(),
1948
+ hasOptions: z.boolean().optional(),
1949
+ link: z.string().optional(),
1950
+ color: z.string().optional(),
1951
+ requiresTailwind: z.boolean().optional(),
1952
+ demoRequiresTailwind: z.boolean().optional()
1953
+ });
1954
+ const ManifestCustomTemplateSchema = z.object({
1955
+ id: z.string(),
1956
+ name: z.string(),
1957
+ description: z.string(),
1958
+ banner: z.string().optional(),
1959
+ icon: z.string().optional(),
1960
+ features: z.array(z.string()).optional()
1961
+ });
1962
+ const ManifestSchema = z.object({
1963
+ version: z.string(),
1964
+ generated: z.string(),
1965
+ integrations: z.array(ManifestIntegrationSchema),
1966
+ customTemplates: z.array(ManifestCustomTemplateSchema).optional()
1967
+ });
1968
+
1969
+ //#endregion
1970
+ //#region src/api/fetch.ts
1971
+ const GITHUB_RAW_BASE = "https://raw.githubusercontent.com/TanStack/cli/main/integrations";
1972
+ /**
1973
+ * Check if a path is a local directory
1974
+ */
1975
+ function isLocalPath(path) {
1976
+ return path.startsWith("/") || path.startsWith("./") || path.startsWith("..");
1977
+ }
1978
+ /**
1979
+ * Fetch the integration manifest from GitHub or local path
1980
+ */
1981
+ async function fetchManifest(baseUrl = GITHUB_RAW_BASE) {
1982
+ if (isLocalPath(baseUrl)) {
1983
+ const manifestPath = join(baseUrl, "manifest.json");
1984
+ if (!existsSync(manifestPath)) throw new Error(`Manifest not found at ${manifestPath}`);
1985
+ const data$1 = JSON.parse(readFileSync(manifestPath, "utf-8"));
1986
+ return ManifestSchema.parse(data$1);
1987
+ }
1988
+ const url = `${baseUrl}/manifest.json`;
1989
+ const response = await fetch(url);
1990
+ if (!response.ok) throw new Error(`Failed to fetch manifest: ${response.statusText}`);
1991
+ const data = await response.json();
1992
+ return ManifestSchema.parse(data);
1993
+ }
1994
+ /**
1995
+ * Fetch integration info.json from GitHub or local path
1996
+ */
1997
+ async function fetchIntegrationInfo(integrationId, baseUrl = GITHUB_RAW_BASE) {
1998
+ if (isLocalPath(baseUrl)) {
1999
+ const infoPath = join(baseUrl, integrationId, "info.json");
2000
+ if (!existsSync(infoPath)) throw new Error(`Integration info not found at ${infoPath}`);
2001
+ const data$1 = JSON.parse(readFileSync(infoPath, "utf-8"));
2002
+ return IntegrationInfoSchema.parse(data$1);
2003
+ }
2004
+ const url = `${baseUrl}/${integrationId}/info.json`;
2005
+ const response = await fetch(url);
2006
+ if (!response.ok) throw new Error(`Failed to fetch integration ${integrationId}: ${response.statusText}`);
2007
+ const data = await response.json();
2008
+ return IntegrationInfoSchema.parse(data);
2009
+ }
2010
+ /**
2011
+ * Recursively read all files from a directory
2012
+ */
2013
+ function readDirRecursive(dir, basePath = "") {
2014
+ const files = {};
2015
+ if (!existsSync(dir)) return files;
2016
+ for (const entry of readdirSync(dir)) {
2017
+ const fullPath = join(dir, entry);
2018
+ const relativePath$1 = basePath ? `${basePath}/${entry}` : entry;
2019
+ if (statSync(fullPath).isDirectory()) Object.assign(files, readDirRecursive(fullPath, relativePath$1));
2020
+ else files[relativePath$1] = readFileSync(fullPath, "utf-8");
2021
+ }
2022
+ return files;
2023
+ }
2024
+ /**
2025
+ * Fetch all files for an integration from GitHub or local path
2026
+ */
2027
+ async function fetchIntegrationFiles(integrationId, baseUrl = GITHUB_RAW_BASE) {
2028
+ if (isLocalPath(baseUrl)) return readDirRecursive(join(baseUrl, integrationId, "assets"));
2029
+ const filesUrl = `${baseUrl}/${integrationId}/files.json`;
2030
+ const response = await fetch(filesUrl);
2031
+ if (!response.ok) return {};
2032
+ const fileList = await response.json();
2033
+ const files = {};
2034
+ await Promise.all(fileList.map(async (filePath) => {
2035
+ const fileUrl = `${baseUrl}/${integrationId}/assets/${filePath}`;
2036
+ const fileResponse = await fetch(fileUrl);
2037
+ if (fileResponse.ok) files[filePath] = await fileResponse.text();
2038
+ }));
2039
+ return files;
2040
+ }
2041
+ /**
2042
+ * Fetch integration package.json if it exists
2043
+ */
2044
+ async function fetchIntegrationPackageJson(integrationId, baseUrl) {
2045
+ if (isLocalPath(baseUrl)) {
2046
+ const pkgPath = join(baseUrl, integrationId, "package.json");
2047
+ if (existsSync(pkgPath)) return JSON.parse(readFileSync(pkgPath, "utf-8"));
2048
+ return null;
2049
+ }
2050
+ const url = `${baseUrl}/${integrationId}/package.json`;
2051
+ const response = await fetch(url);
2052
+ if (!response.ok) return null;
2053
+ return response.json();
2054
+ }
2055
+ /**
2056
+ * Fetch a complete compiled integration from GitHub
2057
+ */
2058
+ async function fetchIntegration(integrationId, baseUrl = GITHUB_RAW_BASE) {
2059
+ const [info, files, pkgJson] = await Promise.all([
2060
+ fetchIntegrationInfo(integrationId, baseUrl),
2061
+ fetchIntegrationFiles(integrationId, baseUrl),
2062
+ fetchIntegrationPackageJson(integrationId, baseUrl)
2063
+ ]);
2064
+ const packageAdditions = info.packageAdditions ?? {};
2065
+ if (pkgJson) {
2066
+ if (pkgJson.dependencies) packageAdditions.dependencies = {
2067
+ ...packageAdditions.dependencies,
2068
+ ...pkgJson.dependencies
2069
+ };
2070
+ if (pkgJson.devDependencies) packageAdditions.devDependencies = {
2071
+ ...packageAdditions.devDependencies,
2072
+ ...pkgJson.devDependencies
2073
+ };
2074
+ if (pkgJson.scripts) packageAdditions.scripts = {
2075
+ ...packageAdditions.scripts,
2076
+ ...pkgJson.scripts
2077
+ };
2078
+ }
2079
+ return IntegrationCompiledSchema.parse({
2080
+ ...info,
2081
+ id: integrationId,
2082
+ files,
2083
+ packageAdditions: Object.keys(packageAdditions).length > 0 ? packageAdditions : void 0,
2084
+ deletedFiles: []
2085
+ });
2086
+ }
2087
+ /**
2088
+ * Fetch multiple integrations in parallel
2089
+ */
2090
+ async function fetchIntegrations(integrationIds, baseUrl = GITHUB_RAW_BASE) {
2091
+ return Promise.all(integrationIds.map((id) => fetchIntegration(id, baseUrl)));
2092
+ }
2093
+
2094
+ //#endregion
2095
+ //#region src/engine/custom-addons/shared.ts
2096
+ /**
2097
+ * Shared utilities for custom integration/template creation
2098
+ * Based on Jack's implementation in create-tsrouter-app
2099
+ */
2100
+ const IGNORE_FILES = [
2101
+ ".template",
2102
+ ".integration",
2103
+ ".tanstack.json",
2104
+ ".git",
2105
+ "integration-info.json",
2106
+ "integration.json",
2107
+ "build",
2108
+ "bun.lock",
2109
+ "bun.lockb",
2110
+ "deno.lock",
2111
+ "dist",
2112
+ "node_modules",
2113
+ "package-lock.json",
2114
+ "pnpm-lock.yaml",
2115
+ "template.json",
2116
+ "template-info.json",
2117
+ "yarn.lock"
2118
+ ];
2119
+ const PROJECT_FILES = ["package.json"];
2120
+ const BINARY_EXTENSIONS = [
2121
+ ".png",
2122
+ ".jpg",
2123
+ ".jpeg",
2124
+ ".gif",
2125
+ ".svg",
2126
+ ".ico"
2127
+ ];
2128
+ /**
2129
+ * Check if a file is binary based on extension
2130
+ */
2131
+ function isBinaryFile(path) {
2132
+ return BINARY_EXTENSIONS.includes(extname(path));
2133
+ }
2134
+ /**
2135
+ * Read file contents, handling binary files with base64 encoding
2136
+ */
2137
+ function readFileHelper(path) {
2138
+ if (isBinaryFile(path)) return `base64::${readFileSync(path).toString("base64")}`;
2139
+ return readFileSync(path, "utf-8");
2140
+ }
2141
+ /**
2142
+ * Create an ignore function that respects .gitignore and standard ignore patterns
2143
+ * Ported from Jack's createIgnore in file-helpers.ts
2144
+ */
2145
+ function createIgnore(path, includeProjectFiles = true) {
2146
+ const gitignorePath = resolve(path, ".gitignore");
2147
+ const ignoreList = existsSync(gitignorePath) ? parseGitignore(readFileSync(gitignorePath)).patterns : [];
2148
+ const ig = ignore().add(ignoreList);
2149
+ return (filePath) => {
2150
+ const fileName = basename(filePath);
2151
+ if (IGNORE_FILES.includes(fileName) || includeProjectFiles && PROJECT_FILES.includes(fileName)) return true;
2152
+ const nameWithoutDotSlash = fileName.replace(/^\.\//, "");
2153
+ return ig.ignores(nameWithoutDotSlash);
2154
+ };
2155
+ }
2156
+ /**
2157
+ * Create package.json additions by comparing original and current
2158
+ * Ported from Jack's createPackageAdditions
2159
+ */
2160
+ function createPackageAdditions(originalPackageJson, currentPackageJson) {
2161
+ const packageAdditions = {};
2162
+ const origScripts = originalPackageJson.scripts || {};
2163
+ const currScripts = currentPackageJson.scripts || {};
2164
+ const scripts = {};
2165
+ for (const script of Object.keys(currScripts)) {
2166
+ const currValue = currScripts[script];
2167
+ if (currValue && origScripts[script] !== currValue) scripts[script] = currValue;
2168
+ }
2169
+ if (Object.keys(scripts).length) packageAdditions.scripts = scripts;
2170
+ const origDeps = originalPackageJson.dependencies || {};
2171
+ const currDeps = currentPackageJson.dependencies || {};
2172
+ const dependencies = {};
2173
+ for (const dep of Object.keys(currDeps)) {
2174
+ const currValue = currDeps[dep];
2175
+ if (currValue && origDeps[dep] !== currValue) dependencies[dep] = currValue;
2176
+ }
2177
+ if (Object.keys(dependencies).length) packageAdditions.dependencies = dependencies;
2178
+ const origDevDeps = originalPackageJson.devDependencies || {};
2179
+ const currDevDeps = currentPackageJson.devDependencies || {};
2180
+ const devDependencies = {};
2181
+ for (const dep of Object.keys(currDevDeps)) {
2182
+ const currValue = currDevDeps[dep];
2183
+ if (currValue && origDevDeps[dep] !== currValue) devDependencies[dep] = currValue;
2184
+ }
2185
+ if (Object.keys(devDependencies).length) packageAdditions.devDependencies = devDependencies;
2186
+ return packageAdditions;
2187
+ }
2188
+ async function createCompileOptionsFromPersisted(persisted, integrationsPath) {
2189
+ let chosenIntegrations = [];
2190
+ if (persisted.chosenIntegrations.length > 0) chosenIntegrations = await fetchIntegrations(persisted.chosenIntegrations, integrationsPath);
2191
+ return {
2192
+ projectName: persisted.projectName,
2193
+ framework: persisted.framework,
2194
+ mode: persisted.mode,
2195
+ typescript: persisted.typescript,
2196
+ tailwind: persisted.tailwind,
2197
+ packageManager: persisted.packageManager,
2198
+ chosenIntegrations,
2199
+ integrationOptions: {},
2200
+ customTemplate: void 0
2201
+ };
2202
+ }
2203
+ function runCompile(options) {
2204
+ return compile(options);
2205
+ }
2206
+ /**
2207
+ * Compare files recursively between current project and original output
2208
+ * Ported from Jack's compareFilesRecursively
2209
+ */
2210
+ async function compareFilesRecursively(basePath, ignoreFn, original, changedFiles) {
2211
+ await compareFilesRecursivelyHelper(basePath, ".", ignoreFn, original, changedFiles);
2212
+ }
2213
+ async function compareFilesRecursivelyHelper(basePath, relativePath$1, ignoreFn, original, changedFiles) {
2214
+ const entries = await readdir(resolve(basePath, relativePath$1), { withFileTypes: true });
2215
+ for (const entry of entries) {
2216
+ const entryRelativePath = relativePath$1 === "." ? entry.name : `${relativePath$1}/${entry.name}`;
2217
+ const entryFullPath = resolve(basePath, entryRelativePath);
2218
+ if (ignoreFn(entry.name)) continue;
2219
+ if (entry.isDirectory()) await compareFilesRecursivelyHelper(basePath, entryRelativePath, ignoreFn, original, changedFiles);
2220
+ else {
2221
+ const contents = readFileHelper(entryFullPath);
2222
+ const originalKey = entryRelativePath;
2223
+ if (!original[originalKey] || original[originalKey] !== contents) changedFiles[entryRelativePath] = contents;
2224
+ }
2225
+ }
2226
+ }
2227
+ async function readCurrentProjectOptions(targetDir) {
2228
+ const persisted = await readConfigFile(targetDir);
2229
+ if (!persisted) throw new Error(`No .tanstack.json file found in ${targetDir}.\nThis project may have been created with an older version of the CLI, or was not created with the TanStack CLI.`);
2230
+ return persisted;
2231
+ }
2232
+ /**
2233
+ * Recursively gather files from a directory
2234
+ * Ported from Jack's recursivelyGatherFiles
2235
+ */
2236
+ async function recursivelyGatherFiles(path, includeProjectFiles = true) {
2237
+ const ignoreFn = createIgnore(path, includeProjectFiles);
2238
+ const files = {};
2239
+ if (!existsSync(path)) return files;
2240
+ await gatherFilesHelper(path, ".", files, ignoreFn);
2241
+ return files;
2242
+ }
2243
+ async function gatherFilesHelper(basePath, relativePath$1, files, ignoreFn) {
2244
+ const entries = await readdir(resolve(basePath, relativePath$1), { withFileTypes: true });
2245
+ for (const entry of entries) {
2246
+ if (ignoreFn(entry.name)) continue;
2247
+ const entryRelativePath = relativePath$1 === "." ? entry.name : `${relativePath$1}/${entry.name}`;
2248
+ const entryFullPath = resolve(basePath, entryRelativePath);
2249
+ if (entry.isDirectory()) await gatherFilesHelper(basePath, entryRelativePath, files, ignoreFn);
2250
+ else files[entryRelativePath] = readFileHelper(entryFullPath);
2251
+ }
2252
+ }
2253
+
2254
+ //#endregion
2255
+ //#region src/engine/custom-addons/integration.ts
2256
+ const INTEGRATION_DIR = ".integration";
2257
+ const INFO_FILE$1 = ".integration/info.json";
2258
+ const COMPILED_FILE$1 = "integration.json";
2259
+ const ASSETS_DIR = "assets";
2260
+ const INTEGRATION_IGNORE_FILES = [
2261
+ "main.jsx",
2262
+ "App.jsx",
2263
+ "main.tsx",
2264
+ "App.tsx",
2265
+ "routeTree.gen.ts"
2266
+ ];
2267
+ function camelCase(str) {
2268
+ return str.split(/(\.|-|\/)/).filter((part) => /^[a-zA-Z]+$/.test(part)).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
2269
+ }
2270
+ function templatize(routeCode, routeFile) {
2271
+ let code = routeCode;
2272
+ code = code.replace(/import { createFileRoute } from ['"]@tanstack\/react-router['"]/g, `import { <% if (fileRouter) { %>createFileRoute<% } else { %>createRoute<% } %> } from '@tanstack/react-router'`);
2273
+ const routeMatch = code.match(/export\s+const\s+Route\s*=\s*createFileRoute\(['"]([^'"]+)['"]\)\s*\(\{([^}]+)\}\)/);
2274
+ let path = "";
2275
+ if (routeMatch) {
2276
+ const fullMatch = routeMatch[0];
2277
+ path = routeMatch[1];
2278
+ const routeDefinition = routeMatch[2];
2279
+ code = code.replace(fullMatch, `<% if (codeRouter) { %>
2280
+ import type { RootRoute } from '@tanstack/react-router'
2281
+ <% } else { %>
2282
+ export const Route = createFileRoute('${path}')({${routeDefinition}})
2283
+ <% } %>`);
2284
+ code += `
2285
+ <% if (codeRouter) { %>
2286
+ export default (parentRoute: RootRoute) => createRoute({
2287
+ path: '${path}',
2288
+ ${routeDefinition}
2289
+ getParentRoute: () => parentRoute,
2290
+ })
2291
+ <% } %>
2292
+ `;
2293
+ } else console.warn(`No route found in the file: ${routeFile}`);
2294
+ const name = basename(path).replace(".tsx", "").replace(/^demo/, "").replace(".", " ").trim();
2295
+ const jsName = camelCase(basename(path));
2296
+ return {
2297
+ url: path,
2298
+ code,
2299
+ name,
2300
+ jsName
2301
+ };
2302
+ }
2303
+ async function validateIntegrationSetup(targetDir) {
2304
+ const options = await readCurrentProjectOptions(targetDir);
2305
+ if (options.mode === "code-router") throw new Error("This project is using code-router mode.\nTo create an integration, the project must use file-router mode.");
2306
+ if (!options.tailwind) throw new Error("This project is not using Tailwind CSS.\nTo create an integration, the project must be created with Tailwind CSS.");
2307
+ if (!options.typescript) throw new Error("This project is not using TypeScript.\nTo create an integration, the project must be created with TypeScript.");
2308
+ }
2309
+ async function readOrGenerateIntegrationInfo(options, targetDir) {
2310
+ const infoPath = resolve(targetDir, INFO_FILE$1);
2311
+ if (existsSync(infoPath)) {
2312
+ const content = await readFile(infoPath, "utf-8");
2313
+ return JSON.parse(content);
2314
+ }
2315
+ return {
2316
+ id: `${options.projectName}-integration`,
2317
+ name: `${options.projectName} Integration`,
2318
+ description: "Custom integration",
2319
+ author: "Author <author@example.com>",
2320
+ version: "0.0.1",
2321
+ license: "MIT",
2322
+ link: `https://github.com/example/${options.projectName}-integration`,
2323
+ type: "integration",
2324
+ phase: "integration",
2325
+ modes: [options.mode],
2326
+ requiresTailwind: options.tailwind || void 0,
2327
+ dependsOn: options.chosenIntegrations.length > 0 ? options.chosenIntegrations : void 0,
2328
+ routes: [],
2329
+ packageAdditions: {
2330
+ scripts: {},
2331
+ dependencies: {},
2332
+ devDependencies: {}
2333
+ }
2334
+ };
2335
+ }
2336
+ async function generateBaseProject(persistedOptions, targetDir, integrationsPath) {
2337
+ return {
2338
+ info: await readOrGenerateIntegrationInfo(persistedOptions, targetDir),
2339
+ output: runCompile(await createCompileOptionsFromPersisted(persistedOptions, integrationsPath))
2340
+ };
2341
+ }
2342
+ async function buildAssetsDirectory(targetDir, output, info) {
2343
+ const assetsDir = resolve(targetDir, INTEGRATION_DIR, ASSETS_DIR);
2344
+ if (existsSync(assetsDir)) return;
2345
+ const ignoreFn = createIgnore(targetDir);
2346
+ const changedFiles = {};
2347
+ await compareFilesRecursively(targetDir, ignoreFn, output.files, changedFiles);
2348
+ for (const file of Object.keys(changedFiles)) {
2349
+ if (INTEGRATION_IGNORE_FILES.includes(basename(file))) continue;
2350
+ const targetPath = resolve(assetsDir, file);
2351
+ mkdirSync(dirname(targetPath), { recursive: true });
2352
+ const fileContent = changedFiles[file];
2353
+ if (file.includes("/routes/")) {
2354
+ const { url, code, name, jsName } = templatize(fileContent, file);
2355
+ info.routes ||= [];
2356
+ if (!info.routes.find((r) => r.url === url)) info.routes.push({
2357
+ url,
2358
+ name,
2359
+ jsName,
2360
+ path: file
2361
+ });
2362
+ writeFileSync(`${targetPath}.ejs`, code);
2363
+ } else writeFileSync(targetPath, fileContent);
2364
+ }
2365
+ }
2366
+ async function updateIntegrationInfo(targetDir, integrationsPath) {
2367
+ const { info, output } = await generateBaseProject(await readCurrentProjectOptions(targetDir), targetDir, integrationsPath);
2368
+ info.packageAdditions = createPackageAdditions(JSON.parse(output.files["package.json"]), JSON.parse(await readFile(resolve(targetDir, "package.json"), "utf-8")));
2369
+ await buildAssetsDirectory(targetDir, output, info);
2370
+ await mkdir(resolve(targetDir, dirname(INFO_FILE$1)), { recursive: true });
2371
+ await writeFile(resolve(targetDir, INFO_FILE$1), JSON.stringify(info, null, 2));
2372
+ }
2373
+ async function compileIntegration(targetDir, _integrationsPath) {
2374
+ const persistedOptions = await readCurrentProjectOptions(targetDir);
2375
+ const info = await readOrGenerateIntegrationInfo(persistedOptions, targetDir);
2376
+ const assetsDir = resolve(targetDir, INTEGRATION_DIR, ASSETS_DIR);
2377
+ const compiledInfo = {
2378
+ ...info,
2379
+ id: info.id || `${persistedOptions.projectName}-integration`,
2380
+ files: await recursivelyGatherFiles(assetsDir),
2381
+ deletedFiles: []
2382
+ };
2383
+ await writeFile(resolve(targetDir, COMPILED_FILE$1), JSON.stringify(compiledInfo, null, 2));
2384
+ console.log(`Compiled integration written to ${COMPILED_FILE$1}`);
2385
+ }
2386
+ async function initIntegration(targetDir, integrationsPath) {
2387
+ await validateIntegrationSetup(targetDir);
2388
+ await updateIntegrationInfo(targetDir, integrationsPath);
2389
+ await compileIntegration(targetDir, integrationsPath);
2390
+ console.log(`
2391
+ Integration initialized successfully!
2392
+
2393
+ Files created:
2394
+ ${INFO_FILE$1} - Integration metadata (edit this to customize)
2395
+ ${INTEGRATION_DIR}/${ASSETS_DIR}/ - Integration asset files
2396
+ ${COMPILED_FILE$1} - Compiled integration (distribute this)
2397
+
2398
+ Next steps:
2399
+ 1. Edit ${INFO_FILE$1} to customize your integration metadata
2400
+ 2. Run 'tanstack integration compile' to rebuild after changes
2401
+ 3. Share ${COMPILED_FILE$1} or host it publicly
2402
+ `);
2403
+ }
2404
+ /**
2405
+ * Load a remote integration from a URL
2406
+ */
2407
+ async function loadRemoteIntegration(url) {
2408
+ const response = await fetch(url);
2409
+ if (!response.ok) throw new Error(`Failed to fetch integration from ${url}: ${response.statusText}`);
2410
+ const jsonContent = await response.json();
2411
+ const result = IntegrationCompiledSchema.safeParse(jsonContent);
2412
+ if (!result.success) throw new Error(`Invalid integration at ${url}: ${result.error.message}`);
2413
+ const integration = result.data;
2414
+ if (!integration.id) integration.id = url;
2415
+ return integration;
2416
+ }
2417
+
2418
+ //#endregion
2419
+ //#region src/engine/custom-addons/template.ts
2420
+ const INFO_FILE = "template-info.json";
2421
+ const COMPILED_FILE = "template.json";
2422
+ /**
2423
+ * Generate default template info from project options
2424
+ * Custom templates are just integration presets - they capture which integrations are selected
2425
+ */
2426
+ async function readOrGenerateTemplateInfo(options, targetDir) {
2427
+ const infoPath = resolve(targetDir, INFO_FILE);
2428
+ if (existsSync(infoPath)) {
2429
+ const content = await readFile(infoPath, "utf-8");
2430
+ return JSON.parse(content);
2431
+ }
2432
+ return {
2433
+ id: `${options.projectName}-template`,
2434
+ name: `${options.projectName} Template`,
2435
+ description: "A curated project template",
2436
+ framework: options.framework,
2437
+ mode: options.mode,
2438
+ typescript: options.typescript,
2439
+ tailwind: options.tailwind,
2440
+ integrations: options.chosenIntegrations
2441
+ };
2442
+ }
2443
+ /**
2444
+ * Compile a custom template from the current project
2445
+ * Custom templates are just integration presets - they specify project defaults and which integrations to include
2446
+ */
2447
+ async function compileTemplate(targetDir) {
2448
+ const persistedOptions = await readCurrentProjectOptions(targetDir);
2449
+ const info = await readOrGenerateTemplateInfo(persistedOptions, targetDir);
2450
+ const compiledInfo = {
2451
+ ...info,
2452
+ id: info.id || `${persistedOptions.projectName}-template`
2453
+ };
2454
+ await writeFile(resolve(targetDir, COMPILED_FILE), JSON.stringify(compiledInfo, null, 2));
2455
+ console.log(`Compiled template written to ${COMPILED_FILE}`);
2456
+ console.log(`\nIncluded integrations: ${compiledInfo.integrations.length > 0 ? compiledInfo.integrations.join(", ") : "(none)"}`);
2457
+ }
2458
+ async function initTemplate(targetDir) {
2459
+ const info = await readOrGenerateTemplateInfo(await readCurrentProjectOptions(targetDir), targetDir);
2460
+ await writeFile(resolve(targetDir, INFO_FILE), JSON.stringify(info, null, 2));
2461
+ await compileTemplate(targetDir);
2462
+ console.log(`
2463
+ Custom template initialized successfully!
2464
+
2465
+ Files created:
2466
+ ${INFO_FILE} - Template metadata (edit this to customize)
2467
+ ${COMPILED_FILE} - Compiled template (distribute this)
2468
+
2469
+ Custom templates are integration presets. They capture:
2470
+ - Project defaults (framework, mode, typescript, tailwind)
2471
+ - Which integrations to include
2472
+ - Preset integration options (if any)
2473
+
2474
+ Next steps:
2475
+ 1. Edit ${INFO_FILE} to customize name, description, and integrations
2476
+ 2. Run 'tanstack template compile' to rebuild after changes
2477
+ 3. Share ${COMPILED_FILE} or host it publicly
2478
+ 4. Users can use: tanstack create --template <url-to-template.json>
2479
+ `);
2480
+ }
2481
+ /**
2482
+ * Load a remote custom template from a URL
2483
+ */
2484
+ async function loadTemplate(url) {
2485
+ const response = await fetch(url);
2486
+ if (!response.ok) throw new Error(`Failed to fetch template from ${url}: ${response.statusText}`);
2487
+ const jsonContent = await response.json();
2488
+ const result = CustomTemplateCompiledSchema.safeParse(jsonContent);
2489
+ if (!result.success) throw new Error(`Invalid template at ${url}: ${result.error.message}`);
2490
+ const template = result.data;
2491
+ if (!template.id) template.id = url;
2492
+ return template;
2493
+ }
2494
+
2495
+ //#endregion
2496
+ export { writeConfigFile as A, IntegrationTypeSchema as C, RouterModeSchema as D, RouteSchema as E, compileWithAttribution as M, processTemplateFile as N, CONFIG_FILE as O, relativePath as P, IntegrationPhaseSchema as S, ManifestSchema as T, HookSchema as _, initIntegration as a, IntegrationOptionSchema as b, fetchIntegrationFiles as c, fetchManifest as d, CategorySchema as f, EnvVarSchema as g, CustomTemplateInfoSchema as h, compileIntegration as i, compile as j, readConfigFile as k, fetchIntegrationInfo as l, CustomTemplateCompiledSchema as m, initTemplate as n, loadRemoteIntegration as o, CommandSchema as p, loadTemplate as r, fetchIntegration as s, compileTemplate as t, fetchIntegrations as u, IntegrationCompiledSchema as v, ManifestIntegrationSchema as w, IntegrationOptionsSchema as x, IntegrationInfoSchema as y };