Skip to content

Commit cc22c9c

Browse files
committed
fix(create): generate minimal scaffolding when declining demo/example pages
1 parent 31ae444 commit cc22c9c

14 files changed

Lines changed: 278 additions & 0 deletions

File tree

packages/create/src/frameworks/react/project/base/src/components/Footer.tsx.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<% if (!includeExamples) { ignoreFile(); return; } %>
12
export default function Footer() {
23
const year = new Date().getFullYear()
34

packages/create/src/frameworks/react/project/base/src/components/Header.tsx.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<% if (!includeExamples) { ignoreFile(); return; } %>
12
import { Link } from '@tanstack/react-router'
23
<% for (const integration of integrations.filter((i) => i.type === 'header-user')) { %>import <%= integration.jsName %> from '<%= relativePath(integration.path) %>'
34
<% } %>import ThemeToggle from './ThemeToggle'

packages/create/src/frameworks/react/project/base/src/components/ThemeToggle.tsx.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<% if (!includeExamples) { ignoreFile(); return; } %>
12
import { useEffect, useState } from 'react'
23

34
type ThemeMode = 'light' | 'dark' | 'auto'

packages/create/src/frameworks/react/project/base/src/routes/__root.tsx.ejs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,99 @@ function RootComponent() {
2727
</>
2828
)
2929
}
30+
<% } else if (!includeExamples) { %>
31+
<% let hasContext = addOnEnabled["apollo-client"] || addOnEnabled["tanstack-query"]; %>
32+
import {
33+
HeadContent, Scripts, <% if (hasContext) { %>createRootRouteWithContext<% } else { %>createRootRoute<% } %> } from '@tanstack/react-router'
34+
import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools';
35+
import { TanStackDevtools } from '@tanstack/react-devtools'
36+
<% for(const integration of integrations.filter(i => i.type === 'layout' || i.type === 'provider' || i.type === 'devtools')) { %>
37+
import <%= integration.jsName %> from '<%= relativePath(integration.path, true) %>'
38+
<% } %><% if (addOnEnabled.paraglide) { %>
39+
import { getLocale } from '#/paraglide/runtime'
40+
<% } %>
41+
import appCss from '../styles.css?url'
42+
<% if (addOnEnabled["apollo-client"]) { %>
43+
import type { ApolloClientIntegration } from "@apollo/client-integration-tanstack-start";
44+
<% } %>
45+
<% if (addOnEnabled["tanstack-query"]) { %>
46+
import type { QueryClient } from '@tanstack/react-query'
47+
<% if (addOnEnabled.tRPC) { %>
48+
import type { TRPCRouter } from '#/integrations/trpc/router'
49+
import type { TRPCOptionsProxy } from '@trpc/tanstack-react-query'
50+
<% } %>
51+
<% } %>
52+
<% if (hasContext) { %>
53+
interface MyRouterContext <% if (addOnEnabled["apollo-client"]) {%> extends ApolloClientIntegration.RouterContext <%} %>{
54+
<% if (addOnEnabled["tanstack-query"]) { %>
55+
queryClient: QueryClient
56+
<% if (addOnEnabled.tRPC) { %>
57+
trpc: TRPCOptionsProxy<TRPCRouter>
58+
<% } %>
59+
<% } %>
60+
}<% } %>
61+
62+
export const Route = <% if (hasContext) { %>createRootRouteWithContext<MyRouterContext>()<% } else { %>createRootRoute<% } %>({
63+
<% if (addOnEnabled.paraglide) { %>
64+
beforeLoad: async () => {
65+
// Other redirect strategies are possible; see
66+
// https://github.com/TanStack/router/tree/main/examples/react/i18n-paraglide#offline-redirect
67+
if (typeof document !== 'undefined') {
68+
document.documentElement.setAttribute('lang', getLocale())
69+
}
70+
},
71+
<% } %>
72+
head: () => ({
73+
meta: [
74+
{
75+
charSet: 'utf-8',
76+
},
77+
{
78+
name: 'viewport',
79+
content: 'width=device-width, initial-scale=1',
80+
},
81+
{
82+
title: 'TanStack Start Starter',
83+
},
84+
],
85+
links: [
86+
{
87+
rel: 'stylesheet',
88+
href: appCss,
89+
},
90+
],
91+
}),
92+
shellComponent: RootDocument
93+
})
94+
95+
function RootDocument({ children }: { children: React.ReactNode }) {
96+
return (
97+
<% if (addOnEnabled.paraglide) { %><html lang={getLocale()}><% } else { %><html lang="en"><% } %>
98+
<head>
99+
<HeadContent />
100+
</head>
101+
<body>
102+
<% for(const integration of integrations.filter(i => i.type === 'provider')) { %><<%= integration.jsName %>>
103+
<% } %>{children}
104+
<TanStackDevtools
105+
config={{
106+
position: 'bottom-right',
107+
}}
108+
plugins={[
109+
{
110+
name: 'Tanstack Router',
111+
render: <TanStackRouterDevtoolsPanel />,
112+
},
113+
<% for(const integration of integrations.filter(i => i.type === 'devtools')) { %><%= integration.jsName %>,<% } %>
114+
]}
115+
/>
116+
<% for(const integration of integrations.filter(i => i.type === 'layout')) { %><<%= integration.jsName %> />
117+
<% } %><% for(const integration of integrations.filter(i => i.type === 'provider').reverse()) { %></<%= integration.jsName %>>
118+
<% } %><Scripts />
119+
</body>
120+
</html>
121+
)
122+
}
30123
<% } else { %>
31124
<% let hasContext = addOnEnabled["apollo-client"] || addOnEnabled["tanstack-query"]; %>
32125
import {

packages/create/src/frameworks/react/project/base/src/routes/about.tsx.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<% if (!includeExamples) { ignoreFile(); return; } %>
12
import { createFileRoute } from '@tanstack/react-router'
23

34
export const Route = createFileRoute('/about')({

packages/create/src/frameworks/react/project/base/src/routes/index.tsx.ejs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
<% if (!includeExamples) { %>
2+
import { createFileRoute } from "@tanstack/react-router";
3+
4+
export const Route = createFileRoute("/")({ component: Home });
5+
6+
function Home() {
7+
return (
8+
<div className="p-8">
9+
<h1 className="text-4xl font-bold">Welcome to TanStack Start</h1>
10+
<p className="mt-4 text-lg">
11+
Edit <code>src/routes/index.tsx</code> to get started.
12+
</p>
13+
</div>
14+
);
15+
}
16+
<% } else { %>
117
import { createFileRoute } from "@tanstack/react-router";
218
319
export const Route = createFileRoute("/")({ component: App });
@@ -70,3 +86,4 @@ function App() {
7086
</main>
7187
);
7288
}
89+
<% } %>

packages/create/src/frameworks/react/project/base/src/styles.css.ejs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
<% if (!includeExamples) { %>
2+
@import "tailwindcss";
3+
4+
* {
5+
box-sizing: border-box;
6+
}
7+
8+
html,
9+
body,
10+
#app {
11+
min-height: 100%;
12+
}
13+
14+
body {
15+
margin: 0;
16+
}
17+
<% } else { %>
118
@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Manrope:wght@400;500;600;700;800&display=swap");
219
@import "tailwindcss";
320
@plugin "@tailwindcss/typography";
@@ -257,3 +274,4 @@ a {
257274
transform: translateY(0);
258275
}
259276
}
277+
<% } %>

packages/create/src/frameworks/solid/project/base/src/components/Header.tsx.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<% if (!includeExamples) { ignoreFile(); return; } %>
12
import { Link } from '@tanstack/solid-router'
23
<% for(const integration of integrations.filter(i => i.type === 'header-user')) { %>
34
import <%= integration.jsName %> from '<%= relativePath(integration.path) %>'

packages/create/src/frameworks/solid/project/base/src/routes/__root.tsx.ejs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,51 @@ function RootComponent() {
1616
</>
1717
)
1818
}
19+
<% } else if (!includeExamples) { %>
20+
import { HeadContent, Outlet, Scripts, createRootRouteWithContext } from '@tanstack/solid-router'
21+
import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'
22+
23+
<% if (addOnEnabled['solid-ui']) { %>
24+
import "@fontsource/inter/400.css"
25+
<% } %>
26+
27+
import { HydrationScript } from 'solid-js/web'
28+
import { Suspense } from 'solid-js'
29+
30+
<% for(const addOn of addOns) {
31+
for(const init of addOn.main?.initialize || []) { %>
32+
<%- init %>
33+
<% } } %>
34+
35+
import styleCss from "../styles.css?url";
36+
37+
export const Route = createRootRouteWithContext()({
38+
head: () => ({
39+
links: [{ rel: "stylesheet", href: styleCss }],
40+
}),
41+
shellComponent: RootComponent,
42+
})
43+
44+
function RootComponent() {
45+
return (
46+
<html>
47+
<head>
48+
<HydrationScript />
49+
</head>
50+
<body>
51+
<HeadContent />
52+
<Suspense>
53+
<Outlet />
54+
<TanStackRouterDevtools />
55+
<% for(const integration of integrations.filter(i => i.type === 'layout')) { %>
56+
<<%= integration.jsName %> />
57+
<% } %>
58+
</Suspense>
59+
<Scripts />
60+
</body>
61+
</html>
62+
);
63+
}
1964
<% } else { %>
2065
import { HeadContent, Outlet, Scripts, createRootRouteWithContext } from '@tanstack/solid-router'
2166
import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'

packages/create/src/frameworks/solid/project/base/src/routes/about.tsx.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<% if (!includeExamples) { ignoreFile(); return; } %>
12
import { createFileRoute } from '@tanstack/solid-router'
23

34
export const Route = createFileRoute('/about')({

0 commit comments

Comments
 (0)