-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (54 loc) · 2.31 KB
/
Copy pathMakefile
File metadata and controls
64 lines (54 loc) · 2.31 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
.PHONY: help serve start stop restart test deploy status
PORT ?= 8765
# :: listens on all interfaces (IPv4 + IPv6 on Linux). Use 0.0.0.0 for IPv4 only.
HOST ?= ::
REMOTE ?= origin
BRANCH ?= main
PIDFILE := .dev-server.pid
LAN_IP4 := $(shell ip -4 route get 1.1.1.1 2>/dev/null | awk '{for (i=1;i<=NF;i++) if ($$i=="src") print $$(i+1)}')
LAN_IP6 := $(shell ip -6 addr show scope global 2>/dev/null | awk '/inet6/{print $$2}' | head -1 | cut -d/ -f1)
help: ## Show available targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " make %-10s %s\n", $$1, $$2}'
serve: ## Run a foreground dev server (Ctrl+C to stop)
@$(MAKE) --no-print-directory _print-urls
@python3 -m http.server $(PORT) --bind $(HOST)
start: ## Start dev server in background (LAN-accessible)
@if [ -f $(PIDFILE) ] && kill -0 $$(cat $(PIDFILE)) 2>/dev/null; then \
echo "Already running (PID $$(cat $(PIDFILE)))"; \
$(MAKE) --no-print-directory _print-urls; \
else \
python3 -m http.server $(PORT) --bind $(HOST) </dev/null >/dev/null 2>&1 & \
echo $$! > $(PIDFILE); \
sleep 0.2; \
echo "Started (PID $$(cat $(PIDFILE)))"; \
$(MAKE) --no-print-directory _print-urls; \
fi
stop: ## Stop background dev server
@if [ -f $(PIDFILE) ]; then \
pid=$$(cat $(PIDFILE)); \
if kill -0 $$pid 2>/dev/null; then \
kill $$pid && echo "Stopped (PID $$pid)"; \
else \
echo "PID file stale, cleaning up"; \
fi; \
rm -f $(PIDFILE); \
else \
pkill -f "python3 -m http.server $(PORT)" 2>/dev/null \
&& echo "Stopped" || echo "Not running"; \
fi
restart: stop start ## Restart background dev server
test: ## Run unit tests (encode/decode)
@node --test tests/*.test.js
_print-urls:
@echo "Local: http://localhost:$(PORT)/"
@if [ -n "$(LAN_IP4)" ]; then echo "LAN v4: http://$(LAN_IP4):$(PORT)/"; fi
@if [ -n "$(LAN_IP6)" ]; then echo "LAN v6: http://[$(LAN_IP6)]:$(PORT)/"; fi
@echo "Bind: $(HOST):$(PORT)"
deploy: ## Push $(BRANCH) to $(REMOTE) (GitHub Pages deploys from main/root)
@git push $(REMOTE) $(BRANCH)
status: ## Show branch, remote, and GitHub Pages deploy settings reminder
@echo "Branch: $$(git branch --show-current)"
@echo "Remote: $$(git remote get-url $(REMOTE) 2>/dev/null || echo '(not set)')"
@echo ""
@echo "GitHub Pages: Settings → Pages → branch $(BRANCH), folder / (root)"