forked from kkoishichan/MomShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
177 lines (134 loc) · 5.89 KB
/
Copy pathMakefile
File metadata and controls
177 lines (134 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
.PHONY: install install-backend install-frontend dev dev-backend dev-frontend \
lint lint-backend lint-frontend format format-backend format-frontend \
typecheck typecheck-backend typecheck-frontend check build-frontend build-backend \
docker-up docker-down docker-logs docker-build \
postgres-up postgres-down postgres-logs db-reset deps-lock deps-update clean clean-all help
# Database config (must match dev-setup.sh / .env)
DB_USER ?= momshell
DB_PASS ?= momshell
DB_NAME ?= momshell
# Colors for terminal output
CYAN := \033[36m
GREEN := \033[32m
YELLOW := \033[33m
RESET := \033[0m
##@ Setup
install: install-backend install-frontend ## Install all dependencies
@echo "$(GREEN)All dependencies installed$(RESET)"
install-backend: ## Install backend dependencies
@echo "$(CYAN)Installing backend dependencies...$(RESET)"
cd backend && go mod download
install-frontend: ## Install frontend dependencies
@echo "$(CYAN)Installing frontend dependencies...$(RESET)"
cd frontend && npm install
##@ Development
dev: ## Start both backend and frontend (requires tmux or run in separate terminals)
@echo "$(YELLOW)Starting development servers...$(RESET)"
@echo "$(CYAN)Run these commands in separate terminals:$(RESET)"
@echo " make dev-backend"
@echo " make dev-frontend"
@echo ""
@echo "$(CYAN)Or use: make dev-tmux (requires tmux)$(RESET)"
dev-tmux: ## Start both servers in tmux split panes
@command -v tmux >/dev/null 2>&1 || { echo "tmux is required but not installed."; exit 1; }
tmux new-session -d -s momshell 'make dev-backend' \; \
split-window -h 'make dev-frontend' \; \
attach
dev-backend: postgres-up ## Start backend development server
@echo "$(CYAN)Starting backend server on http://localhost:8000$(RESET)"
cd backend && go run cmd/server/main.go
dev-frontend: ## Start frontend development server
@echo "$(CYAN)Starting frontend server on http://localhost:5173$(RESET)"
cd frontend && npx vite
##@ Code Quality
lint: lint-backend lint-frontend ## Run all linters
@echo "$(GREEN)All linting passed$(RESET)"
lint-backend: ## Run backend linter (go vet)
@echo "$(CYAN)Linting backend...$(RESET)"
cd backend && go vet ./... && golangci-lint run ./...
lint-frontend: ## Run frontend linter (eslint)
@echo "$(CYAN)Linting frontend...$(RESET)"
cd frontend && npm run lint
format: format-backend ## Format all code
@echo "$(GREEN)All code formatted$(RESET)"
format-backend: ## Format backend code (go fmt)
@echo "$(CYAN)Formatting backend...$(RESET)"
cd backend && go fmt ./...
typecheck: typecheck-backend typecheck-frontend ## Run all type checkers
@echo "$(GREEN)All type checks passed$(RESET)"
typecheck-backend: ## Run backend type check (compile)
@echo "$(CYAN)Type checking backend...$(RESET)"
cd backend && go build ./...
typecheck-frontend: ## Run frontend type checker (vue-tsc)
@echo "$(CYAN)Type checking frontend...$(RESET)"
cd frontend && npm run typecheck
check: lint typecheck ## Run all checks (lint + typecheck)
@echo "$(GREEN)All checks passed$(RESET)"
##@ Build
build-frontend: ## Build frontend for production
@echo "$(CYAN)Building frontend...$(RESET)"
cd frontend && npm run build
build-backend: ## Build backend binary
@echo "$(CYAN)Building backend...$(RESET)"
cd backend && go build -o bin/server cmd/server/main.go
##@ Docker
docker-up: ## Start all services (app + postgres)
@echo "$(CYAN)Starting Docker containers...$(RESET)"
cd deploy && docker compose up -d --build
docker-down: ## Stop all services
@echo "$(CYAN)Stopping Docker containers...$(RESET)"
cd deploy && docker compose down
docker-logs: ## Show Docker logs
cd deploy && docker compose logs -f
docker-build: ## Build application Docker image
@echo "$(CYAN)Building Docker image...$(RESET)"
docker build -t momshell .
##@ Database
postgres-up: ## Start local PostgreSQL (systemd)
@echo "$(CYAN)Ensuring local PostgreSQL is running on localhost:5432...$(RESET)"
@if pg_isready -q 2>/dev/null; then \
echo "$(GREEN)PostgreSQL is already running$(RESET)"; \
else \
echo "$(YELLOW)Starting PostgreSQL via systemctl...$(RESET)"; \
sudo systemctl start postgresql; \
until pg_isready -q 2>/dev/null; do sleep 1; done; \
echo "$(GREEN)PostgreSQL is ready$(RESET)"; \
fi
postgres-down: ## Stop local PostgreSQL (systemd)
@echo "$(CYAN)Stopping local PostgreSQL...$(RESET)"
@sudo systemctl stop postgresql
@echo "$(GREEN)PostgreSQL stopped$(RESET)"
postgres-logs: ## Show local PostgreSQL logs
@journalctl -u postgresql -f
db-reset: postgres-up ## Reset PostgreSQL schema (drop and recreate public schema)
@echo "$(YELLOW)Resetting database...$(RESET)"
psql -U user -d momshell -c "DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;"
@echo "$(GREEN)Database reset. It will be recreated on next server start.$(RESET)"
##@ Dependencies
deps-lock: ## Sync backend dependencies
@echo "$(CYAN)Locking dependencies...$(RESET)"
cd backend && go mod tidy
@echo "$(GREEN)Dependencies locked$(RESET)"
deps-update: ## Update all dependencies
@echo "$(CYAN)Updating backend dependencies...$(RESET)"
cd backend && go get -u ./...
cd backend && go mod tidy
@echo "$(CYAN)Updating frontend dependencies...$(RESET)"
cd frontend && npm update
@echo "$(GREEN)All dependencies updated$(RESET)"
##@ Cleanup
clean: ## Clean all caches and temporary files
@echo "$(CYAN)Cleaning caches...$(RESET)"
rm -rf backend/bin backend/.cache
rm -rf frontend/node_modules/.cache
@echo "$(GREEN)Caches cleaned$(RESET)"
clean-all: clean ## Clean everything including node_modules
@echo "$(YELLOW)Removing node_modules...$(RESET)"
rm -rf frontend/node_modules
@echo "$(GREEN)All cleaned$(RESET)"
##@ Help
help: ## Show this help
@awk 'BEGIN {FS = ":.*##"; printf "\n$(CYAN)Usage:$(RESET)\n make $(GREEN)<target>$(RESET)\n"} \
/^[a-zA-Z_-]+:.*?##/ { printf " $(GREEN)%-18s$(RESET) %s\n", $$1, $$2 } \
/^##@/ { printf "\n$(YELLOW)%s$(RESET)\n", substr($$0, 5) }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help