Skip to content

feat: replace routes and integrations with customProperties #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

timoconnellaus
Copy link
Collaborator

@timoconnellaus timoconnellaus commented Jul 25, 2025

replaces the hard coded routes and integrations with a generic implementation of customProperties defined at for a framework

e.g.
frameworks/react-cra/src/index.ts

const customProperties = {
    routes: z
      .array(
        z.object({
          url: z.string().optional(),
          name: z.string().optional(),
          path: z.string(),
          jsName: z.string(),
        }),
      )
      .optional(),
    integrations: z
      .array(
        z.object({
          type: z.enum(['provider', 'root-provider', 'layout', 'header-user']),
          path: z.string(),
          jsName: z.string(),
        }),
      )
      .optional(),
  } as Record<string, ZodTypeAny>
  
  const addOns = scanAddOnDirectories(
    [
      join(baseDirectory, 'add-ons'),
      join(baseDirectory, 'toolchains'),
      join(baseDirectory, 'examples'),
    ],
    { customProperties }, // to validate custom properties in addons
  )
  
  const framework = {
    id: 'react-cra',
    name: 'React',
    description: 'Templates for React CRA',
    version: '0.1.0',
    customProperties, // pass custom properties to framework
    base: files,
    addOns,
    basePackageJSON,
    optionalPackages,
    supportedModes: {
      'code-router': {
        displayName: 'Code Router',
        description: 'TanStack Router using code to define routes',
        forceTypescript: false,
      },
      'file-router': {
        displayName: 'File Router',
        description: 'TanStack Router using files to define routes',
        forceTypescript: true,
      },
    },
  }

Usage in info.json

{
  "name": "Query",
  "description": "Integrate TanStack Query into your application.",
  "phase": "add-on",
  "modes": ["file-router", "code-router"],
  "type": "add-on",
  "link": "https://tanstack.com/query/latest",
  "customProperties": {
    "routes": [
      {
        "url": "/demo/tanstack-query",
        "name": "TanStack Query",
        "path": "src/routes/demo.tanstack-query.tsx",
        "jsName": "TanStackQueryDemo"
      }
    ],
    "integrations": [
      {
        "type": "root-provider",
        "path": "src/integrations/tanstack-query/root-provider.tsx",
        "jsName": "TanStackQueryProvider"
      },
      {
        "type": "layout",
        "path": "src/integrations/tanstack-query/layout.tsx",
        "jsName": "TanStackQueryLayout"
      }
    ]
  }
}

Usage in ejs

const rootRoute = createRootRoute({
  component: () => (
    <>
    <% for(const integration of integrations.filter(i => i.type === 'provider')) { %>
      <<%= integration.jsName %>>
    <% } %>
    <% if (routes.length > 0) { %><Header /><% } %>
      <Outlet />
      <TanStackRouterDevtools />
      <% for(const integration of integrations.filter(i => i.type === 'layout')) { %>
        <<%= integration.jsName %> />
      <% } %>
    <% for(const integration of integrations.filter(i => i.type === 'provider').reverse()) { %>
      </<%= integration.jsName %>>
    <% } %>
    </>
  ),
});

@timoconnellaus timoconnellaus requested a review from jherr July 25, 2025 05:04
id: 'react-cra',
name: 'React',
description: 'Templates for React CRA',
version: '0.1.0',
customProperties: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is repeat of the schema above.

- Keep customProperties schema definition in framework files for validation
- Move routes and integrations to root level in all add-on info.json files
- Update template processing to collect from root level but validate against customProperties
- Fix missing path and jsName in Solid tanchat example
- Update add-on generator to create routes at root level

This makes routes and integrations feel like first-class properties to developers
while maintaining clean schema definitions in the framework.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jherr this more like it?

@timoconnellaus timoconnellaus changed the title Feature: replace routes and integrations with customProperties feat: replace routes and integrations with customProperties Aug 12, 2025
@timoconnellaus timoconnellaus marked this pull request as draft August 12, 2025 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants