Skip to content

Commit 427be1e

Browse files
committed
Merge branch 'main' into alpha
2 parents eda1a66 + 9b2b9e2 commit 427be1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+355
-70
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Available options:
4646
- `--template <type>`: Choose between `file-router`, `typescript`, or `javascript`
4747
- `--tailwind`: Enable Tailwind CSS
4848
- `--package-manager`: Specify your preferred package manager (`npm`, `yarn`, `pnpm`, `bun`, or `deno`)
49-
- `--toolchain`: Specify your toolchain solution for formatting/linting (`biome`)
49+
- `--toolchain`: Specify your toolchain solution for formatting/linting (`biome`, `eslint+prettier`)
5050
- `--no-git`: Do not initialize a git repository
5151
- `--add-ons`: Enable add-on selection or specify add-ons to install
5252

@@ -102,6 +102,8 @@ Choose your preferred solution for formatting and linting either through the int
102102

103103
Setting this flag to `biome` will configure it as your toolchain of choice, adding a `biome.json` to the root of the project. Consult the [biome documentation](https://biomejs.dev/guides/getting-started/) for further customization.
104104

105+
Setting this flag to `eslint+prettier` will configure it as your toolchain of choice, adding an `eslint.config.js` and `prettier.config.js` to the root of the project, as well as a `.prettierignore` file. Consult the [eslint documentation](https://eslint.org/docs/latest/) and [prettier documentation](https://prettier.io/docs/) for further customization.
106+
105107
## Add-ons (experimental)
106108

107109
You can enable add-on selection:

src/create-app.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,25 @@ async function createPackageJSON(
203203
},
204204
}
205205
}
206+
if (options.toolchain === 'eslint+prettier') {
207+
const eslintPrettierPackageJSON = JSON.parse(
208+
await environment.readFile(
209+
resolve(templateDir, 'package.eslintprettier.json'),
210+
'utf-8',
211+
),
212+
)
213+
packageJSON = {
214+
...packageJSON,
215+
scripts: {
216+
...packageJSON.scripts,
217+
...eslintPrettierPackageJSON.scripts,
218+
},
219+
devDependencies: {
220+
...packageJSON.devDependencies,
221+
...eslintPrettierPackageJSON.devDependencies,
222+
},
223+
}
224+
}
206225
if (options.mode === FILE_ROUTER) {
207226
const frPackageJSON = JSON.parse(
208227
await environment.readFile(resolve(routerDir, 'package.fr.json'), 'utf8'),
@@ -421,6 +440,18 @@ export async function createApp(
421440
copyFiles(templateDirBase, ['./toolchain/biome.json'], true)
422441
}
423442

443+
if (options.toolchain === 'eslint+prettier') {
444+
copyFiles(
445+
templateDirBase,
446+
[
447+
'./toolchain/eslint.config.js',
448+
'./toolchain/prettier.config.js',
449+
'./toolchain/.prettierignore',
450+
],
451+
true,
452+
)
453+
}
454+
424455
// Setup reportWebVitals
425456
if (!isAddOnEnabled('start') && options.framework === 'react') {
426457
if (options.typescript) {
@@ -452,7 +483,7 @@ export async function createApp(
452483
)
453484
}
454485

455-
// Setup the package.json file, optionally with typescript, tailwind and biome
486+
// Setup the package.json file, optionally with typescript, tailwind and formatter/linter
456487
await createPackageJSON(
457488
environment,
458489
options.projectName,
@@ -715,6 +746,16 @@ export async function createApp(
715746
s?.stop(`Applied toolchain ${options.toolchain}...`)
716747
}
717748

749+
if (options.toolchain === 'eslint+prettier') {
750+
s?.start(`Applying toolchain ${options.toolchain}...`)
751+
await environment.execute(
752+
options.packageManager,
753+
['run', 'check'],
754+
targetDir,
755+
)
756+
s?.stop(`Applied toolchain ${options.toolchain}...`)
757+
}
758+
718759
if (options.git) {
719760
s?.start(`Initializing git repository...`)
720761
await environment.execute('git', ['init'], resolve(targetDir))

src/toolchain.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
export const SUPPORTED_TOOLCHAINS = ['none', 'biome'] as const
1+
export const SUPPORTED_TOOLCHAINS = [
2+
'none',
3+
'biome',
4+
'eslint+prettier',
5+
] as const
26
export type ToolChain = (typeof SUPPORTED_TOOLCHAINS)[number]
37
export const DEFAULT_TOOLCHAIN: ToolChain = 'none'

templates/react/add-on/start/assets/src/router.tsx.ejs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ export const createRouter = () => {
2424
},
2525
scrollRestoration: true,
2626
defaultPreloadStaleTime: 0,
27+
<% if (addOnEnabled.tRPC) { %>
28+
Wrap: (props: { children: React.ReactNode }) => {
29+
return (
30+
<TanstackQuery.Provider>
31+
{props.children}
32+
</TanstackQuery.Provider>
33+
);
34+
},
35+
<% } %>
2736
}), TanstackQuery.getContext().queryClient)
2837
<% } else { %>
2938
const router = createTanstackRouter({
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { initTRPC } from "@trpc/server";
2+
import superjson from "superjson";
3+
4+
const t = initTRPC.create({
5+
transformer: superjson,
6+
});
7+
8+
export const createTRPCRouter = t.router;
9+
export const publicProcedure = t.procedure;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createTRPCContext } from "@trpc/tanstack-react-query";
2+
import type { TRPCRouter } from "@/trpc/router";
3+
4+
export const { TRPCProvider, useTRPC } = createTRPCContext<TRPCRouter>();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { TRPCError } from '@trpc/server'
2+
import type { TRPCRouterRecord } from '@trpc/server'
3+
// import { z } from 'zod'
4+
5+
import { createTRPCRouter, publicProcedure } from './init'
6+
7+
const peopleRouter = {
8+
list: publicProcedure.query(async () =>
9+
fetch('https://swapi.dev/api/people')
10+
.then((res) => res.json())
11+
.then((d) => d.results as { name: string }[]),
12+
),
13+
} satisfies TRPCRouterRecord
14+
15+
export const trpcRouter = createTRPCRouter({
16+
people: peopleRouter,
17+
})
18+
export type TRPCRouter = typeof trpcRouter
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createAPIFileRoute } from '@tanstack/react-start/api'
2+
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'
3+
import { trpcRouter } from '@/integrations/trpc/router'
4+
5+
function handler({ request }: { request: Request }) {
6+
return fetchRequestHandler({
7+
req: request,
8+
router: trpcRouter,
9+
endpoint: '/api/trpc',
10+
})
11+
}
12+
13+
export const APIRoute = createAPIFileRoute('/api/trpc/$')({
14+
GET: handler,
15+
POST: handler,
16+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "tRPC",
3+
"description": "Integrate tRPC into your application.",
4+
"phase": "add-on",
5+
"templates": ["file-router"],
6+
"link": "https://trpc.io/",
7+
"routes": [],
8+
"dependsOn": ["tanstack-query", "start"]
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"dependencies": {
3+
"@trpc/client": "^11.0.0",
4+
"@trpc/server": "^11.0.0",
5+
"@trpc/tanstack-react-query": "^11.0.0",
6+
"superjson": "^2.2.2",
7+
"zod": "^3.24.2"
8+
}
9+
}

0 commit comments

Comments
 (0)