Skip to content

Commit

Permalink
chore: add readms
Browse files Browse the repository at this point in the history
* chore: update apps and packages list and add installation instructions

* docs: add commands for database migration, HTTP client generation, and email template generation

* chore: update testing scripts and configurations

* docs: update email template generation path in README
  • Loading branch information
typeWolffo authored Aug 7, 2024
1 parent 6fd0cd5 commit f958efe
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 52 deletions.
137 changes: 87 additions & 50 deletions examples/common_nestjs_remix/README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,118 @@
# Turborepo starter
### Apps and Packages

- apps
- `api`: a NestJS backend application working as API
- `web`: a Vite Remix SPA
- `reverse-proxy`: for domains and https during development
- packages
- `email-templates`: a package for email templates
- `eslint-config`: a package for eslint configuration
- `typescript-config`: a package for typescript configuration

This is an official starter Turborepo.
### Install

## Using this example
To start with the setup make sure you have the correct NodeJS version stated in [.tool-versions](./.tool-versions).
For the node versioning we recommend [asdf](https://asdf-vm.com/). At the time of writing this readme the version is `20.15.0`

Run the following command:
After these steps, run the following command

```sh
npx create-turbo@latest
pnpm install
```

## What's inside?
Now to configure our reverse proxy we need to install [Caddy](https://caddyserver.com/docs/install#homebrew-mac). You
can do this using `homebrew` on mac.

This Turborepo includes the following packages/apps:
> [!IMPORTANT]
> First run has to be run by hand to configure caddy. Later on it will automatically
> start with the app start script.
### Apps and Packages
To do that proceed with the following

- `docs`: a [Next.js](https://nextjs.org/) app
- `web`: another [Next.js](https://nextjs.org/) app
- `@repo/ui`: a stub React component library shared by both `web` and `docs` applications
- `@repo/eslint-config`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
- `@repo/typescript-config`: `tsconfig.json`s used throughout the monorepo

Each package/app is 100% [TypeScript](https://www.typescriptlang.org/).
```sh
cd ./apps/reverse-proxy
caddy run
```

### Utilities
After running caddy proceed with the on screen instructions.

This Turborepo has some additional tools already setup for you:
Last step is to go our NestJS app and configure its environmental variables and docker.
So being in `guidebook/apps/api` run the following command

- [TypeScript](https://www.typescriptlang.org/) for static type checking
- [ESLint](https://eslint.org/) for code linting
- [Prettier](https://prettier.io) for code formatting
```sh
cp .env.example .env
docker-compose up -d
```

### Build
### Migrations

To build all apps and packages, run the following command:
Once the docker is up and running we need to run the migrations. To do that run the following command

```
cd my-turborepo
pnpm build
```sh
pnpm db:migrate
```

### Develop

To develop all apps and packages, run the following command:
Now in the main directory once you run `pnpm dev` it will run everything in parallel
and you should be abble to acces your app on the following adresses!

```
cd my-turborepo
pnpm dev
```
| Service | URL |
| ------- | ---------------------------------------------------------------------------- |
| Web app | [ https://app.guidebook.localhost ](https://app.guidebook.localhost) |
| Api | [https://api.guidebook.localhost ](https://api.guidebook.localhost) |
| Swagger | [ https://api.guidebook.localhost/api ](https://api.guidebook.localhost/api) |

### Remote Caching
### Commands

Turborepo can use a technique known as [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching) to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.
- #### Database

By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can [create one](https://vercel.com/signup), then enter the following commands:
- generate migration

```
cd my-turborepo
npx turbo login
```
```sh
pnpm db:generate
```

This will authenticate the Turborepo CLI with your [Vercel account](https://vercel.com/docs/concepts/personal-accounts/overview).
- run migrations
```sh
pnpm db:migrate
```
> [!IMPORTANT]
> Once migration is generated chagne its name to something more descriptive.
> Also make sure to change the migration name in [\_journal.json](apps/api/src/storage/migrations/meta/_journal.json) file under the `tag` key.

Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your Turborepo:
- #### HTTP Client

```
npx turbo link
```
To generate the http client run the following command.

```sh
pnpm generate:client
```

This command automates the process of creating a TypeScript client for the API based on the Swagger specification.

- #### Email Templates

Email templates are generated on every start of turborepo. To generate them manually run the following command in `packages/email-templates`.

## Useful Links
```sh
pnpm build
```

Learn more about the power of Turborepo:
The mailhog service is available at [mailbox.guidebook.localhost](mailbox.guidebook.localhost)

- [Tasks](https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks)
- [Caching](https://turbo.build/repo/docs/core-concepts/caching)
- [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching)
- [Filtering](https://turbo.build/repo/docs/core-concepts/monorepos/filtering)
- [Configuration Options](https://turbo.build/repo/docs/reference/configuration)
- [CLI Usage](https://turbo.build/repo/docs/reference/command-line-reference)
- #### Testing
- **Frontend**:
```sh
pnpm test:web
```
```sh
pnpm test:web:e2e
```
- **Backend**:
```sh
pnpm test:api
```
```sh
pnpm test:api:e2e
```
2 changes: 1 addition & 1 deletion examples/common_nestjs_remix/apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"build": "remix vite:build",
"dev": "vite dev",
"dev_ssr": "node ./server.js",
"test": "vitest",
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
"start": "cross-env NODE_ENV=production node ./server.js",
"generate:client": "swagger-typescript-api -p ../api/src/swagger/api-schema.json -o ./app/api --axios --name generated-api.ts --api-class-name API",
"tsc": "tsc --noEmit",
"test": "vitest",
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui"
},
Expand Down
6 changes: 5 additions & 1 deletion examples/common_nestjs_remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"generate:client": "pnpm run --filter=web generate:client",
"db:generate": "pnpm run --filter=api db:generate",
"db:migrate": "pnpm run --filter=api db:migrate"
"db:migrate": "pnpm run --filter=api db:migrate",
"test:web": "pnpm run --filter=web test",
"test:api": "pnpm run --filter=api test",
"test:web:e2e": "pnpm run --filter=web test:e2e",
"test:api:e2e": "pnpm run --filter=api test:e2e"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
Expand Down

0 comments on commit f958efe

Please sign in to comment.