-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
328 lines (299 loc) · 11.6 KB
/
Copy pathMakefile
File metadata and controls
328 lines (299 loc) · 11.6 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
.PHONY: help setup rebase-upstream status feature-start feature-end build build-cli build-server install install-server install-cli install-webapp server stop logs cli e2e-test browser-inspect setup-credentials validate validate-quick push
# Base development branch for submodules (combines all features we want to merge)
BASE_SUBMODULE_BRANCH := rrnewton
# Default target
help:
@echo "Happy Repository Management"
@echo ""
@echo "=== Server & Development ==="
@echo " make server - Start all services (server + webapp)"
@echo " make stop - Stop all services"
@echo " make logs - View server logs"
@echo " make cli - Run CLI with local server (uses ~/.happy)"
@echo " make setup-credentials - Auto-create test credentials in ~/.happy"
@echo ""
@echo "=== Build Targets ==="
@echo " make build - Build all TypeScript code (CLI and server)"
@echo " make build-cli - Build happy-cli only"
@echo " make build-server - Typecheck happy-server only"
@echo " make install - Install dependencies for all repos"
@echo " make install-server - Install happy-server dependencies only"
@echo " make install-cli - Install happy-cli dependencies only"
@echo " make install-webapp - Install happy webapp dependencies only"
@echo ""
@echo "=== Testing ==="
@echo " make validate - Run all validation tests (builds + unit + browser)"
@echo " make validate-quick - Run quick validation (builds only, no browser tests)"
@echo " make e2e-test - Run full E2E test (isolated test credentials)"
@echo " make browser-inspect - Inspect webapp with headless browser"
@echo ""
@echo "=== Repository Management ==="
@echo " make setup - Configure submodule remotes and branches"
@echo " make rebase-upstream - Fetch and rebase on upstream/main"
@echo " make status - Show submodule branch status"
@echo " make push - Push all repos (submodules + parent) to origin"
@echo " make feature-start - Start a new feature branch (use FEATURE=name)"
@echo " make feature-end - End feature branch and return to base development"
@echo ""
@echo "Examples:"
@echo " make server # Start all services for development"
@echo " make cli # Run CLI connected to local server"
@echo " make build # Rebuild all TypeScript after code changes"
@echo ""
# Setup submodule remotes and branches
setup:
@./scripts/setup-submodules.sh
# Rebase all submodules on upstream/main
rebase-upstream: setup
@./scripts/rebase-upstream.sh
# Show current status of all repos (parent + submodules)
status:
@echo ""
@echo "==============================================================================="
@echo "=== Repository Status ==="
@echo "==============================================================================="
@echo ""
@if [ -f feature_name.txt ]; then \
echo "Feature mode: $$(cat feature_name.txt)"; \
else \
echo "Mode: Base development"; \
fi
@echo ""
@# Parent repo
@echo "-------------------------------------------------------------------------------"
@echo "[PARENT] $$(git rev-parse --abbrev-ref HEAD)"
@echo "-------------------------------------------------------------------------------"
@TRACKING=$$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || echo "none"); \
AHEAD=$$(git rev-list --count @{u}..HEAD 2>/dev/null || echo "0"); \
BEHIND=$$(git rev-list --count HEAD..@{u} 2>/dev/null || echo "0"); \
echo "Tracking: $$TRACKING (+$$AHEAD/-$$BEHIND)"
@echo ""
@git status --short || true
@echo ""
@DIFF=$$(git diff --stat 2>/dev/null); \
if [ -n "$$DIFF" ]; then \
echo "Unstaged changes:"; \
echo "$$DIFF"; \
echo ""; \
fi
@STAGED=$$(git diff --cached --stat 2>/dev/null); \
if [ -n "$$STAGED" ]; then \
echo "Staged changes:"; \
echo "$$STAGED"; \
echo ""; \
fi
@# Submodules
@for submod in happy happy-cli happy-server; do \
echo "-------------------------------------------------------------------------------"; \
BRANCH=$$(cd $$submod && git rev-parse --abbrev-ref HEAD); \
echo "[$$submod] $$BRANCH"; \
echo "-------------------------------------------------------------------------------"; \
TRACKING=$$(cd $$submod && git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || echo "none"); \
AHEAD=$$(cd $$submod && git rev-list --count @{u}..HEAD 2>/dev/null || echo "0"); \
BEHIND=$$(cd $$submod && git rev-list --count HEAD..@{u} 2>/dev/null || echo "0"); \
echo "Tracking: $$TRACKING (+$$AHEAD/-$$BEHIND)"; \
echo ""; \
(cd $$submod && git status --short) || true; \
echo ""; \
DIFF=$$(cd $$submod && git diff --stat 2>/dev/null); \
if [ -n "$$DIFF" ]; then \
echo "Unstaged changes:"; \
echo "$$DIFF"; \
echo ""; \
fi; \
STAGED=$$(cd $$submod && git diff --cached --stat 2>/dev/null); \
if [ -n "$$STAGED" ]; then \
echo "Staged changes:"; \
echo "$$STAGED"; \
echo ""; \
fi; \
done
@echo "==============================================================================="
@echo ""
# Start a new feature branch
feature-start:
@if [ -z "$(FEATURE)" ]; then \
echo "Error: FEATURE name required. Usage: make feature-start FEATURE=name"; \
exit 1; \
fi
@if [ -f feature_name.txt ]; then \
echo "Error: Already in feature mode: $$(cat feature_name.txt)"; \
echo "Run 'make feature-end' first"; \
exit 1; \
fi
@echo "Starting feature: $(FEATURE)"
@echo ""
@# Create feature_name.txt
@echo "$(FEATURE)" > feature_name.txt
@# Create parent branch
@echo "Creating parent branch: happy-$(FEATURE)"
@git checkout -b happy-$(FEATURE) happy
@# Add feature_name.txt to git
@git add feature_name.txt
@git commit -m "Start feature: $(FEATURE)"
@echo ""
@# Create feature branches in submodules (branching from base development branch)
@for submod in happy happy-cli happy-server; do \
echo "Creating feature-$(FEATURE) in $$submod (from $(BASE_SUBMODULE_BRANCH))..."; \
cd $$submod && \
git checkout -b feature-$(FEATURE) $(BASE_SUBMODULE_BRANCH) && \
cd ..; \
done
@echo ""
@echo "Feature $(FEATURE) started!"
@echo " Parent branch: happy-$(FEATURE)"
@echo " Submodule branches: feature-$(FEATURE)"
@echo ""
# End feature branch and return to base development
feature-end:
@if [ ! -f feature_name.txt ]; then \
echo "Error: Not in feature mode"; \
exit 1; \
fi
@FEATURE=$$(cat feature_name.txt) && \
echo "Ending feature: $$FEATURE" && \
echo "" && \
echo "Checking out $(BASE_SUBMODULE_BRANCH) in submodules..." && \
for submod in happy happy-cli happy-server; do \
cd $$submod && \
git checkout $(BASE_SUBMODULE_BRANCH) && \
cd ..; \
done && \
echo "" && \
echo "Switching to happy branch..." && \
git checkout happy && \
echo "" && \
echo "Removing feature_name.txt..." && \
rm -f feature_name.txt && \
git add feature_name.txt && \
git commit -m "End feature: $$FEATURE" && \
echo "" && \
echo "Feature $$FEATURE ended!" && \
echo " Feature branches still exist but are not active" && \
echo " Delete them manually if no longer needed:" && \
echo " git branch -D happy-$$FEATURE" && \
echo " cd <submodule> && git branch -D feature-$$FEATURE" && \
echo ""
# ============================================================================
# Build Targets
# ============================================================================
# Install dependencies for happy-server
install-server:
@echo "Installing happy-server dependencies..."
@cd happy-server && yarn install
# Install dependencies for happy-cli
install-cli:
@echo "Installing happy-cli dependencies..."
@cd happy-cli && yarn install
# Install dependencies for happy webapp
install-webapp:
@echo "Installing happy webapp dependencies..."
@cd happy && yarn install
# Install dependencies for all repositories
install: install-server install-cli install-webapp
@echo ""
@echo "=== All dependencies installed ==="
# Build happy-cli (compiles TypeScript to dist/)
build-cli:
@echo "=== Building happy-cli ==="
@cd happy-cli && yarn build
@echo "=== happy-cli build complete ==="
# Typecheck happy-server (runs with tsx, no compilation needed)
build-server:
@echo "=== Typechecking happy-server ==="
@cd happy-server && yarn build
@echo "=== happy-server typecheck complete ==="
# Build all TypeScript code
# Note: happy webapp uses Expo and builds at runtime, no pre-build needed
build: build-cli build-server
@echo ""
@echo "=== All builds complete ==="
@echo ""
@echo "Built components:"
@echo " - happy-cli: dist/ directory updated"
@echo " - happy-server: TypeScript validated (runs directly with tsx)"
@echo " - happy webapp: No pre-build needed (Expo builds at runtime)"
@echo ""
# ============================================================================
# Server & Development Targets
# ============================================================================
# Start all services (server + webapp) - no test credentials created
server: build
@echo ""
@echo "=== Starting Happy Server ==="
@echo ""
@./start-server.sh
# Stop all services (all slots)
stop:
@echo "=== Stopping all services ==="
@./happy-cli/bin/happy.mjs daemon stop 2>/dev/null || true
@./happy-launcher.sh cleanup --all-slots
@echo "All services stopped"
# View server logs
logs:
@./happy-launcher.sh logs server
# Run CLI with local server (uses default ~/.happy credentials)
cli:
HAPPY_SERVER_URL=http://localhost:3005 ./happy-cli/bin/happy.mjs
list:
HAPPY_SERVER_URL=http://localhost:3005 ./happy-cli/bin/happy.mjs list
# Auto-create credentials in ~/.happy (for quick setup)
setup-credentials:
@echo "=== Creating credentials in ~/.happy ==="
@HAPPY_HOME_DIR=~/.happy HAPPY_SERVER_URL=http://localhost:3005 node scripts/setup-test-credentials.mjs
# ============================================================================
# Testing Targets
# ============================================================================
# Full E2E test with isolated test credentials (for CI/testing only)
e2e-test: build
@echo ""
@echo "=== Running E2E Test (isolated credentials) ==="
@echo ""
@./happy-launcher.sh cleanup --clean-logs
@./e2e-web-demo.sh
# Inspect webapp with headless browser (requires webapp to be running)
browser-inspect:
@echo "=== Inspecting webapp with headless browser ==="
@cd scripts/browser && node inspect-webapp.mjs --screenshot --console
# Run all validation tests (builds, unit tests, browser tests if services running)
validate:
@./scripts/validate.sh
# Run quick validation (builds only, skip browser tests)
validate-quick:
@./scripts/validate.sh --quick
# ============================================================================
# Git Push Target
# ============================================================================
# Push all repos (submodules + parent) at their current branches
push:
@echo ""
@echo "=== Pushing All Repositories ==="
@echo ""
@FAILED=""; \
for submod in happy happy-cli happy-server; do \
BRANCH=$$(cd $$submod && git rev-parse --abbrev-ref HEAD); \
echo "Pushing $$submod ($$BRANCH)..."; \
if cd $$submod && git push origin $$BRANCH 2>&1; then \
echo " ✓ $$submod pushed successfully"; \
else \
echo " ✗ $$submod push failed"; \
FAILED="$$FAILED $$submod"; \
fi; \
cd ..; \
done; \
PARENT_BRANCH=$$(git rev-parse --abbrev-ref HEAD); \
echo "Pushing parent repo ($$PARENT_BRANCH)..."; \
if git push origin $$PARENT_BRANCH 2>&1; then \
echo " ✓ parent pushed successfully"; \
else \
echo " ✗ parent push failed"; \
FAILED="$$FAILED parent"; \
fi; \
echo ""; \
if [ -z "$$FAILED" ]; then \
echo "=== All repositories pushed successfully ==="; \
else \
echo "=== Push completed with failures:$$FAILED ==="; \
exit 1; \
fi; \
echo ""