Files

69 lines
2.0 KiB
Makefile
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
SHELL := /bin/bash
GO ?= go
PNPM ?= pnpm
ADDR ?= :8080
.PHONY: help deps web server dev start build test clean db-reset stop logs
help:
@echo "ONE · 一个博客"
@echo ""
@echo " make dev 前后端一起起(后端 8080,前端 3000 带热更新)"
@echo " make web 只构建前端到 frontend/dist"
@echo " make server 只起后端(8080)"
@echo " make start 构建前端 + 单端口启动(8080 同时服务前后端)"
@echo " make deps 安装前后端依赖"
@echo " make test 跑后端测试"
@echo " make stop 停掉 make dev 起的两个进程"
@echo " make logs 看 dev 进程日志"
@echo " make clean 清理构建产物"
@echo " make db-reset 删掉本地 SQLite 库(会清空数据)"
deps:
cd backend && $(GO) mod download
cd frontend && $(PNPM) install
web:
cd frontend && $(PNPM) run build
server:
cd backend && ONE_ADDR=$(ADDR) $(GO) run .
# 一条命令起后端 + 前端(开发用,两个进程)
# 输出写进 .run/*.log,避免后台进程占住终端导致命令不返回
dev:
@mkdir -p .run
@(cd backend && { ONE_ADDR=$(ADDR) $(GO) run . > ../.run/server.log 2>&1 & echo $$! > ../.run/server.pid; })
@(cd frontend && { $(PNPM) run dev > ../.run/web.log 2>&1 & echo $$! > ../.run/web.pid; })
@echo "后端 http://localhost:8080 (日志 .run/server.log)"
@echo "前端 http://localhost:3000 (日志 .run/web.log)"
@echo "停止:make stop 看日志:make logs"
# 生产式单端口:构建前端,由 Go 静态托管
start: web
cd backend && ONE_ADDR=$(ADDR) $(GO) run .
build: web
cd backend && $(GO) build -o ../one-server .
test:
cd backend && $(GO) test ./...
stop:
@for f in .run/server.pid .run/web.pid; do \
if [ -f $$f ]; then pid=$$(cat $$f); \
pkill -P $$pid 2>/dev/null; kill $$pid 2>/dev/null; \
fi; \
done
@rm -f .run/*.pid
@echo stopped
logs:
@tail -f .run/server.log .run/web.log
clean:
rm -rf frontend/dist one-server .run
db-reset:
rm -f data/one.db data/one.db-wal data/one.db-shm