Skip to content
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
30 changes: 12 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- run: make setup-ci
- run: make build
- run: bun install
- run: bun run build

biome:
name: Code style check via Biome
Expand All @@ -53,8 +53,8 @@ jobs:
with:
version: latest

- run: make setup
- run: biome check
- run: bun install --frozen-lockfile
- run: bun style:check

type-check:
name: Type Check
Expand All @@ -64,12 +64,8 @@ jobs:
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- run: make setup-ci

- run: bunx tsc --noEmit
working-directory: web
- run: bunx tsc --noEmit
working-directory: server
- run: bun install --frozen-lockfile
- run: bun type

spell-check:
name: Spell Check
Expand All @@ -80,8 +76,8 @@ jobs:
with:
bun-version: latest

- run: make setup-ci
- run: bunx cspell --quiet .
- run: bun install --frozen-lockfile
- run: bun spell .

test:
name: Bun Test
Expand All @@ -90,24 +86,22 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: make setup-ci
- run: make test
- run: bun install --frozen-lockfile
- run: bun run test

deploy-test-web:
name: Deploy Test (web)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: oven-sh/setup-bun@v2
- run: make prepare-deploy-web
- run: bun prepare:deploy:web
- run: test `ls web/.next | wc -l` != 0

deploy-test-server:
name: Deploy Test (server)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: oven-sh/setup-bun@v2
- run: make prepare-deploy-server
- run: bun prepare:deploy:server
14 changes: 5 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/node_modules
.env
/.direnv
/.husky

# Logs
logs
*.log
Expand All @@ -7,11 +12,6 @@ yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
Expand All @@ -22,7 +22,3 @@ dist-ssr
*.njsproj
*.sln
*.sw?

.env
/.direnv
.husky
128 changes: 3 additions & 125 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,15 @@ default: start

LOCAL_DB := postgres://user:password@localhost:5432/database

setup:
if [ ! `command -v bun` ]; then echo 'ERR: Bun is required!'; exit 1; fi
make sync
@echo "auto setup is done. now do:"
@echo "- edit server/.env.dev"
@echo "- edit web/.env"
@echo "- run make sync"

setup-ci:
if [ "" == ${DATABASE_URL} ]; then echo 'Please set DATABASE_URL_FOR_SQL_GENERATION!'; exit 1; fi
make sync
make generate-sql

sync: sync-server sync-web sync-root sync-common
@echo '----------------------------------------------------------------------------------------------------------'
@echo '| Most work is done. now running prisma-generate-sql (which might fail if .env.dev is not set configured)|'
@echo '----------------------------------------------------------------------------------------------------------'
make generate-sql || true

generate-sql:
@cd server; bunx dotenv -e .env.dev -- bunx prisma generate --sql

start: start-all # build -> serve
build: build-server build-web
serve: serve-all # serve only. does not build.
watch:
(trap 'kill 0' EXIT; make watch-web & make watch-server & wait)


test: export DATABASE_URL=$(LOCAL_DB)
test: export NEVER_LOAD_DOTENV=1
test: export UNSAFE_SKIP_AUTH=1
test: export FIREBASE_PROJECT_ID=mock-proj
test: export CORS_ALLOW_ORIGINS=http://localhost:3000,https://localhost:5173
test: dev-db
cd server/src; ENV_FILE=../.env.dev bun test
cd ./test; ENV_FILE=../server/.env.dev bun test
cd server/src; ENV_FILE=none bun test
cd ./test; ENV_FILE=none bun test
docker stop postgres

prepare-deploy-web: sync-common
cd web; bun install; bun run build
deploy-web:
@if [ "${PORT}" == "" ]; then echo 'env PORT not found!'; exit 1; fi
cd web; bun next start --port ${PORT}
prepare-deploy-server: sync-common sync-server generate-sql
deploy-server:
cd server; bun src/main.ts

docker:
@# deferring `docker compose down`. https://qiita.com/KEINOS/items/532dc395fe0f89c2b574
trap 'docker compose down' EXIT; docker compose up --build

docker-watch:
docker compose up --build --watch

seed:
cd server; bunx prisma db seed

## server/.envをDATABASE_URL=postgres://user:password@localhost:5432/databaseにしてから行う
dev-db: export DATABASE_URL=$(LOCAL_DB)
dev-db: export NEVER_LOAD_DOTENV=1
Expand All @@ -79,79 +30,6 @@ dev-db:
done
@echo "PostgreSQL is ready. Running seed..."
@cd server; bunx prisma generate; bunx prisma db push
@make seed
@bun run seed
@echo "Seeding completed."

# Sync (install/update packages, generate prisma, etc)

sync-web:
cd web; bun install
# copy .env.sample -> .env only if .env is not there

sync-server:
cd server; bun install --frozen-lockfile
cd server; bun prisma generate
# copy .env.sample -> .env only if .env is not there

sync-root:
bun install
sync-common:
cd common; bun install


# Static checks

## code style
style:
if command -v biome; then biome check --write; else bunx @biomejs/biome check --write; fi
style-check:
if command -v biome; then biome check; else bunx @biomejs/biome check; fi

## Deprecated commands, there warnings will be deleted in the future
lint:
@echo 'DEPRECATED: `make lint` is deprecated. run `make style` instead.'
@exit 1

format:
@echo 'DEPRECATED: `make format` is deprecated. run `make style` instead.'
@exit 1

format-check:
@echo 'DEPRECATED: `make format-check` is deprecated. run `make style-check` instead.'
@exit 1

# type checks
type-check:
make type-check-server
make type-check-web

type-check-server:
cd server; bunx tsc --noEmit

type-check-web:
cd web; bunx tsc --noEmit


# Runner

start-all: build-web build-server
make serve-all

build-web:
cd web; bun run build
build-server:
cd server; bun run build

serve-all:
(trap 'kill 0' EXIT; make serve-web & make serve-server & wait)
serve-web:
cd web; bun run preview # todo: make serve function
serve-server:
cd server; bun run serve

watch-web:
cd web; bun run dev
watch-server:
cd server; bun run dev

.PHONY: test
3 changes: 0 additions & 3 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"name": "course-mate",
"devDependencies": {
"@biomejs/biome": "^1.9.1",
"husky": "^9.1.4",
"lefthook": "^1.10.10",
"lint-staged": "^15.2.10",
},
Expand Down Expand Up @@ -824,8 +823,6 @@

"human-signals": ["[email protected]", "", {}, "sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ=="],

"husky": ["[email protected]", "", { "bin": { "husky": "bin.js" } }, "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA=="],

"iconv-lite": ["[email protected]", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3" } }, "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA=="],

"idb": ["[email protected]", "", {}, "sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ=="],
Expand Down
2 changes: 1 addition & 1 deletion lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ pre-commit:
run: if [ "$(git branch --show-current)" == "main" ]; then echo "Cannot make commit on main! aborting..."; exit 1; fi
cspell:
glob: "*"
run: bunx cspell --quiet .
run: bun run spell
25 changes: 22 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,35 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "lefthook install"
"prepare": "lefthook install && (cd server; bun run prepare)",
"check": "bun type && bun style:check",
"style": "biome check . --fix",
"style:check": "biome check .",
"type": "bun type:web && bun type:server && bun type:common",
"type:web": "cd web; bun run tsc",
"type:server": "cd server; bun run tsc",
"type:common": "cd common; bun run tsc",
"build": "bun run build:server && bun run build:web",
"build:web": "cd web; bun run build",
"build:server": "cd server; bun run build",
"watch": "trap 'kill 0' EXIT; bun run watch:web & bun run watch:server & wait",
"watch:web": "cd web; bun run dev",
"watch:server": "cd server; bun run dev",
"seed": "cd server; bun prisma db seed",
"prepare:deploy:web": "bun install --frozen-lockfile && bun run build:web",
"prepare:deploy:server": "bun install --frozen-lockfile",
"deploy:web": "cd web; bun run start --port $PORT",
"deploy:server": "cd server; bun run src/main.ts",
"dev-db": "make dev-db",
"test": "make test",
"spell": "bunx cspell --quiet ."
},
"keywords": [],
"author": "",
"license": "ISC",
"workspaces": ["common", "web", "server"],
"devDependencies": {
"@biomejs/biome": "^1.9.1",
"husky": "^9.1.4",
"lefthook": "^1.10.10",
"lint-staged": "^15.2.10"
},
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "bun --env-file=./.env.dev prisma generate --sql || (echo 'please set DATABASE_URL in server/.env.dev' && exit 1)",
"dev": "bun --watch src/main.ts",
"build": "tsc",
"serve": "bun target/main.js"
Expand Down
23 changes: 11 additions & 12 deletions server/src/seeds/seed-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import {
} from "./test-data/data";

async function main() {
await Promise.all(
subjects.map(async ({ group, subjects }) => {
for (const [name] of subjects) {
await prisma.interestSubject.create({
data: {
name,
group,
},
});
}
}),
);
// avoid flaky tests. don't replace this with Promise.all
for (const { group, subjects: subject } of subjects) {
for (const [name] of subject) {
await prisma.interestSubject.create({
data: {
name,
group,
},
});
}
}

await Promise.all(
users.map(async (user) => {
Expand Down
17 changes: 7 additions & 10 deletions server/src/seeds/seed.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { prisma } from "../database/client";
import { subjects } from "./data/subjects";

const promises: Array<Promise<unknown>> = [];
for (const subjectGroup of subjects) {
const group = subjectGroup.group;
for (const name of subjectGroup.subjects) {
promises.push(
prisma.interestSubject.upsert({
where: {
name_group: { name, group },
},
update: { name, group },
create: { name, group },
}),
);
await prisma.interestSubject.upsert({
where: {
name_group: { name, group },
},
update: { name, group },
create: { name, group },
});
}
}