Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use turbo #1

Merged
merged 12 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

39 changes: 14 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ jobs:
- name: 📥 Install Dependencies
run: pnpm install

- name: 📦 Build libs
run: pnpm build:ui

- name: 🔬 Lint
run: pnpm lint

Expand All @@ -86,9 +83,6 @@ jobs:
- name: 📥 Install Dependencies
run: pnpm install

- name: 📦 Build libs
run: pnpm build:ui

- name: 🔎 Type check
run: pnpm typecheck

Expand Down Expand Up @@ -143,7 +137,7 @@ jobs:
run: pnpm test:e2e

build:
name: 🏗️ Build apps
name: 🏗️ Build
needs: [changes]
runs-on: ubuntu-latest
steps:
Expand All @@ -164,8 +158,14 @@ jobs:
- name: 📥 Install Dependencies
run: pnpm install

- name: 🏗️ Build apps
run: pnpm build:apps
- name: 🏗️ Build
run: pnpm build

- uses: actions/upload-artifact@v3
if: needs.changes.outputs.docs == 'true'
with:
name: docs-artifacts
path: ./apps/docs/build

deploy-nestjs:
name: 🐯 Deploy NestJS App
Expand Down Expand Up @@ -217,26 +217,15 @@ jobs:
with:
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/[email protected]
- name: Download docs artifacts
uses: actions/download-artifact@v3
with:
version: 8

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm

- name: 📥 Install Dependencies
run: pnpm install

- name: 🏗️ Build
run: pnpm build:docs
name: docs-artifacts
path: ./build

- name: 🚀 Deploy to Chromatic
uses: chromaui/action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
storybookBuildDir: ./apps/docs/build
storybookBuildDir: ./build
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ node_modules
dist
build
public/build
.next

## Monorepo
.turbo

# Environment variables
.env
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto-install-peers = true
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"turbo.json": "jsonc"
}
}
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
- [x] build and deploy Storybook
- [x] set unified path aliases for all apps and shared libs (done for `apps/`, because `libs/` probably don't need them anyway)
- [x] add unused imports plugin to eslint
- [ ] research if it's worth using `turbo` - probably yes, to make it easier to run tasks that depend on each other
- [x] research if it's worth using `turbo` - probably yes, to make it easier to run tasks that depend on each other
- [ ] use turbo repo and ensure the following works
- [x] lint, test, build, develop
- [ ] gh actions
- [ ] deployment
- [ ] create diagram
- [ ] setup renovate

Expand All @@ -31,6 +35,37 @@
| Remix | https://pnpm-monorepo-remix.fly.dev/ |
| Docs (Storybook) | https://6562c63f0bbf6184dd3b3f1e-aulbjawzef.chromatic.com |

## Getting started

### Pre-requisites

- [pnpm](https://pnpm.io/installation)
- [Docker](https://docs.docker.com/get-docker/)

### Install dependencies

```sh
pnpm install
```

### Database

```sh
docker compose up mongo
```

### Run NestJS app

```sh
pnpm develop:nestjs
```

### Run Remix app

```sh
pnpm develop:remix
```

## References

- https://pnpm.io/next/filtering
Expand All @@ -41,4 +76,5 @@
- https://github.com/vercel/turbo/tree/main/examples - turbo repo examples
- https://github.com/storybookjs/storybook
- https://storybook.js.org/tutorials/design-systems-for-developers/react/en/architecture/
-
- https://turbo.build/repo/docs/getting-started/existing-monorepo
- https://github.com/vercel/style-guide/tree/canary
16 changes: 1 addition & 15 deletions apps/docs/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: [
'@repo/eslint-config/base',
'@repo/eslint-config/react',
'plugin:storybook/recommended',
],
overrides: [
{
files: ['*.stories.tsx'],
rules: {
// For some reason it shows errors for imports from @repo/ui, even though they are resolved correctly.
// Both develop and build work fine, so I'm disabling it for now.
'import/no-unresolved': 'off',
},
},
],
extends: ['@repo/eslint-config/storybook'],
}
4 changes: 3 additions & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"build": "storybook build -o build",
"start": "serve build",
"clean": "rm -rf .turbo && rm -rf node_modules",
"lint": "eslint ./stories/*.stories.tsx --max-warnings 0"
"lint": "eslint .",
"lint:fix": "pnpm lint --fix",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@repo/ui": "workspace:*",
Expand Down
15 changes: 1 addition & 14 deletions apps/docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"allowJs": true,
"declaration": false,
"declarationMap": false,
"incremental": true,
"jsx": "preserve",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"noEmit": true,
"resolveJsonModule": true,
"target": "es5",
"skipLibCheck": true
},
"extends": "@repo/tsconfig/react-app.json",
"include": ["."],
"exclude": ["dist", "build", "node_modules"]
}
8 changes: 8 additions & 0 deletions apps/docs/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": ["//"],
"pipeline": {
"build": {
"outputs": ["build/**"]
}
}
}
20 changes: 1 addition & 19 deletions apps/nestjs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ['@repo/eslint-config/base'],
env: {
node: true,
},
settings: {
'import/resolver': {
typescript: {
project: 'apps/nestjs/tsconfig.json',
},
},
},
overrides: [
{
files: ['jest.config.js', 'jest-e2e.config.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
],
extends: ['@repo/eslint-config/nest'],
}
3 changes: 0 additions & 3 deletions apps/nestjs/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module.exports = {
testEnvironment: 'node',
rootDir: './src',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: './coverage',
}
10 changes: 7 additions & 3 deletions apps/nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"build": "nest build",
"develop": "nest start --watch",
"develop:debug": "nest start --debug --watch",
"lint": "eslint .",
"lint:fix": "pnpm lint --fix",
"start": "node build/main",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.config.js"
"test:e2e": "jest --config ./test/jest-e2e.config.js",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
Expand All @@ -23,11 +26,12 @@
"rxjs": "^7.8.1"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@company/types": "workspace:*",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@repo/eslint-config": "workspace:*",
"@repo/tsconfig": "workspace:^",
"@repo/types": "workspace:*",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
Expand Down
3 changes: 2 additions & 1 deletion apps/nestjs/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing'
import type { TestingModule } from '@nestjs/testing'
import { Test } from '@nestjs/testing'

import { AppController } from './app.controller'
import { AppService } from './app.service'
Expand Down
6 changes: 4 additions & 2 deletions apps/nestjs/src/cats/cats.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Test, TestingModule } from '@nestjs/testing'
import type { TestingModule } from '@nestjs/testing'
import { Test } from '@nestjs/testing'

import { CatsController } from './cats.controller'
import { CatsService } from './cats.service'
import { CreateCatDto } from './dto/create-cat.dto'
import type { CreateCatDto } from './dto/create-cat.dto'

describe('Cats Controller', () => {
let controller: CatsController
Expand Down Expand Up @@ -84,6 +85,7 @@ describe('Cats Controller', () => {
age: 2,
},
])

expect(service.findAll).toHaveBeenCalled()
})
})
Expand Down
4 changes: 1 addition & 3 deletions apps/nestjs/src/cats/cats.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common'

import { CatsService } from './cats.service'
import { CreateCatDto } from './dto/create-cat.dto'
import { Cat } from './schemas/cat.schema'
import type { Cat } from './schemas/cat.schema'

@Controller('cats')
export class CatsController {
Expand All @@ -25,8 +25,6 @@ export class CatsController {

@Delete(':id')
async delete(@Param('id') id: string) {
console.log('id', id)

return this.catsService.delete(id)
}
}
7 changes: 4 additions & 3 deletions apps/nestjs/src/cats/cats.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getModelToken } from '@nestjs/mongoose'
import { Test, TestingModule } from '@nestjs/testing'
import { Model } from 'mongoose'
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing'
import type { Model } from 'mongoose'

import { CatsService } from './cats.service'
import { Cat } from './schemas/cat.schema'
import type { Cat } from './schemas/cat.schema'

const mockCat = {
name: 'Cat #1',
Expand Down
2 changes: 1 addition & 1 deletion apps/nestjs/src/cats/cats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Model } from 'mongoose'

import { CreateCatDto } from './dto/create-cat.dto'
import type { CreateCatDto } from './dto/create-cat.dto'
import { Cat } from './schemas/cat.schema'

@Injectable()
Expand Down
4 changes: 2 additions & 2 deletions apps/nestjs/src/cats/schemas/cat.schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Cat as CatInterface } from '@company/types'
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
import { HydratedDocument } from 'mongoose'
import type { Cat as CatInterface } from '@repo/types'
import type { HydratedDocument } from 'mongoose'

export type CatDocument = HydratedDocument<Cat>

Expand Down
2 changes: 1 addition & 1 deletion apps/nestjs/src/config/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { registerAs } from '@nestjs/config'

export type AppConfig = {
export interface AppConfig {
env: 'development' | 'production' | 'test'
port: number
}
Expand Down
3 changes: 2 additions & 1 deletion apps/nestjs/src/dogs/dogs.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing'
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing'

import { DogsController } from './dogs.controller'
import { DogsService } from './dogs.service'
Expand Down
2 changes: 1 addition & 1 deletion apps/nestjs/src/dogs/dogs.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dog } from '@company/types'
import { Controller, Get } from '@nestjs/common'
import type { Dog } from '@repo/types'

import { DogsService } from './dogs.service'

Expand Down
3 changes: 2 additions & 1 deletion apps/nestjs/src/dogs/dogs.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing'
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing'

import { DogsService } from './dogs.service'

Expand Down
2 changes: 1 addition & 1 deletion apps/nestjs/src/dogs/dogs.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dog } from '@company/types'
import { Injectable } from '@nestjs/common'
import type { Dog } from '@repo/types'

@Injectable()
export class DogsService {
Expand Down
Loading