179 lines
6.0 KiB
Makefile
179 lines
6.0 KiB
Makefile
.PHONY: install build start dev test test-unit test-integration test-e2e test-cov test-watch test-docker-all clean prisma-generate prisma-migrate prisma-studio lint format docker-build docker-up docker-down
|
|
|
|
# =============================================================================
|
|
# 环境变量
|
|
# =============================================================================
|
|
NODE_ENV ?= development
|
|
DATABASE_URL ?= postgresql://postgres:postgres@localhost:5432/rwadurian_planting_test?schema=public
|
|
|
|
# =============================================================================
|
|
# 安装和构建
|
|
# =============================================================================
|
|
install:
|
|
npm install
|
|
|
|
build:
|
|
npm run build
|
|
|
|
clean:
|
|
rm -rf dist node_modules coverage .nyc_output
|
|
|
|
# =============================================================================
|
|
# 开发
|
|
# =============================================================================
|
|
start:
|
|
npm run start
|
|
|
|
dev:
|
|
npm run start:dev
|
|
|
|
# =============================================================================
|
|
# 数据库
|
|
# =============================================================================
|
|
prisma-generate:
|
|
npx prisma generate
|
|
|
|
prisma-migrate:
|
|
npx prisma migrate dev
|
|
|
|
prisma-migrate-prod:
|
|
npx prisma migrate deploy
|
|
|
|
prisma-studio:
|
|
npx prisma studio
|
|
|
|
prisma-reset:
|
|
npx prisma migrate reset --force
|
|
|
|
# =============================================================================
|
|
# 测试
|
|
# =============================================================================
|
|
test: test-unit
|
|
|
|
test-unit:
|
|
@echo "=========================================="
|
|
@echo "Running Unit Tests..."
|
|
@echo "=========================================="
|
|
npm run test
|
|
|
|
test-unit-verbose:
|
|
npm run test -- --verbose
|
|
|
|
test-watch:
|
|
npm run test:watch
|
|
|
|
test-cov:
|
|
@echo "=========================================="
|
|
@echo "Running Unit Tests with Coverage..."
|
|
@echo "=========================================="
|
|
npm run test:cov
|
|
|
|
test-integration:
|
|
@echo "=========================================="
|
|
@echo "Running Integration Tests..."
|
|
@echo "=========================================="
|
|
npm run test -- --testPathPattern=integration --runInBand
|
|
|
|
test-e2e:
|
|
@echo "=========================================="
|
|
@echo "Running E2E Tests..."
|
|
@echo "=========================================="
|
|
npm run test:e2e
|
|
|
|
test-all:
|
|
@echo "=========================================="
|
|
@echo "Running All Tests..."
|
|
@echo "=========================================="
|
|
$(MAKE) test-unit
|
|
$(MAKE) test-integration
|
|
$(MAKE) test-e2e
|
|
@echo "=========================================="
|
|
@echo "All Tests Completed!"
|
|
@echo "=========================================="
|
|
|
|
# =============================================================================
|
|
# Docker 测试
|
|
# =============================================================================
|
|
docker-build:
|
|
docker build -t planting-service:test .
|
|
|
|
docker-up:
|
|
docker-compose up -d
|
|
|
|
docker-down:
|
|
docker-compose down -v
|
|
|
|
docker-test-unit:
|
|
@echo "=========================================="
|
|
@echo "Running Unit Tests in Docker..."
|
|
@echo "=========================================="
|
|
docker-compose -f docker-compose.test.yml run --rm test npm run test
|
|
|
|
docker-test-integration:
|
|
@echo "=========================================="
|
|
@echo "Running Integration Tests in Docker..."
|
|
@echo "=========================================="
|
|
docker-compose -f docker-compose.test.yml run --rm test npm run test -- --testPathPattern=integration --runInBand
|
|
|
|
docker-test-e2e:
|
|
@echo "=========================================="
|
|
@echo "Running E2E Tests in Docker..."
|
|
@echo "=========================================="
|
|
docker-compose -f docker-compose.test.yml run --rm test npm run test:e2e
|
|
|
|
test-docker-all:
|
|
@echo "=========================================="
|
|
@echo "Running All Tests in Docker..."
|
|
@echo "=========================================="
|
|
docker-compose -f docker-compose.test.yml up -d db
|
|
@sleep 5
|
|
docker-compose -f docker-compose.test.yml run --rm test sh -c "npx prisma migrate deploy && npm run test && npm run test:e2e"
|
|
docker-compose -f docker-compose.test.yml down -v
|
|
@echo "=========================================="
|
|
@echo "All Docker Tests Completed!"
|
|
@echo "=========================================="
|
|
|
|
# =============================================================================
|
|
# 代码质量
|
|
# =============================================================================
|
|
lint:
|
|
npm run lint
|
|
|
|
format:
|
|
npm run format
|
|
|
|
# =============================================================================
|
|
# 帮助
|
|
# =============================================================================
|
|
help:
|
|
@echo "Planting Service - Available Commands:"
|
|
@echo ""
|
|
@echo " Development:"
|
|
@echo " make install - Install dependencies"
|
|
@echo " make build - Build the project"
|
|
@echo " make dev - Start in development mode"
|
|
@echo " make start - Start in production mode"
|
|
@echo ""
|
|
@echo " Database:"
|
|
@echo " make prisma-generate - Generate Prisma client"
|
|
@echo " make prisma-migrate - Run database migrations"
|
|
@echo " make prisma-studio - Open Prisma Studio"
|
|
@echo " make prisma-reset - Reset database"
|
|
@echo ""
|
|
@echo " Testing:"
|
|
@echo " make test-unit - Run unit tests"
|
|
@echo " make test-integration - Run integration tests"
|
|
@echo " make test-e2e - Run end-to-end tests"
|
|
@echo " make test-cov - Run tests with coverage"
|
|
@echo " make test-all - Run all tests"
|
|
@echo " make test-docker-all - Run all tests in Docker"
|
|
@echo ""
|
|
@echo " Code Quality:"
|
|
@echo " make lint - Run linter"
|
|
@echo " make format - Format code"
|
|
@echo ""
|
|
@echo " Docker:"
|
|
@echo " make docker-build - Build Docker image"
|
|
@echo " make docker-up - Start Docker containers"
|
|
@echo " make docker-down - Stop Docker containers"
|