-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 01d7899
Showing
44 changed files
with
5,326 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Make sure to override these in deployment | ||
DATABASE_URL=postgresql://postgres:@localhost:5432/next-prisma-starter-new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", // Specifies the ESLint parser | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin | ||
"plugin:react/recommended", | ||
"plugin:react-hooks/recommended", | ||
"plugin:prettier/recommended" | ||
], | ||
"parserOptions": { | ||
"project": "tsconfig.json", | ||
"ecmaVersion": 2018, // Allows for the parsing of modern ECMAScript features | ||
"sourceType": "module" // Allows for the use of imports | ||
}, | ||
"rules": { | ||
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs | ||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"react/react-in-jsx-scope": "off", | ||
"react/prop-types": "off", | ||
"@typescript-eslint/no-explicit-any": "off" | ||
}, | ||
// "overrides": [ | ||
// { | ||
// "files": [], | ||
// "rules": { | ||
// "@typescript-eslint/no-unused-vars": "off" | ||
// } | ||
// } | ||
// ], | ||
"settings": { | ||
"react": { | ||
"version": "detect" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# These are supported funding model platforms | ||
|
||
github: KATT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: npm | ||
directory: '/' | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: E2E-testing | ||
on: [push] | ||
jobs: | ||
e2e: | ||
services: | ||
postgres: | ||
image: postgres | ||
env: | ||
POSTGRES_DATABASE: trpcdb | ||
POSTGRES_USER: postgres | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
ports: | ||
- 5432:5432 | ||
env: | ||
NODE_ENV: test | ||
NEXTAUTH_SECRET: supersecret | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
node: ['18.x'] | ||
os: [ubuntu-latest] | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: pnpm/[email protected] | ||
with: | ||
version: 7.26.0 | ||
|
||
- name: Use Node ${{ matrix.node }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
# cache: 'pnpm' # You can active this cache when your repo has a lockfile | ||
|
||
- name: Install deps (with cache) | ||
run: pnpm install | ||
|
||
- name: Install playwright | ||
run: pnpm playwright install chromium | ||
|
||
- name: Next.js cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ github.workspace }}/.next/cache | ||
key: ${{ runner.os }}-${{ runner.node }}-${{ hashFiles('**/pnpm-lock.yaml') }}-nextjs | ||
|
||
- name: Setup Prisma | ||
run: pnpm prebuild | ||
|
||
- name: Build and test | ||
run: pnpm build && pnpm test-start && pnpm test-dev | ||
|
||
- name: Upload test results | ||
if: ${{ always() }} | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: test results | ||
path: | | ||
playwright/test-results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
tsconfig.tsbuildinfo | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
*.db | ||
*.db-journal | ||
|
||
|
||
# testing | ||
playwright/test-results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
enable-pre-post-scripts=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"recommendations": [ | ||
"esbenp.prettier-vscode", | ||
"dbaeumer.vscode-eslint", | ||
"prisma.prisma" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Prisma + tRPC | ||
|
||
## Features | ||
|
||
- 🧙♂️ E2E typesafety with [tRPC](https://trpc.io) | ||
- ⚡ Full-stack React with Next.js | ||
- ⚡ Database with Prisma | ||
- ⚙️ VSCode extensions | ||
- 🎨 ESLint + Prettier | ||
- 💚 CI setup using GitHub Actions: | ||
- ✅ E2E testing with [Playwright](https://playwright.dev/) | ||
- ✅ Linting | ||
- 🔐 Validates your env vars on build and start | ||
|
||
## Setup | ||
|
||
```bash | ||
pnpm create next-app --example https://github.com/trpc/trpc --example-path examples/next-prisma-starter trpc-prisma-starter | ||
cd trpc-prisma-starter | ||
pnpm | ||
pnpm dx | ||
``` | ||
|
||
### Requirements | ||
|
||
- Node >= 14 | ||
- Postgres | ||
|
||
## Development | ||
|
||
### Start project | ||
|
||
```bash | ||
pnpm create next-app --example https://github.com/trpc/trpc --example-path examples/next-prisma-starter trpc-prisma-starter | ||
cd trpc-prisma-starter | ||
pnpm | ||
pnpm dx | ||
``` | ||
|
||
### Commands | ||
|
||
```bash | ||
pnpm build # runs `prisma generate` + `prisma migrate` + `next build` | ||
pnpm db-reset # resets local db | ||
pnpm dev # starts next.js | ||
pnpm dx # starts postgres db + runs migrations + seeds + starts next.js | ||
pnpm test-dev # runs e2e tests on dev | ||
pnpm test-start # runs e2e tests on `next start` - build required before | ||
pnpm test:unit # runs normal Vitest unit tests | ||
pnpm test:e2e # runs e2e tests | ||
``` | ||
|
||
## Deployment | ||
|
||
### Using [Render](https://render.com/) | ||
|
||
The project contains a [`render.yaml`](./render.yaml) [_"Blueprint"_](https://render.com/docs/blueprint-spec) which makes the project easily deployable on [Render](https://render.com/). | ||
|
||
Go to [dashboard.render.com/blueprints](https://dashboard.render.com/blueprints) and connect to this Blueprint and see how the app and database automatically gets deployed. | ||
|
||
## Files of note | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Path</th> | ||
<th>Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><a href="./prisma/schema.prisma"><code>./prisma/schema.prisma</code></a></td> | ||
<td>Prisma schema</td> | ||
</tr> | ||
<tr> | ||
<td><a href="./src/pages/api/trpc/[trpc].ts"><code>./src/pages/api/trpc/[trpc].ts</code></a></td> | ||
<td>tRPC response handler</td> | ||
</tr> | ||
<tr> | ||
<td><a href="./src/server/routers"><code>./src/server/routers</code></a></td> | ||
<td>Your app's different tRPC-routers</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
--- | ||
|
||
Created by [@alexdotjs](https://twitter.com/alexdotjs). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// @ts-check | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const { env } = require('./src/server/env'); | ||
|
||
/** | ||
* Don't be scared of the generics here. | ||
* All they do is to give us autocompletion when using this. | ||
* | ||
* @template {import('next').NextConfig} T | ||
* @param {T} config - A generic parameter that flows through to the return type | ||
* @constraint {{import('next').NextConfig}} | ||
*/ | ||
function getConfig(config) { | ||
return config; | ||
} | ||
|
||
/** | ||
* @link https://nextjs.org/docs/api-reference/next.config.js/introduction | ||
*/ | ||
module.exports = getConfig({ | ||
/** | ||
* Dynamic configuration available for the browser and server. | ||
* Note: requires `ssr: true` or a `getInitialProps` in `_app.tsx` | ||
* @link https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration | ||
*/ | ||
publicRuntimeConfig: { | ||
NODE_ENV: env.NODE_ENV, | ||
}, | ||
/** We run eslint as a separate task in CI */ | ||
eslint: { ignoreDuringBuilds: !!process.env.CI }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"name": "@examples/trpc-next-prisma-starter", | ||
"version": "10.27.3", | ||
"private": true, | ||
"scripts": { | ||
"generate": "prisma generate", | ||
"prisma-studio": "prisma studio", | ||
"db-seed": "prisma db seed", | ||
"db-reset": "prisma migrate dev reset", | ||
"dx:next": "run-s migrate-dev db-seed && next dev", | ||
"dx:prisma-studio": "pnpm prisma-studio", | ||
"dx": "run-p dx:* --print-label", | ||
"dev": "pnpm dx:next", | ||
"prebuild": "run-s generate migrate", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "eslint --cache --ext \".js,.ts,.tsx\" --report-unused-disable-directives --report-unused-disable-directives src", | ||
"lint-fix": "pnpm lint --fix", | ||
"migrate-dev": "prisma migrate dev", | ||
"migrate": "prisma migrate deploy", | ||
"test": "run-s test:*", | ||
"test:unit": "vitest run", | ||
"test:e2e": "playwright test", | ||
"test-dev": "start-server-and-test dev http://127.0.0.1:3000 test", | ||
"test-start": "start-server-and-test start http://127.0.0.1:3000 test", | ||
"postinstall": "pnpm generate" | ||
}, | ||
"prisma": { | ||
"seed": "tsx prisma/seed.ts" | ||
}, | ||
"prettier": { | ||
"printWidth": 80, | ||
"trailingComma": "all", | ||
"singleQuote": true | ||
}, | ||
"dependencies": { | ||
"@prisma/client": "^4.14.1", | ||
"@tanstack/react-query": "^4.18.0", | ||
"@trpc/client": "^10.27.3", | ||
"@trpc/next": "^10.27.3", | ||
"@trpc/react-query": "^10.27.3", | ||
"@trpc/server": "^10.27.3", | ||
"clsx": "^1.1.1", | ||
"next": "^13.4.3", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"superjson": "^1.7.4", | ||
"zod": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.26.1", | ||
"@types/node": "^18.7.20", | ||
"@types/react": "^18.2.6", | ||
"@typescript-eslint/eslint-plugin": "^5.59.2", | ||
"@typescript-eslint/parser": "^5.59.2", | ||
"eslint": "^8.40.0", | ||
"eslint-config-next": "^13.4.3", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-react": "^7.32.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.8.8", | ||
"prisma": "^4.14.1", | ||
"start-server-and-test": "^1.12.0", | ||
"tsx": "^3.12.7", | ||
"typescript": "^4.8.3", | ||
"vite": "^4.1.2", | ||
"vitest": "^0.28.5" | ||
}, | ||
"publishConfig": { | ||
"access": "restricted" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PlaywrightTestConfig, devices } from '@playwright/test'; | ||
|
||
const baseUrl = process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:3000'; | ||
console.log(`ℹ️ Using base URL "${baseUrl}"`); | ||
|
||
const opts = { | ||
// launch headless on CI, in browser locally | ||
headless: !!process.env.CI || !!process.env.PLAYWRIGHT_HEADLESS, | ||
// collectCoverage: !!process.env.PLAYWRIGHT_HEADLESS | ||
}; | ||
const config: PlaywrightTestConfig = { | ||
testDir: './playwright', | ||
timeout: 35e3, | ||
outputDir: './playwright/test-results', | ||
// 'github' for GitHub Actions CI to generate annotations, plus a concise 'dot' | ||
// default 'list' when running locally | ||
reporter: process.env.CI ? 'github' : 'list', | ||
use: { | ||
...devices['Desktop Chrome'], | ||
baseURL: baseUrl, | ||
headless: opts.headless, | ||
video: 'on', | ||
}, | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.