Skip to content

Latest commit

 

History

History
217 lines (141 loc) · 5.17 KB

LOCAL.md

File metadata and controls

217 lines (141 loc) · 5.17 KB

Local Setup

Join the Trash Discord

To contribute you will first need to fork the repo and make some adjustments to get it up and running on your local machine. Below are the steps to follow for you to get TypeHero to run on your local machine.

1. Create a .env file

Provide your values as needed.

2 Configure your database

You can either use PlanetScale or a local Docker container to run your database. Use either 2.a or 2.b for the next step.

2.a Local Database (using Docker)

Starting the docker container

docker compose up -d

2.b Remote Database (using PlanetScale)

Follow the PlanetScale quick start guide to get started

After creating an account and creating a database using the steps above:

  1. Click either the big "Connect" button or the "connect to your database" Link. connect

  2. Select "Connect with Prisma" and copy the DATABASE_URL for your .env getting the connection string

3. Create a new GitHub OAuth Application

Follow this link to create a new app filling the following required details on creation:

Homepage URL: http://localhost:3000
Authorization callback URL: http://localhost:3000/api/auth/callback/github

Once completed, you will be redirected to the application page settings, from there create the client secret by clicking on Generate a new client secret button.

Next, copy the client secret generated and the client ID into the .env file, replacing <client_id> and <client_secret>, respectively:

GITHUB_ID=<client_id>
GITHUB_SECRET=<client_secret>

4. Setup uploadthing for file uploads

Go to uploadthing.com and create a project, then copy in the secrets into your .env.

In the end your local .env file should look something like the following

DATABASE_URL="mysql://dev:dev@localhost/typehero"
GITHUB_ID=very_real_github_id
GITHUB_SECRET=very_real_secret

UPLOADTHING_SECRET="very_real_uploadthing_secret"
UPLOADTHING_APP_ID="very_real_uploadthing_app_id"
# Next Auth
# You can generate a new secret on the command line with:
# openssl rand -base64 32
# https://next-auth.js.org/configuration/options#secret
NEXTAUTH_SECRET="for local use you can just use a garble of letters"
NEXTAUTH_URL="http://localhost:3000"

5. Install dependencies

Use pnpm to install dependencies.

pnpm install

6. Push Database Schema and Seed

pnpm db:push
pnpm db:seed

7. Running the dev server

Finally, you can run the dev server:

pnpm dev

Sync data

Once the server is running you can seed and sync data

  1. Navigate to http://localhost:3000/api/auth/github to authenticate with GitHub OAuth.

Make Yourself an Admin

  1. Ensure you have logged into your local instance atleast once

  2. Run pnpm db:studio - to open Prisma Studio

    prisma studio

  3. Click on the User table from the list of models

  4. Locate your username and open record in new tab to modify Role

    modify role

Dependencies

UI Library: shadcn

Testing

1. Install Playwright Dependencies

pnpm test:e2e:install

2. Run E2E Tests

You can use the production server or the dev server to run the e2e tests.

Warning

The dev server may cause tests to timeout.

2.a Production server

Playwright will automatically start the production server

pnpm build && pnpm test:e2e

2.b Dev server

Open two separate terminals and run the following commands in each one:

Terminal 1:

pnpm dev

Terminal 2:

pnpm test:e2e

FAQ

How do I totally rebuild and re-seed the database?

Run the command

pnpm refresh

This will cause Prisma to force reset the database through the db:reset command and then run db:seed.

What if I run into errors with that command? If you are using the docker setup for your local environment then get into the container with
docker exec -it typehero-db bash
# we are in the container from here on
$ mysql -u dev -p -h 127.0.0.1 typehero
> drop database typehero;

Exit out of the container and then run

pnpm refresh

This tends to resolve the issue as it entirely destroys and rebuilds + reseeds the database.

How do I use the `@vercel/toolbar` locally? If you have access to the vercel project then you can run `vercel link` (make sure you have the vercel CLI).

Follow the interactive CLI to link it to the Trash Company/typehero project.

From there on out you should be able to read and make comments while on local host for that branch.