Skip to content

Commit 97eb45e

Browse files
committed
feat: add 'make dev' command to replace dev.sh script
- Auto-installs Air if not found (with GOPATH/bin PATH handling) - Creates placeholder files for Go embed directive in dev mode - Starts backend with Air live reload (or falls back to go run) - Starts frontend with Vite HMR - Handles cleanup on Ctrl+C/SIGTERM - Removed dev.sh in favor of unified Makefile command
1 parent efff1a3 commit 97eb45e

File tree

2 files changed

+46
-85
lines changed

2 files changed

+46
-85
lines changed

Makefile

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,56 @@
1-
.PHONY: help docs docs-serve docs-clean website website-dev website-build
1+
.PHONY: help docs docs-serve docs-clean website website-dev website-build dev
22

33
help: ## Show this help message
44
@echo 'Usage: make [target]'
55
@echo ''
66
@echo 'Available targets:'
77
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
88

9+
dev: ## Start development environment with Air (backend) and Vite (frontend)
10+
@echo "🚀 Starting development environment..."
11+
@# Ensure air is installed
12+
@if ! command -v air >/dev/null 2>&1; then \
13+
echo "⚠️ 'air' command not found."; \
14+
echo "📦 Auto-installing 'air' for live reload..."; \
15+
GOPATH=$$(go env GOPATH); \
16+
if [[ ":$$PATH:" != *":$$GOPATH/bin:"* ]]; then \
17+
echo "⚠️ $$GOPATH/bin is not in your PATH. Adding it temporarily..."; \
18+
export PATH=$$PATH:$$GOPATH/bin; \
19+
fi; \
20+
go install github.com/air-verse/air@latest; \
21+
if ! command -v air >/dev/null 2>&1; then \
22+
echo "❌ Failed to install 'air'. Falling back to 'go run'..."; \
23+
USE_GO_RUN=true; \
24+
else \
25+
echo "✅ 'air' installed successfully."; \
26+
USE_GO_RUN=false; \
27+
fi; \
28+
else \
29+
USE_GO_RUN=false; \
30+
fi; \
31+
\
32+
mkdir -p internal/web/dist; \
33+
if [ -z "$$(ls -A internal/web/dist)" ]; then \
34+
echo "📄 Creating placeholder files for Go embed..."; \
35+
echo "<!-- Placeholder for development -->" > internal/web/dist/index.html; \
36+
echo "placeholder" > internal/web/dist/dummy_asset; \
37+
fi; \
38+
\
39+
trap 'echo ""; echo "🛑 Stopping development servers..."; kill 0; exit 0' INT TERM; \
40+
\
41+
if [ "$$USE_GO_RUN" = true ]; then \
42+
echo "🔧 Starting Go backend (standard run)..."; \
43+
go run cmd/server/main.go & \
44+
else \
45+
echo "🔥 Starting Go backend (with Air live reload)..."; \
46+
air & \
47+
fi; \
48+
\
49+
echo "⚛️ Starting React frontend (Vite)..."; \
50+
cd web/frontend && npm run dev & \
51+
\
52+
wait
53+
954
docs: ## Generate API documentation from Go code annotations
1055
@echo "Generating API documentation..."
1156
@command -v swag >/dev/null 2>&1 || { echo "Error: swag not installed. Run: go install github.com/swaggo/swag/cmd/swag@latest"; exit 1; }

dev.sh

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)