Skip to content

Commit e2ef12d

Browse files
authored
migrate most scripts from make to bun (#643)
1 parent 349bb27 commit e2ef12d

File tree

9 files changed

+62
-182
lines changed

9 files changed

+62
-182
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
- uses: oven-sh/setup-bun@v2
3939
with:
4040
bun-version: latest
41-
- run: make setup-ci
42-
- run: make build
41+
- run: bun install
42+
- run: bun run build
4343

4444
biome:
4545
name: Code style check via Biome
@@ -53,8 +53,8 @@ jobs:
5353
with:
5454
version: latest
5555

56-
- run: make setup
57-
- run: biome check
56+
- run: bun install --frozen-lockfile
57+
- run: bun style:check
5858

5959
type-check:
6060
name: Type Check
@@ -64,12 +64,8 @@ jobs:
6464
- uses: oven-sh/setup-bun@v2
6565
with:
6666
bun-version: latest
67-
- run: make setup-ci
68-
69-
- run: bunx tsc --noEmit
70-
working-directory: web
71-
- run: bunx tsc --noEmit
72-
working-directory: server
67+
- run: bun install --frozen-lockfile
68+
- run: bun type
7369

7470
spell-check:
7571
name: Spell Check
@@ -80,8 +76,8 @@ jobs:
8076
with:
8177
bun-version: latest
8278

83-
- run: make setup-ci
84-
- run: bunx cspell --quiet .
79+
- run: bun install --frozen-lockfile
80+
- run: bun spell .
8581

8682
test:
8783
name: Bun Test
@@ -90,24 +86,22 @@ jobs:
9086
steps:
9187
- uses: actions/checkout@v4
9288
- uses: oven-sh/setup-bun@v2
93-
- run: make setup-ci
94-
- run: make test
89+
- run: bun install --frozen-lockfile
90+
- run: bun run test
9591

9692
deploy-test-web:
9793
name: Deploy Test (web)
9894
runs-on: ubuntu-latest
9995
steps:
10096
- uses: actions/checkout@v4
101-
- uses: actions/setup-node@v3
10297
- uses: oven-sh/setup-bun@v2
103-
- run: make prepare-deploy-web
98+
- run: bun prepare:deploy:web
10499
- run: test `ls web/.next | wc -l` != 0
105100

106101
deploy-test-server:
107102
name: Deploy Test (server)
108103
runs-on: ubuntu-latest
109104
steps:
110105
- uses: actions/checkout@v4
111-
- uses: actions/setup-node@v3
112106
- uses: oven-sh/setup-bun@v2
113-
- run: make prepare-deploy-server
107+
- run: bun prepare:deploy:server

.gitignore

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/node_modules
2+
.env
3+
/.direnv
4+
/.husky
5+
16
# Logs
27
logs
38
*.log
@@ -7,11 +12,6 @@ yarn-error.log*
712
pnpm-debug.log*
813
lerna-debug.log*
914

10-
node_modules
11-
dist
12-
dist-ssr
13-
*.local
14-
1515
# Editor directories and files
1616
.vscode/*
1717
!.vscode/extensions.json
@@ -22,7 +22,3 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25-
26-
.env
27-
/.direnv
28-
.husky

Makefile

Lines changed: 3 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,15 @@ default: start
22

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

5-
setup:
6-
if [ ! `command -v bun` ]; then echo 'ERR: Bun is required!'; exit 1; fi
7-
make sync
8-
@echo "auto setup is done. now do:"
9-
@echo "- edit server/.env.dev"
10-
@echo "- edit web/.env"
11-
@echo "- run make sync"
12-
13-
setup-ci:
14-
if [ "" == ${DATABASE_URL} ]; then echo 'Please set DATABASE_URL_FOR_SQL_GENERATION!'; exit 1; fi
15-
make sync
16-
make generate-sql
17-
18-
sync: sync-server sync-web sync-root sync-common
19-
@echo '----------------------------------------------------------------------------------------------------------'
20-
@echo '| Most work is done. now running prisma-generate-sql (which might fail if .env.dev is not set configured)|'
21-
@echo '----------------------------------------------------------------------------------------------------------'
22-
make generate-sql || true
23-
24-
generate-sql:
25-
@cd server; bunx dotenv -e .env.dev -- bunx prisma generate --sql
26-
27-
start: start-all # build -> serve
28-
build: build-server build-web
29-
serve: serve-all # serve only. does not build.
30-
watch:
31-
(trap 'kill 0' EXIT; make watch-web & make watch-server & wait)
32-
33-
345
test: export DATABASE_URL=$(LOCAL_DB)
35-
test: export NEVER_LOAD_DOTENV=1
366
test: export UNSAFE_SKIP_AUTH=1
377
test: export FIREBASE_PROJECT_ID=mock-proj
388
test: export CORS_ALLOW_ORIGINS=http://localhost:3000,https://localhost:5173
399
test: dev-db
40-
cd server/src; ENV_FILE=../.env.dev bun test
41-
cd ./test; ENV_FILE=../server/.env.dev bun test
10+
cd server/src; ENV_FILE=none bun test
11+
cd ./test; ENV_FILE=none bun test
4212
docker stop postgres
4313

44-
prepare-deploy-web: sync-common
45-
cd web; bun install; bun run build
46-
deploy-web:
47-
@if [ "${PORT}" == "" ]; then echo 'env PORT not found!'; exit 1; fi
48-
cd web; bun next start --port ${PORT}
49-
prepare-deploy-server: sync-common sync-server generate-sql
50-
deploy-server:
51-
cd server; bun src/main.ts
52-
53-
docker:
54-
@# deferring `docker compose down`. https://qiita.com/KEINOS/items/532dc395fe0f89c2b574
55-
trap 'docker compose down' EXIT; docker compose up --build
56-
57-
docker-watch:
58-
docker compose up --build --watch
59-
60-
seed:
61-
cd server; bunx prisma db seed
62-
6314
## server/.envをDATABASE_URL=postgres://user:password@localhost:5432/databaseにしてから行う
6415
dev-db: export DATABASE_URL=$(LOCAL_DB)
6516
dev-db: export NEVER_LOAD_DOTENV=1
@@ -79,79 +30,6 @@ dev-db:
7930
done
8031
@echo "PostgreSQL is ready. Running seed..."
8132
@cd server; bunx prisma generate; bunx prisma db push
82-
@make seed
33+
@bun run seed
8334
@echo "Seeding completed."
8435

85-
# Sync (install/update packages, generate prisma, etc)
86-
87-
sync-web:
88-
cd web; bun install
89-
# copy .env.sample -> .env only if .env is not there
90-
91-
sync-server:
92-
cd server; bun install --frozen-lockfile
93-
cd server; bun prisma generate
94-
# copy .env.sample -> .env only if .env is not there
95-
96-
sync-root:
97-
bun install
98-
sync-common:
99-
cd common; bun install
100-
101-
102-
# Static checks
103-
104-
## code style
105-
style:
106-
if command -v biome; then biome check --write; else bunx @biomejs/biome check --write; fi
107-
style-check:
108-
if command -v biome; then biome check; else bunx @biomejs/biome check; fi
109-
110-
## Deprecated commands, there warnings will be deleted in the future
111-
lint:
112-
@echo 'DEPRECATED: `make lint` is deprecated. run `make style` instead.'
113-
@exit 1
114-
115-
format:
116-
@echo 'DEPRECATED: `make format` is deprecated. run `make style` instead.'
117-
@exit 1
118-
119-
format-check:
120-
@echo 'DEPRECATED: `make format-check` is deprecated. run `make style-check` instead.'
121-
@exit 1
122-
123-
# type checks
124-
type-check:
125-
make type-check-server
126-
make type-check-web
127-
128-
type-check-server:
129-
cd server; bunx tsc --noEmit
130-
131-
type-check-web:
132-
cd web; bunx tsc --noEmit
133-
134-
135-
# Runner
136-
137-
start-all: build-web build-server
138-
make serve-all
139-
140-
build-web:
141-
cd web; bun run build
142-
build-server:
143-
cd server; bun run build
144-
145-
serve-all:
146-
(trap 'kill 0' EXIT; make serve-web & make serve-server & wait)
147-
serve-web:
148-
cd web; bun run preview # todo: make serve function
149-
serve-server:
150-
cd server; bun run serve
151-
152-
watch-web:
153-
cd web; bun run dev
154-
watch-server:
155-
cd server; bun run dev
156-
157-
.PHONY: test

bun.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"name": "course-mate",
66
"devDependencies": {
77
"@biomejs/biome": "^1.9.1",
8-
"husky": "^9.1.4",
98
"lefthook": "^1.10.10",
109
"lint-staged": "^15.2.10",
1110
},
@@ -829,8 +828,6 @@
829828

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

832-
"husky": ["[email protected]", "", { "bin": { "husky": "bin.js" } }, "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA=="],
833-
834831
"iconv-lite": ["[email protected]", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3" } }, "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA=="],
835832

836833
"idb": ["[email protected]", "", {}, "sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ=="],

lefthook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ pre-commit:
1313
run: if [ "$(git branch --show-current)" == "main" ]; then echo "Cannot make commit on main! aborting..."; exit 1; fi
1414
cspell:
1515
glob: "*"
16-
run: bunx cspell --quiet .
16+
run: bun run spell

package.json

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,35 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
8-
"prepare": "lefthook install"
7+
"prepare": "lefthook install && (cd server; bun run prepare)",
8+
"check": "bun type && bun style:check",
9+
"style": "biome check . --fix",
10+
"style:check": "biome check .",
11+
"type": "bun type:web && bun type:server && bun type:common",
12+
"type:web": "cd web; bun run tsc",
13+
"type:server": "cd server; bun run tsc",
14+
"type:common": "cd common; bun run tsc",
15+
"build": "bun run build:server && bun run build:web",
16+
"build:web": "cd web; bun run build",
17+
"build:server": "cd server; bun run build",
18+
"watch": "trap 'kill 0' EXIT; bun run watch:web & bun run watch:server & wait",
19+
"watch:web": "cd web; bun run dev",
20+
"watch:server": "cd server; bun run dev",
21+
"seed": "cd server; bun prisma db seed",
22+
"prepare:deploy:web": "bun install --frozen-lockfile && bun run build:web",
23+
"prepare:deploy:server": "bun install --frozen-lockfile",
24+
"deploy:web": "cd web; bun run start --port $PORT",
25+
"deploy:server": "cd server; bun run src/main.ts",
26+
"dev-db": "make dev-db",
27+
"test": "make test",
28+
"spell": "bunx cspell --quiet ."
929
},
1030
"keywords": [],
1131
"author": "",
1232
"license": "ISC",
1333
"workspaces": ["common", "web", "server"],
1434
"devDependencies": {
1535
"@biomejs/biome": "^1.9.1",
16-
"husky": "^9.1.4",
1736
"lefthook": "^1.10.10",
1837
"lint-staged": "^15.2.10"
1938
},

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
7+
"prepare": "bun --env-file=./.env.dev prisma generate --sql || (echo 'please set DATABASE_URL in server/.env.dev' && exit 1)",
88
"dev": "bun --watch src/main.ts",
99
"build": "tsc",
1010
"serve": "bun target/main.js"

server/src/seeds/seed-test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ import {
99
} from "./test-data/data";
1010

1111
async function main() {
12-
await Promise.all(
13-
subjects.map(async ({ group, subjects }) => {
14-
for (const [name] of subjects) {
15-
await prisma.interestSubject.create({
16-
data: {
17-
name,
18-
group,
19-
},
20-
});
21-
}
22-
}),
23-
);
12+
// avoid flaky tests. don't replace this with Promise.all
13+
for (const { group, subjects: subject } of subjects) {
14+
for (const [name] of subject) {
15+
await prisma.interestSubject.create({
16+
data: {
17+
name,
18+
group,
19+
},
20+
});
21+
}
22+
}
2423

2524
await Promise.all(
2625
users.map(async (user) => {

server/src/seeds/seed.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import { prisma } from "../database/client";
22
import { subjects } from "./data/subjects";
33

4-
const promises: Array<Promise<unknown>> = [];
54
for (const subjectGroup of subjects) {
65
const group = subjectGroup.group;
76
for (const name of subjectGroup.subjects) {
8-
promises.push(
9-
prisma.interestSubject.upsert({
10-
where: {
11-
name_group: { name, group },
12-
},
13-
update: { name, group },
14-
create: { name, group },
15-
}),
16-
);
7+
await prisma.interestSubject.upsert({
8+
where: {
9+
name_group: { name, group },
10+
},
11+
update: { name, group },
12+
create: { name, group },
13+
});
1714
}
1815
}

0 commit comments

Comments
 (0)