# Makefile for broad-announce
#
# Dev targets:
#   make proto          — regenerate Go stubs from .proto files
#   make vet            — run go vet on all packages
#   make build          — build all Go binaries
#   make test           — run Go unit tests
#   make web-install    — pnpm install in web/
#   make web-build      — build the SPA into web/dist/
#   make web-dev        — vite dev server on :5173
#   make web-test       — vitest run in web/
#   make web-typecheck  — tsc --noEmit
#   make build          — builds Go + embeds web/dist into admind

.PHONY: proto vet build test web-install web-build web-dev web-test web-typecheck build-with-web

PROTO_DIR   := proto
GEN_DIR     := gen/go
BUF         := buf

# proto regenerates the Go stubs from .proto sources.
# Run this whenever you edit anything under proto/.
proto:
	cd $(PROTO_DIR) && \
		$(BUF) lint --config $(PROTO_DIR)/buf.yaml . && \
		$(BUF) generate --template $(PROTO_DIR)/buf.gen.yaml $(PROTO_DIR)/
	go build ./$(GEN_DIR)/...

vet:
	go vet ./...

build:
	go build ./cmd/...

test:
	go test ./...

# ── Frontend (M13b W0) ─────────────────────────────────────────────

# web-install runs pnpm install for the web workspace.
# Idempotent; uses the local pnpm-store at .pnpm-store.
web-install:
	pnpm install --frozen-lockfile=false

# web-build produces web/dist/ that the admind binary embeds
# via //go:embed web/dist/*.
web-build:
	cd web && pnpm run build

# web-dev starts the Vite dev server on :5173 with proxy
# rules so /v1/* goes to the local stack. Bring up the stack
# (docker compose up -d) before running this.
web-dev:
	cd web && pnpm run dev

# web-test runs the vitest unit tests.
web-test:
	cd web && pnpm run test

# web-typecheck runs tsc without emitting.
web-typecheck:
	cd web && pnpm exec tsc --noEmit

# build-with-web runs the SPA build first, then builds all
# Go binaries so admind picks up the freshly built web/dist.
build-with-web: web-build build

# ── M13a smoke ────────────────────────────────────────────────────
M13A_SMOKE = bash scripts/m13a_smoke.sh

m13a-smoke:
	$(M13A_SMOKE)
