refactor: Makefile 命名规范化,新增顶层便捷命令
统一命名规范为 <namespace>-<action>[-<variant>] 格式: - 重命名 desktop-mac/win/linux → desktop-build-mac/win/linux - 重命名 backend-migrate-* → backend-db-* - 重命名 frontend-build-desktop → desktop-prepare-frontend - 重命名 embedfs-prepare → desktop-prepare-embedfs - 重命名 package-macos → desktop-package-mac 新增顶层便捷命令: - dev: 并行启动开发环境 - build: 构建所有产物 - test: 运行所有测试 - lint: 检查所有代码 - clean: 清理所有构建产物
This commit is contained in:
94
Makefile
94
Makefile
@@ -1,22 +1,44 @@
|
||||
.PHONY: all clean \
|
||||
backend-build backend-run backend-test backend-test-unit backend-test-integration backend-test-coverage \
|
||||
backend-lint backend-deps backend-generate \
|
||||
backend-migrate-up backend-migrate-down backend-migrate-status backend-migrate-create \
|
||||
frontend-build frontend-dev frontend-test frontend-test-watch frontend-test-coverage frontend-test-e2e frontend-lint \
|
||||
desktop-mac desktop-win desktop-linux package-macos
|
||||
.PHONY: all dev build test lint clean \
|
||||
backend-build backend-run backend-dev backend-test backend-test-unit backend-test-integration backend-test-coverage \
|
||||
backend-lint backend-clean backend-deps backend-generate \
|
||||
backend-db-up backend-db-down backend-db-status backend-db-create \
|
||||
frontend-build frontend-dev frontend-test frontend-test-watch frontend-test-coverage frontend-test-e2e frontend-lint frontend-clean \
|
||||
desktop-build desktop-build-mac desktop-build-win desktop-build-linux \
|
||||
desktop-dev desktop-package-mac desktop-package-win desktop-package-linux desktop-clean \
|
||||
desktop-prepare-frontend desktop-prepare-embedfs
|
||||
|
||||
# ============================================
|
||||
# 顶层便捷命令
|
||||
# ============================================
|
||||
|
||||
dev:
|
||||
@echo "🚀 Starting development environment..."
|
||||
@$(MAKE) -j2 backend-dev frontend-dev
|
||||
|
||||
build: backend-build frontend-build
|
||||
@echo "✅ Build complete"
|
||||
|
||||
test: backend-test frontend-test
|
||||
@echo "✅ All tests passed"
|
||||
|
||||
lint: backend-lint frontend-lint
|
||||
@echo "✅ Lint complete"
|
||||
|
||||
all: build test lint
|
||||
|
||||
# ============================================
|
||||
# 后端
|
||||
# ============================================
|
||||
|
||||
all: backend-build
|
||||
|
||||
backend-build:
|
||||
cd backend && go build -o bin/server ./cmd/server
|
||||
|
||||
backend-run:
|
||||
cd backend && go run ./cmd/server
|
||||
|
||||
backend-dev:
|
||||
cd backend && go run ./cmd/server
|
||||
|
||||
backend-test:
|
||||
cd backend && go test ./... -v
|
||||
|
||||
@@ -34,22 +56,25 @@ backend-test-coverage:
|
||||
backend-lint:
|
||||
cd backend && go tool golangci-lint run ./...
|
||||
|
||||
backend-clean:
|
||||
rm -rf backend/bin/ backend/coverage.out backend/coverage.html
|
||||
|
||||
backend-deps:
|
||||
cd backend && go mod tidy
|
||||
|
||||
backend-generate:
|
||||
cd backend && go generate ./...
|
||||
|
||||
backend-migrate-up:
|
||||
backend-db-up:
|
||||
cd backend && goose -dir migrations sqlite3 $(DB_PATH) up
|
||||
|
||||
backend-migrate-down:
|
||||
backend-db-down:
|
||||
cd backend && goose -dir migrations sqlite3 $(DB_PATH) down
|
||||
|
||||
backend-migrate-status:
|
||||
backend-db-status:
|
||||
cd backend && goose -dir migrations sqlite3 $(DB_PATH) status
|
||||
|
||||
backend-migrate-create:
|
||||
backend-db-create:
|
||||
@read -p "Migration name: " name; \
|
||||
cd backend && goose -dir migrations create $$name sql
|
||||
|
||||
@@ -78,35 +103,60 @@ frontend-test-e2e:
|
||||
frontend-lint:
|
||||
cd frontend && bun run lint
|
||||
|
||||
frontend-clean:
|
||||
rm -rf frontend/dist frontend/.next frontend/node_modules
|
||||
|
||||
# ============================================
|
||||
# 桌面应用
|
||||
# ============================================
|
||||
|
||||
frontend-build-desktop:
|
||||
cd frontend && cp .env.desktop .env.production.local && bun install && bun run build && rm -f .env.production.local
|
||||
desktop-build: desktop-build-mac desktop-build-win desktop-build-linux
|
||||
@echo "✅ Desktop builds complete for all platforms"
|
||||
|
||||
embedfs-prepare:
|
||||
desktop-prepare-frontend:
|
||||
@echo "📦 Preparing frontend for desktop..."
|
||||
cd frontend && cp .env.desktop .env.production.local
|
||||
cd frontend && bun install && bun run build
|
||||
rm -f frontend/.env.production.local
|
||||
|
||||
desktop-prepare-embedfs:
|
||||
@echo "📦 Preparing embedded filesystem..."
|
||||
rm -rf embedfs/assets embedfs/frontend-dist
|
||||
cp -r assets embedfs/assets
|
||||
cp -r frontend/dist embedfs/frontend-dist
|
||||
|
||||
desktop-mac: frontend-build-desktop embedfs-prepare
|
||||
desktop-build-mac: desktop-prepare-frontend desktop-prepare-embedfs
|
||||
@echo "🍎 Building macOS..."
|
||||
cd backend && CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o ../build/nex-mac-arm64 ./cmd/desktop
|
||||
cd backend && CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o ../build/nex-mac-amd64 ./cmd/desktop
|
||||
|
||||
desktop-win: frontend-build-desktop embedfs-prepare
|
||||
desktop-build-win: desktop-prepare-frontend desktop-prepare-embedfs
|
||||
@echo "🪟 Building Windows..."
|
||||
cd backend && CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -ldflags "-H=windowsgui" -o ../build/nex-win-amd64.exe ./cmd/desktop
|
||||
|
||||
desktop-linux: frontend-build-desktop embedfs-prepare
|
||||
desktop-build-linux: desktop-prepare-frontend desktop-prepare-embedfs
|
||||
@echo "🐧 Building Linux..."
|
||||
cd backend && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o ../build/nex-linux-amd64 ./cmd/desktop
|
||||
|
||||
package-macos:
|
||||
desktop-dev: desktop-prepare-frontend desktop-prepare-embedfs
|
||||
@echo "🖥️ Starting desktop app in dev mode..."
|
||||
cd backend && go run ./cmd/desktop
|
||||
|
||||
desktop-package-mac:
|
||||
./scripts/build/package-macos.sh
|
||||
|
||||
desktop-package-win:
|
||||
@echo "⚠️ Windows packaging not implemented yet"
|
||||
|
||||
desktop-package-linux:
|
||||
@echo "⚠️ Linux packaging not implemented yet"
|
||||
|
||||
desktop-clean:
|
||||
rm -rf build/ embedfs/assets embedfs/frontend-dist
|
||||
|
||||
# ============================================
|
||||
# 清理
|
||||
# ============================================
|
||||
|
||||
clean:
|
||||
rm -rf backend/bin/ backend/coverage.out backend/coverage.html
|
||||
rm -rf build/
|
||||
clean: backend-clean frontend-clean desktop-clean
|
||||
@echo "✅ Clean complete"
|
||||
|
||||
58
README.md
58
README.md
@@ -92,14 +92,17 @@ nex/
|
||||
|
||||
```bash
|
||||
# macOS (arm64 + amd64)
|
||||
make desktop-mac
|
||||
make package-macos # 打包为 .app
|
||||
make desktop-build-mac
|
||||
make desktop-package-mac # 打包为 .app
|
||||
|
||||
# Windows
|
||||
make desktop-win
|
||||
make desktop-build-win
|
||||
|
||||
# Linux
|
||||
make desktop-linux
|
||||
make desktop-build-linux
|
||||
|
||||
# 构建所有平台
|
||||
make desktop-build
|
||||
```
|
||||
|
||||
**使用桌面应用**:
|
||||
@@ -244,23 +247,48 @@ export NEX_LOG_LEVEL=debug
|
||||
## 测试
|
||||
|
||||
```bash
|
||||
make backend-test # 后端测试
|
||||
make backend-test-coverage # 后端覆盖率
|
||||
make frontend-test # 前端测试
|
||||
make frontend-test-e2e # 前端 E2E 测试
|
||||
# 顶层便捷命令
|
||||
make test # 运行所有测试
|
||||
|
||||
# 后端测试
|
||||
make backend-test # 后端测试
|
||||
make backend-test-coverage # 后端覆盖率
|
||||
make backend-test-unit # 后端单元测试
|
||||
make backend-test-integration # 后端集成测试
|
||||
|
||||
# 前端测试
|
||||
make frontend-test # 前端测试
|
||||
make frontend-test-e2e # 前端 E2E 测试
|
||||
make frontend-test-coverage # 前端覆盖率
|
||||
```
|
||||
|
||||
## 开发
|
||||
|
||||
```bash
|
||||
make backend-build # 构建后端
|
||||
make backend-run # 运行后端
|
||||
make backend-lint # 后端代码检查
|
||||
make backend-migrate-up # 数据库迁移
|
||||
# 顶层便捷命令
|
||||
make dev # 启动开发环境(并行启动后端和前端)
|
||||
make build # 构建所有产物
|
||||
make lint # 检查所有代码
|
||||
make clean # 清理所有构建产物
|
||||
|
||||
make frontend-build # 构建前端
|
||||
make frontend-dev # 前端开发模式
|
||||
make frontend-lint # 前端代码检查
|
||||
# 后端开发
|
||||
make backend-build # 构建后端
|
||||
make backend-run # 运行后端
|
||||
make backend-dev # 后端开发模式
|
||||
make backend-lint # 后端代码检查
|
||||
make backend-clean # 清理后端构建产物
|
||||
|
||||
# 数据库操作
|
||||
make backend-db-up # 数据库迁移
|
||||
make backend-db-down # 数据库回滚
|
||||
make backend-db-status # 数据库迁移状态
|
||||
make backend-db-create # 创建新迁移
|
||||
|
||||
# 前端开发
|
||||
make frontend-build # 构建前端
|
||||
make frontend-dev # 前端开发模式
|
||||
make frontend-lint # 前端代码检查
|
||||
make frontend-clean # 清理前端构建产物
|
||||
```
|
||||
|
||||
## 开发规范
|
||||
|
||||
@@ -35,6 +35,7 @@ github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA=
|
||||
github.com/googleapis/gax-go/v2 v2.14.1/go.mod h1:Hb/NubMaVM88SrNkvl8X/o8XWwDJEPqouaLeN2IUxoA=
|
||||
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
|
||||
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
|
||||
@@ -112,19 +112,19 @@ TBD - 提供跨平台桌面应用支持,将后端服务与前端静态资源
|
||||
|
||||
#### Scenario: macOS 构建
|
||||
|
||||
- **WHEN** 执行 `desktop-mac` 构建命令
|
||||
- **WHEN** 执行 `desktop-build-mac` 构建命令
|
||||
- **THEN** 生成 `nex-mac-arm64` 和 `nex-mac-amd64` 可执行文件
|
||||
- **AND** 可打包为 `.app` bundle
|
||||
|
||||
#### Scenario: Windows 构建
|
||||
|
||||
- **WHEN** 执行 `desktop-win` 构建命令
|
||||
- **WHEN** 执行 `desktop-build-win` 构建命令
|
||||
- **THEN** 生成 `nex-win-amd64.exe` 可执行文件
|
||||
- **AND** 使用 `-H=windowsgui` linker flag 隐藏控制台窗口
|
||||
|
||||
#### Scenario: Linux 构建
|
||||
|
||||
- **WHEN** 执行 `desktop-linux` 构建命令
|
||||
- **WHEN** 执行 `desktop-build-linux` 构建命令
|
||||
- **THEN** 生成 `nex-linux-amd64` 可执行文件
|
||||
|
||||
### Requirement: macOS .app 打包
|
||||
|
||||
@@ -18,7 +18,7 @@ if [ -f "${BUILD_DIR}/nex-mac-arm64" ]; then
|
||||
elif [ -f "${BUILD_DIR}/nex-mac-amd64" ]; then
|
||||
cp "${BUILD_DIR}/nex-mac-amd64" "${BUILD_DIR}/${APP_NAME}.app/Contents/MacOS/nex"
|
||||
else
|
||||
echo "错误: 未找到 macOS 二进制文件,请先运行 make desktop-mac"
|
||||
echo "错误: 未找到 macOS 二进制文件,请先运行 make desktop-build-mac"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user