Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .changeset/create-routes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
'@tanstack/cms-ui-react': minor
'@tanstack/cms-cli': minor
'@tanstack/cms-core': patch
---

**Breaking:** `createRoutes(definition, spec?)` from
`@tanstack/cms-ui-react/virtual-routes` replaces `cmsVirtualRoutes(options)`,
which is removed. It takes the `defineCmsDefinition` result from
`src/cms.definition.ts`, the only app module `vite.config.ts` imports, and
reads the admin base path and plugin routes from it, so they're no longer
repeated in the Vite config.

The spec names routes by surface. `public`, `admin`, and `api` each take `true`
(every route), `false` (none), a list of route keys (only those), or an object
that drops (`false`) or replaces (a file path) single keys. A surface you leave
out is mounted, so `createRoutes(definition)` mounts everything. `custom`
replaces `children`, and `rootFile` is unchanged. `routesDirectory` and
`generatedDirectory` move to the `tanstackCms()` Vite plugin, which has to
come before `tanstackStart()`. `CreateRoutesSpec` replaces
`CmsVirtualRoutesOptions`, and the route keys (`CmsRouteKey`) are stable public
API. An old option throws with its replacement in the message.

```ts
// before
cmsVirtualRoutes({
adminBasePath: '/admin',
include: { public: false },
routes: { agent: false },
})
// after: admin.basePath is set in defineCmsDefinition()
createRoutes(definition, { public: false, admin: { agent: false } })
```

Migrate with `pnpm codemod create-routes <path-to-your-app>`, run from a
TanStack CMS checkout. It rewrites `vite.config.ts` files and Markdown code
blocks and warns where an `adminBasePath` or `plugins` value has to move into
the definition. `tanstack-cms init` now writes `createRoutes(definition)`.
9 changes: 5 additions & 4 deletions .claude/skills/astro-starlight-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ shape of [`examples/blog`](../../../examples/blog) (same as the Payload skill
`@tanstack/router-plugin`, `typescript`, node/react types, `vitest`.
Scripts: `dev`, `build`, `test:types`, `test:lib` (`vitest run`),
`migrate:data`. Pick a free dev port.
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: cmsVirtualRoutes() } }), nitro(), viteReact()]`
with `tanstackCms` from `@tanstack/cms-ui-react/vite` and `cmsVirtualRoutes`
from `@tanstack/cms-ui-react/virtual-routes`.
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: createRoutes(definition) } }), nitro(), viteReact()]`
with `tanstackCms` from `@tanstack/cms-ui-react/vite`, `createRoutes` from
`@tanstack/cms-ui-react/virtual-routes`, and `definition` from
`./src/cms.definition` (the only app module the Vite config imports).
- `vitest.config.ts` — plain `defineConfig({ test: { environment: 'node', include: ['src/**/*.test.ts'] } })`
from `vitest/config`.
- `tsconfig.json` — `{ "extends": "../../tsconfig.base.json", "include": ["src/**/*.ts","src/**/*.tsx"] }`.
Expand All @@ -84,7 +85,7 @@ shape of [`examples/blog`](../../../examples/blog) (same as the Payload skill
Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
`redirectsCollection`, …): Vite config and client code load this file, and
`pnpm test:definitions` fails if it reaches React, Start, or server code.
`pnpm test:definitions` fails if it reaches React, Start, server code, or the `@tanstack/cms-core` root.
Then write `cms.config.ts` calling
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
rules that need server code attach there by collection name
Expand Down
9 changes: 5 additions & 4 deletions .claude/skills/emdash-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ migration skills' §2):
`@tanstack/router-plugin`, `typescript`, node/react types, `vitest`.
Scripts: `dev`, `build`, `test:types`, `test:lib` (`vitest run`),
`migrate:data`. Pick a free dev port.
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: cmsVirtualRoutes() } }), nitro(), viteReact()]`
with `tanstackCms` from `@tanstack/cms-ui-react/vite` and `cmsVirtualRoutes`
from `@tanstack/cms-ui-react/virtual-routes`.
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: createRoutes(definition) } }), nitro(), viteReact()]`
with `tanstackCms` from `@tanstack/cms-ui-react/vite`, `createRoutes` from
`@tanstack/cms-ui-react/virtual-routes`, and `definition` from
`./src/cms.definition` (the only app module the Vite config imports).
- `vitest.config.ts` — plain `defineConfig({ test: { environment: 'node', include: ['src/**/*.test.ts'] } })`
from `vitest/config`.
- `tsconfig.json` — `{ "extends": "../../tsconfig.base.json", "include": ["src/**/*.ts","src/**/*.tsx"] }`.
Expand All @@ -98,7 +99,7 @@ npm project with a large dependency tree) — see `examples/emdash-before` and t
Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
`redirectsCollection`, …): Vite config and client code load this file, and
`pnpm test:definitions` fails if it reaches React, Start, or server code.
`pnpm test:definitions` fails if it reaches React, Start, server code, or the `@tanstack/cms-core` root.
Then write `cms.config.ts` calling
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
rules that need server code attach there by collection name
Expand Down
15 changes: 8 additions & 7 deletions .claude/skills/payload-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ nested docs), and custom React admin components — these drive the gap report.

Outside this repo, start from a TanStack Start app and run
`npx tanstack-cms init` (from `@tanstack/cms-cli`): it creates
`src/cms.definition.ts` and `src/cms.config.ts`, adds `tanstackCms()` and `cmsVirtualRoutes()` to
`src/cms.definition.ts` and `src/cms.config.ts`, adds `tanstackCms()` and `createRoutes(definition)` to
`vite.config.ts`, imports the config from `src/router.tsx`, and ignores
`.data/`. In this repo, copy the shape of [`examples/blog`](../../../examples/blog):

Expand All @@ -63,11 +63,12 @@ Outside this repo, start from a TanStack Start app and run
`test:types` (`tsc --noEmit`), `test:lib` (`vitest run`), `cms`
(`tanstack-cms`), `migrate:data`. Pick a free dev port.
- `vite.config.ts` — as in `examples/blog`:
`plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: cmsVirtualRoutes() } }), nitro(), viteReact()]`
with `tanstackCms` from `@tanstack/cms-ui-react/vite` and `cmsVirtualRoutes`
from `@tanstack/cms-ui-react/virtual-routes`. Payload serves its admin at
`/admin`; keep that URL with `cmsVirtualRoutes({ adminBasePath: '/admin' })`
plus `defineCmsDefinition({ admin: { basePath: '/admin' } })`.
`plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: createRoutes(definition) } }), nitro(), viteReact()]`
with `tanstackCms` from `@tanstack/cms-ui-react/vite`, `createRoutes` from
`@tanstack/cms-ui-react/virtual-routes`, and `definition` from
`./src/cms.definition`. Payload serves its admin at `/admin`; keep that URL
with `defineCmsDefinition({ admin: { basePath: '/admin' } })`, which
`createRoutes` mounts the admin under (set it once, in the definition).
- `vitest.config.ts` — a plain `defineConfig({ test: { environment: 'node', include: ['src/**/*.test.ts'] } })`
from `vitest/config`, so tests don't load the Start/Nitro plugins.
- `tsconfig.json` — `{ "extends": "../../tsconfig.base.json", "include": ["src/**/*.ts","src/**/*.tsx"] }`.
Expand All @@ -80,7 +81,7 @@ Outside this repo, start from a TanStack Start app and run
Write `cms.definition.ts` calling `defineCmsDefinition({ collections, admin })`,
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
`redirectsCollection`, …): Vite config and client code load this file, and
`pnpm test:definitions` fails if it reaches React, Start, or server code.
`pnpm test:definitions` fails if it reaches React, Start, server code, or the `@tanstack/cms-core` root.
Then write `cms.config.ts` calling
`defineCms(definition, { blockTypes, auth, seed, collections, … })` and
register the definition's type
Expand Down
6 changes: 3 additions & 3 deletions .claude/skills/voting/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ All store functions from `@tanstack/cms-core/server` are **async** —
## 0. Prerequisites

- A TanStack CMS app (`cms.definition.ts` + `cms.config.ts` +
`cmsVirtualRoutes()`), e.g. a copy of
`createRoutes(definition)`), e.g. a copy of
[`examples/blog`](../../../examples/blog).
- An `auth` config (`createMockAuth()` from `@tanstack/cms-ui-react` for
demos, `auth: { getUser }` in production) so votes have a voter.
Expand Down Expand Up @@ -251,10 +251,10 @@ A small component: up arrow, score, down arrow. Requirements:
silently); `useCmsAuth()` from `@tanstack/cms-ui-react` says who's signed in.
- Wiring, in order of preference:
1. Render `VoteButtons` in app-owned pages (list cards, a top-posts page)
added with `cmsVirtualRoutes({ children: [route('/top', './top.tsx')] })`
added with `createRoutes(definition, { custom: [route('/top', './top.tsx')] })`
— child paths are relative to `src/routes`. This is what the worked
example does.
2. **Replace the built-in post page**: `cmsVirtualRoutes({ routes: { post: './post.$id.tsx' } })`
2. **Replace the built-in post page**: `createRoutes(definition, { public: { post: './post.$id.tsx' } })`
swaps in your own file (relative to `src/routes`); it must call
`createFileRoute('/post/$id')`. Start from the package's
`routes/post.$id.tsx` and add the buttons.
Expand Down
9 changes: 5 additions & 4 deletions .claude/skills/wordpress-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ migration skills' §2):
`@tanstack/router-plugin`, `typescript`, node/react types, `vitest`.
Scripts: `dev`, `build`, `test:types`, `test:lib` (`vitest run`),
`migrate:data`. Pick a free dev port.
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: cmsVirtualRoutes() } }), nitro(), viteReact()]`
with `tanstackCms` from `@tanstack/cms-ui-react/vite` and `cmsVirtualRoutes`
from `@tanstack/cms-ui-react/virtual-routes`.
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: createRoutes(definition) } }), nitro(), viteReact()]`
with `tanstackCms` from `@tanstack/cms-ui-react/vite`, `createRoutes` from
`@tanstack/cms-ui-react/virtual-routes`, and `definition` from
`./src/cms.definition` (the only app module the Vite config imports).
- `vitest.config.ts` — plain `defineConfig({ test: { environment: 'node', include: ['src/**/*.test.ts'] } })`
from `vitest/config`.
- `tsconfig.json` — extends `../../tsconfig.base.json`; `src/router.tsx` —
Expand All @@ -91,7 +92,7 @@ workspace app.
Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
`redirectsCollection`, …): Vite config and client code load this file, and
`pnpm test:definitions` fails if it reaches React, Start, or server code.
`pnpm test:definitions` fails if it reaches React, Start, server code, or the `@tanstack/cms-core` root.
Then write `cms.config.ts` calling
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
rules that need server code attach there by collection name
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TanStack Start app, and your UI reads its content through TanStack DB.

- **TanStack Start is the runtime.** The admin, the public pages, and every API
endpoint are Start routes shipped in a package and mounted with
`cmsVirtualRoutes()`. Each CMS operation is a Start server function
`createRoutes(definition)`. Each CMS operation is a Start server function
(`@tanstack/cms-api/start`), so the admin and your own loaders call the
engine in-process, with no HTTP hop. The same operations are served over
HTTP, MCP, and WebMCP for everything outside the app.
Expand Down Expand Up @@ -106,8 +106,8 @@ for your app's own routes and components. See
- **SEO built in.** Sitemap, robots.txt, redirects, OpenGraph and JSON-LD
helpers, and signed webhooks on publish, unpublish, and delete.
- **Routes from a package.** The admin, public pages, and API endpoints mount
into your Start app with `cmsVirtualRoutes()`. Move the admin under a base
path, override any route with your own file, or drop it.
into your Start app with `createRoutes(definition)`. Mount only some, move
the admin under a base path, or replace or drop any route by its key.
- **A CLI.** `tanstack-cms init`, `migrate`, `seed`, `export`, `import`, and
`backup`.

Expand Down Expand Up @@ -163,7 +163,9 @@ declare module '@tanstack/cms-core' {
}
```

A small app can keep both halves in one `defineCms({ collections, … })` call.
A small app can keep both halves in one `defineCms({ collections, … })` call,
but `vite.config.ts` mounts the routes from the definition, so keep at least
`defineCmsDefinition({})` in `src/cms.definition.ts`.

```ts
// vite.config.ts
Expand All @@ -172,14 +174,15 @@ import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import { nitro } from 'nitro/vite'
import viteReact from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { cmsVirtualRoutes } from '@tanstack/cms-ui-react/virtual-routes'
import { createRoutes } from '@tanstack/cms-ui-react/virtual-routes'
import { tanstackCms } from '@tanstack/cms-ui-react/vite'
import { definition } from './src/cms.definition'

export default defineConfig({
plugins: [
tanstackCms(),
tailwindcss(),
tanstackStart({ router: { virtualRouteConfig: cmsVirtualRoutes() } }),
tanstackStart({ router: { virtualRouteConfig: createRoutes(definition) } }),
nitro(),
viteReact(),
],
Expand Down
11 changes: 6 additions & 5 deletions app/base/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { nitro } from 'nitro/vite'
import viteReact from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { index, route } from '@tanstack/virtual-file-routes'
import { cmsVirtualRoutes } from '@tanstack/cms-ui-react/virtual-routes'
import { createRoutes } from '@tanstack/cms-ui-react/virtual-routes'
import { tanstackCms } from '@tanstack/cms-ui-react/vite'
import { definition } from './src/cms.definition'

const quickjsPackages = [
'quickjs-emscripten',
Expand All @@ -22,11 +23,11 @@ export default defineConfig({
tailwindcss(),
tanstackStart({
router: {
virtualRouteConfig: cmsVirtualRoutes({
virtualRouteConfig: createRoutes(definition, {
rootFile: './__root.tsx',
include: { public: false },
routes: { agent: './agent.tsx' },
children: [
public: false,
admin: { agent: './agent.tsx' },
custom: [
index('./home.tsx'),
route('/setup', './setup.tsx'),
route('/collections', './collections.tsx'),
Expand Down
4 changes: 2 additions & 2 deletions app/prm/src/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* and priority (`high` | `medium` | `low` | `unranked`).
* - `personSource` stores per-field provenance (`high` | `medium` | `low`).
*/
import { defineCollection } from '@tanstack/cms-core'
import type { AccessRule } from '@tanstack/cms-core'
import { defineCollection } from '@tanstack/cms-core/definition'
import type { AccessRule } from '@tanstack/cms-core/definition'

export const INTEREST_OPTIONS = [
'agent-harness',
Expand Down
9 changes: 5 additions & 4 deletions app/prm/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import { nitro } from 'nitro/vite'
import viteReact from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { route } from '@tanstack/virtual-file-routes'
import { cmsVirtualRoutes } from '@tanstack/cms-ui-react/virtual-routes'
import { createRoutes } from '@tanstack/cms-ui-react/virtual-routes'
import { tanstackCms } from '@tanstack/cms-ui-react/vite'
import { definition } from './src/cms.definition'

export default defineConfig({
plugins: [
tanstackCms(),
tailwindcss(),
tanstackStart({
router: {
virtualRouteConfig: cmsVirtualRoutes({
virtualRouteConfig: createRoutes(definition, {
rootFile: './__root.tsx',
include: { public: false, admin: true, api: true },
children: [
public: false,
custom: [
route('/', './index.tsx'),
route('/setup', './setup.tsx'),
route('/login', './login.tsx'),
Expand Down
2 changes: 1 addition & 1 deletion docs/agents/on-page-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Agents working off the page (the content agent, MCP, WebMCP) never get this dire
## Using the Components in Your Own Routes
If you replace the CMS `page` or `post` route (`cmsVirtualRoutes({ routes: { post: './my-post.tsx' } })`), render the interactive components to keep on-page editing:
If you replace the CMS `page` or `post` route (`createRoutes(definition, { public: { post: './my-post.tsx' } })`), render the interactive components to keep on-page editing:
```tsx validate=type
import {
Expand Down
2 changes: 1 addition & 1 deletion docs/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tanstack-cms init [--dir <dir>] [--force]
Adds TanStack CMS to an existing TanStack Start app:

- **Config**: writes `src/cms.definition.ts` (a `post` collection, importing only `@tanstack/cms-core/definition`) and `src/cms.config.ts` (`defineCms(definition, { … })` with a seed post and the `Register` augmentation for end-to-end types), or both in the app root when there is no `src` directory. If either file exists, both are kept unless `--force` is passed.
- **Vite**: in `vite.config.ts`, `.mts`, or `.js`, replaces a plain `tanstackStart()` call with `tanstackCms()` plus `tanstackStart({ router: { virtualRouteConfig: cmsVirtualRoutes() } })` and adds the imports. A config that already passes options to `tanstackStart` is left alone and the snippet is printed instead.
- **Vite**: in `vite.config.ts`, `.mts`, or `.js`, replaces a plain `tanstackStart()` call with `tanstackCms()` plus `tanstackStart({ router: { virtualRouteConfig: createRoutes(definition) } })` and adds the imports (`definition` from `./src/cms.definition`). A config that already passes options to `tanstackStart` is left alone and the snippet is printed instead.
- **Router**: adds `import './cms.config'` to `router.tsx` / `router.ts`, so the content model is registered before any loader or server function runs.
- **`.gitignore`**: adds `.data/` (the default SQLite database and uploads directory).

Expand Down
Loading
Loading