Skip to content

Commit

Permalink
Merge pull request #1 from YAPP-Github/config/monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
leobang17 authored Jun 15, 2024
2 parents fd38019 + bbed95d commit 607e07d
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 16 deletions.
45 changes: 45 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# node_modules
node_modules
app/**/node_modules
libs/**/node_modules

# build output
dist
app/**/dist
# libs/**/dist

# dependency manager
.pnpm
.pnp
.pnp.js

# git
.git
.gitignore
*.md

# local dev configs
.vscode
.DS_Store
*.swp

# logs
Thumbs.db
*.tmp
*.log

# docker
Dockerfile
docker-compose.yml

# test & coverage reports
coverage
*.test.js
*.spec.js
*.test.ts
*.spec.ts

# env files
.env
.env.local
.env.*.local
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# compiled output
/dist
/node_modules
**/dist
**/node_modules
**/tsconfig.tsbuildinfo

# Logs
logs
Expand Down
35 changes: 35 additions & 0 deletions apps/Dockerfile.app
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

# Base Stage
FROM node:20-slim AS base

ARG PKG_NAME
ARG PORT

ENV PKG_NAME=$PKG_NAME
ENV PORT=$PORT
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN corepack enable

# Builder Stage
FROM base AS builder
WORKDIR /usr/src/app
COPY . .

# Install dependencies: with dependency cache
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

# Build shared libraries & Auth application
RUN pnpm --filter "libs/*" build
RUN pnpm --filter=$PKG_NAME build

# Remove unnecessary dependencies from production
RUN pnpm --filter=$PKG_NAME deploy --prod /prod

# Prod Stage
FROM base AS prod
COPY --from=builder /prod /prod
WORKDIR /prod
EXPOSE $PORT
CMD [ "node", "dist/main" ]
12 changes: 12 additions & 0 deletions apps/auth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@apps/auth",
"version": "1.0.0",
"dependencies": {
"@libs/common": "workspace:*"
},
"scripts": {
"start": "nest start",
"build": "nest build",
"test": "jest"
}
}
9 changes: 9 additions & 0 deletions apps/auth/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
15 changes: 15 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.8'

services:
auth:
image: 'hedwig/auth'
build:
context: .
dockerfile: ./apps/Dockerfile.app
args:
- PKG_NAME=@apps/auth
- PORT=3000
container_name: auth
ports:
- '3000:3000'
restart: 'no'
9 changes: 9 additions & 0 deletions libs/common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@libs/common",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc"
}
}
9 changes: 9 additions & 0 deletions libs/common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
{
"name": "yapp-web-2-server",
"name": "hedwig-server",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"start": "pnpm --recursive run start",
"build": "pnpm --recursive run build",
"auth": "pnpm -F @apps/auth",
"common": "pnpm -F @libs/common",
"format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/apps/yapp-web-2-server/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"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 ./apps/yapp-web-2-server/test/jest-e2e.json"
"test:e2e": "jest --config ./apps/hedwig-server/test/jest-e2e.json"
},
"workspaces": [
"apps/*",
"libs/*"
],
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
Expand Down Expand Up @@ -73,4 +76,4 @@
"^@app/common(|/.*)$": "<rootDir>/libs/common/src/$1"
}
}
}
}
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
- 'apps/*'
- 'libs/*'
12 changes: 4 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"paths": {
"@app/common": [
"libs/common/src"
],
"@app/common/*": [
"libs/common/src/*"
]
"@libs/common/*": ["libs/common/src/*"]
}
}
}
},
"include": ["apps/**/*", "libs/**/*"]
}

0 comments on commit 607e07d

Please sign in to comment.