.PHONY: build ui ui-build run docker docker-build test test-race test-both fmt clean help APP_NAME := helix-proxy GO := go UI_DIR := ui DIST_DIR := $(UI_DIR)/dist DATA_DIR := data # Inject git tag and commit separately; version package picks tag → commit → dev. GIT_TAG := $(shell git describe --tags --exact-match HEAD 2>/dev/null) GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null) LDFLAGS := -X helix-proxy/internal/version.Version=$(GIT_TAG) -X helix-proxy/internal/version.Commit=$(GIT_COMMIT) # Default target help: @echo "Helix Proxy Makefile" @echo "" @echo " build Build the Go binary (embeds UI if dist/ present)" @echo " ui Install UI deps (npm ci in ui/)" @echo " ui-build Build Svelte SPA to $(DIST_DIR)" @echo " run Build + run (uses current dir as cwd)" @echo " docker Build docker image (helix-proxy:dev)" @echo " docker-build Build docker image" @echo " test Run go tests" @echo " test-race Run go tests with race detector" @echo " test-both Run go tests and race detector" @echo " fmt Format Go sources (gofmt)" @echo " clean Remove build artifacts and ui/dist" @echo "" build: ui-build @echo "Building $(APP_NAME) (tag=$(if $(GIT_TAG),$(GIT_TAG),none), commit=$(if $(GIT_COMMIT),$(GIT_COMMIT),none))..." $(GO) build -ldflags "$(LDFLAGS)" -o $(APP_NAME) ./cmd/helix-proxy ui: @echo "Installing UI dependencies..." cd $(UI_DIR) && npm ci ui-build: clean @if [ -d "$(UI_DIR)" ]; then \ echo "Building Svelte UI..."; \ cd $(UI_DIR) && npm run build; \ else \ echo "No $(UI_DIR)/ dir, skipping UI build (will use empty embed or stub)"; \ fi run: build @echo "Running $(APP_NAME) from cwd (data/ will be created relative)..." PROXY_MODE=development ./$(APP_NAME) docker docker-build: @echo "Building docker image helix-proxy:dev..." docker build -t helix-proxy:dev . test: $(GO) test ./... -count=1 test-race: $(GO) test ./... -count=1 -race test-both: test test-race fmt: @echo "Formatting Go sources..." @files="$$(gofmt -l .)"; \ if [ -n "$$files" ]; then \ count=$$(echo "$$files" | wc -l); \ echo "Reformatted $$count file(s):"; \ echo "$$files" | sed 's/^/ /'; \ echo "$$files" | xargs gofmt -w; \ else \ echo "All Go files already formatted."; \ fi clean: rm -f $(APP_NAME) rm -rf $(DIST_DIR) rm -rf $(DATA_DIR) @echo "Cleaned binaries and UI dist."