Open History to see the last commit
1import { dirname, join } from 'node:path'
2import { fileURLToPath } from 'node:url'
3import { z } from 'zod'
4import {
5 registerFramework,
6 scanAddOnDirectories,
7 scanProjectDirectory,
8} from '@tanstack/cta-engine'
9import type { ZodTypeAny } from 'zod'
10
11export function createFrameworkDefinition(): any {
12 const baseDirectory = dirname(dirname(fileURLToPath(import.meta.url)))
13
14 // Define custom properties for React framework
15 const customProperties = {
16 routes: z
17 .array(
18 z.object({
19 url: z.string().optional(),
20 name: z.string().optional(),
21 path: z.string(),
22 jsName: z.string(),
23 }),
24 )
25 .optional(),
26 integrations: z
27 .array(
28 z.object({
29 type: z.enum(['provider', 'root-provider', 'layout', 'header-user']),
30 path: z.string(),
31 jsName: z.string(),
32 }),
33 )
34 .optional(),
35 } as Record<string, ZodTypeAny>
36
37 const addOns = scanAddOnDirectories(
38 [
39 join(baseDirectory, 'add-ons'),
40 join(baseDirectory, 'toolchains'),
41 join(baseDirectory, 'examples'),
42 ],
43 { customProperties },
44 )
45
46 const { files, basePackageJSON, optionalPackages } = scanProjectDirectory(
47 join(baseDirectory, 'project'),
48 join(baseDirectory, 'project/base'),
49 )
50
51 const framework = {
52 id: 'react-cra',
53 name: 'React',
54 description: 'Templates for React CRA',
55 version: '0.1.0',
56 customProperties: {
57 routes: z
58 .array(
59 z.object({
60 url: z.string().optional(),
61 name: z.string().optional(),
62 path: z.string(),
63 jsName: z.string(),
64 }),
65 )
66 .optional(),
67 integrations: z
68 .array(
69 z.object({
70 type: z.enum([
71 'provider',
72 'root-provider',
73 'layout',
74 'header-user',
75 ]),
76 path: z.string(),
77 jsName: z.string(),
78 }),
79 )
80 .optional(),
81 },
82 base: files,
83 addOns,
84 basePackageJSON,
85 optionalPackages,
86 supportedModes: {
87 'code-router': {
88 displayName: 'Code Router',
89 description: 'TanStack Router using code to define routes',
90 forceTypescript: false,
91 },
92 'file-router': {
93 displayName: 'File Router',
94 description: 'TanStack Router using files to define routes',
95 forceTypescript: true,
96 },
97 },
98 }
99
100 return framework
101}
102
103export function register() {
104 registerFramework(createFrameworkDefinition())
105}