Skip to content

Commit

Permalink
Create trpc template
Browse files Browse the repository at this point in the history
  • Loading branch information
barbarbar338 committed May 4, 2024
1 parent e098653 commit 0484f38
Show file tree
Hide file tree
Showing 42 changed files with 5,230 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .env.example
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
25 changes: 25 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:react/recommended",
"plugin:react-hooks/recommended"
],
"reportUnusedDisableDirectives": true,
"parserOptions": {
"project": "tsconfig.json",
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"@typescript-eslint/consistent-type-definitions": "off",
"react/react-in-jsx-scope": "off",
"react/prop-types": "off"
},
"settings": {
"react": {
"version": "detect"
}
}
}
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: barbarbar338
7 changes: 7 additions & 0 deletions .github/dependabot.yml
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
106 changes: 106 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Testing
on: [push]
jobs:
e2e:
name: "Build + E2E tests"
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: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: pnpm/action-setup@v2
with:
version: 8.5.1

- uses: actions/setup-node@v3
with:
node-version: 20.x
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 }}-${{ hashFiles('**/pnpm-lock.yaml') }}-nextjs

- name: Setup Prisma
run: pnpm prebuild

- run: pnpm build
- run: pnpm test-e2e

- name: Check types
run: pnpm tsc

- name: Upload test results
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: test results
path: |
playwright/test-results
unit:
name: "Unit tests + typecheck"
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: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: pnpm/action-setup@v2
with:
version: 8.5.1

- uses: actions/setup-node@v3
with:
node-version: 20.x
cache: "pnpm" # You can active this cache when your repo has a lockfile

- name: Install deps (with cache)
run: pnpm install

- name: Next.js cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}-nextjs

- name: Setup Prisma
run: pnpm prebuild

- run: pnpm test-unit
- run: pnpm tsc
49 changes: 49 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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

# environment
*.env*
!.env.example

# prisma
migrations
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable-pre-post-scripts=true
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tabWidth": 4,
"useTabs": true,
"bracketSpacing": true,
"singleQuote": false,
"endOfLine": "crlf",
"trailingComma": "all",
"semi": true
}
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"prisma.prisma"
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# 🖥️ HastePaste App Website
# 🖥️ HastePaste

> Tried to make a free to use service for everyone but failed. It was a great experience to serve millions of people but it was not possible to continue it for free. Project gets more expensive as it grows. It was hard to find a sponsor for this project, everyone wanted to use it for free but no one wanted to pay for its expenses. It was afforable for me for a while but when the database and requests increased, everything became more expensive. It was a great experience to serve a free to use service, thanks.
>
> ~barbarbar338
A simple pastebin service made with NextJS, TRPC, Prisma, PostgreSQL and TailwindCSS.

Note: this is an old version of hastepaste, feel free to use it for your own projects.
Accessible at [hastepaste.xyz](https://hastepaste.xyz)
5 changes: 5 additions & 0 deletions next-env.d.ts
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.
22 changes: 22 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @ts-check
/* eslint-disable @typescript-eslint/no-var-requires */
const { env } = require("./src/server/env");

/**
* @template {import("next").NextConfig} T
* @param {T} config
* @constraint {{import("next").NextConfig}}
*/
function getConfig(config) {
return config;
}

module.exports = getConfig({
publicRuntimeConfig: {
NODE_ENV: env.NODE_ENV,
},
eslint: { ignoreDuringBuilds: !!process.env.CI },
typescript: {
ignoreBuildErrors: true,
},
});
72 changes: 72 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "hastepaste",
"version": "3.0.0-alpha.1",
"private": true,
"publishConfig": {
"access": "restricted"
},
"prisma": {
"seed": "tsx prisma/seed.ts"
},
"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": "yarn prisma-studio",
"dx": "run-p dx:* --print-label",
"dev": "yarn dx:next",
"prebuild": "run-s generate migrate",
"build": "next build",
"start": "next start",
"lint": "eslint --cache --ext \".js,.ts,.tsx\" src",
"lint-fix": "yarn lint --fix",
"migrate-dev": "prisma migrate dev",
"migrate": "prisma migrate deploy",
"test-unit": "vitest",
"test-e2e": "playwright test",
"test-start": "run-s test-unit test-e2e",
"postinstall": "yarn generate",
"format": "prettier --write .",
"update": "taze latest -w"
},
"dependencies": {
"@prisma/client": "^5.13.0",
"@tanstack/react-query": "^5.32.1",
"@trpc/client": "npm:@trpc/client@next",
"@trpc/next": "npm:@trpc/next@next",
"@trpc/react-query": "npm:@trpc/react-query@next",
"@trpc/server": "npm:@trpc/server@next",
"clsx": "^2.1.1",
"next": "^14.2.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"superjson": "^2.2.1",
"zod": "^3.23.6"
},
"devDependencies": {
"@playwright/test": "^1.43.1",
"@types/node": "^20.12.8",
"@types/react": "^18.3.1",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"autoprefixer": "^10.4.19",
"dotenv": "^16.4.5",
"eslint": "^9.2.0",
"eslint-config-next": "^14.2.3",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.38",
"prettier": "^3.2.5",
"prisma": "^5.13.0",
"start-server-and-test": "^2.0.3",
"tailwindcss": "^3.4.3",
"taze": "^0.13.8",
"tsx": "^4.9.0",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vitest": "^1.6.0"
}
}
24 changes: 24 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { PlaywrightTestConfig, devices } from "@playwright/test";

const opts = {
headless: !!process.env.CI || !!process.env.PLAYWRIGHT_HEADLESS,
};
const config: PlaywrightTestConfig = {
testDir: "./playwright",
timeout: 35e3,
outputDir: "./playwright/test-results",
reporter: process.env.CI ? "github" : "list",
use: {
...devices["Desktop Chrome"],
headless: opts.headless,
video: "on",
},
retries: process.env.CI ? 3 : 0,
webServer: {
command: process.env.CI ? "npm run start" : "npm run dev",
reuseExistingServer: Boolean(process.env.TEST_LOCAL === "1"),
port: 3000,
},
};

export default config;
22 changes: 22 additions & 0 deletions playwright/smoke.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test } from "@playwright/test";

test.setTimeout(35e3);

test("go to /", async ({ page }) => {
await page.goto("/");

await page.waitForSelector(`text=Starter`);
});

test("add a post", async ({ page }) => {
const nonce = `${Math.random()}`;

await page.goto("/");
await page.fill(`[name=title]`, nonce);
await page.fill(`[name=text]`, nonce);
await page.click(`form [type=submit]`);
await page.waitForLoadState("networkidle");
await page.reload();

await page.waitForSelector(`text="${nonce}"`);
});
6 changes: 6 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
Loading

0 comments on commit 0484f38

Please sign in to comment.