2026-05-23 22:44:06 +08:00
|
|
|
APP := cs-agent
|
|
|
|
|
MAIN := ./cmd/server
|
|
|
|
|
WEB_DIR := web
|
|
|
|
|
SPA_INDEX := $(WEB_DIR)/out/index.html
|
|
|
|
|
|
|
|
|
|
GO ?= go
|
|
|
|
|
PNPM ?= pnpm
|
|
|
|
|
GOOS ?= $(shell $(GO) env GOOS)
|
|
|
|
|
GOARCH ?= $(shell $(GO) env GOARCH)
|
2026-05-24 20:38:08 +08:00
|
|
|
DEV_SERVER_URL ?= http://127.0.0.1:8083
|
2026-05-23 22:44:06 +08:00
|
|
|
|
|
|
|
|
.DEFAULT_GOAL := help
|
|
|
|
|
|
|
|
|
|
.PHONY: all help build build-go build-linux release run run-go dev test check clean clean-web \
|
|
|
|
|
web-install web-dev web-build-spa ensure-spa build-spa web-build-ssr web-typecheck web-lint \
|
|
|
|
|
generator enums migration testdata
|
|
|
|
|
|
|
|
|
|
all: build
|
2026-04-09 10:01:23 +08:00
|
|
|
|
2026-04-16 21:21:54 +08:00
|
|
|
help:
|
|
|
|
|
@echo "Available targets:"
|
2026-05-23 22:44:06 +08:00
|
|
|
@echo " make build Build web SPA and Go binary"
|
|
|
|
|
@echo " make build-go Build Go binary only, ensuring SPA exists"
|
|
|
|
|
@echo " make build-linux Build linux amd64 binary"
|
|
|
|
|
@echo " make release Build release binaries for common platforms"
|
|
|
|
|
@echo " make run Build web SPA then run server"
|
|
|
|
|
@echo " make run-go Run server only, ensuring SPA exists"
|
|
|
|
|
@echo " make dev Run Go server with dev tag and web dev server"
|
|
|
|
|
@echo " make test Run Go tests, ensuring SPA exists"
|
|
|
|
|
@echo " make check Run Go tests, web typecheck, and web lint"
|
|
|
|
|
@echo " make clean Remove Go binaries"
|
|
|
|
|
@echo " make clean-web Remove web build output"
|
|
|
|
|
@echo " make web-install Install web dependencies"
|
|
|
|
|
@echo " make web-dev Run web dev server"
|
|
|
|
|
@echo " make web-build-spa Build static web SPA"
|
|
|
|
|
@echo " make web-typecheck Run web typecheck"
|
|
|
|
|
@echo " make web-lint Run web lint"
|
2026-04-16 21:21:54 +08:00
|
|
|
@echo " make generator Run code generator"
|
|
|
|
|
@echo " make enums Generate frontend enums"
|
|
|
|
|
@echo " make migration Run migration command"
|
|
|
|
|
@echo " make testdata Run testdata generator"
|
|
|
|
|
|
2026-05-23 22:44:06 +08:00
|
|
|
build: web-build-spa
|
|
|
|
|
@$(MAKE) build-go
|
|
|
|
|
|
|
|
|
|
build-go: ensure-spa
|
|
|
|
|
@echo "Building $(APP)..."
|
|
|
|
|
@$(GO) build -v -o $(APP) $(MAIN)
|
|
|
|
|
|
|
|
|
|
build-linux: web-build-spa
|
|
|
|
|
@echo "Building $(APP) for linux/amd64..."
|
|
|
|
|
@GOOS=linux GOARCH=amd64 $(GO) build -v -o $(APP)-linux-amd64 $(MAIN)
|
2026-04-16 18:19:16 +08:00
|
|
|
|
2026-05-23 22:44:06 +08:00
|
|
|
release: web-build-spa
|
|
|
|
|
@echo "Building release binaries..."
|
|
|
|
|
@GOOS=linux GOARCH=amd64 $(GO) build -v -o $(APP)-linux-amd64 $(MAIN)
|
|
|
|
|
@GOOS=linux GOARCH=arm64 $(GO) build -v -o $(APP)-linux-arm64 $(MAIN)
|
|
|
|
|
@GOOS=darwin GOARCH=amd64 $(GO) build -v -o $(APP)-darwin-amd64 $(MAIN)
|
|
|
|
|
@GOOS=darwin GOARCH=arm64 $(GO) build -v -o $(APP)-darwin-arm64 $(MAIN)
|
|
|
|
|
@GOOS=windows GOARCH=amd64 $(GO) build -v -o $(APP)-windows-amd64.exe $(MAIN)
|
|
|
|
|
|
|
|
|
|
run: web-build-spa
|
|
|
|
|
@$(GO) run $(MAIN)
|
|
|
|
|
|
|
|
|
|
run-go: ensure-spa
|
|
|
|
|
@$(GO) run $(MAIN)
|
|
|
|
|
|
|
|
|
|
dev:
|
|
|
|
|
@$(GO) run -tags dev $(MAIN) & \
|
2026-04-09 10:01:23 +08:00
|
|
|
server_pid=$$!; \
|
2026-05-23 22:44:06 +08:00
|
|
|
trap 'kill $$server_pid 2>/dev/null || true' EXIT INT TERM; \
|
2026-05-24 20:38:08 +08:00
|
|
|
echo "Waiting for server at $(DEV_SERVER_URL)..."; \
|
|
|
|
|
until curl -fsS "$(DEV_SERVER_URL)" >/dev/null 2>&1; do \
|
|
|
|
|
if ! kill -0 $$server_pid 2>/dev/null; then \
|
|
|
|
|
wait $$server_pid; \
|
|
|
|
|
exit $$?; \
|
|
|
|
|
fi; \
|
|
|
|
|
sleep 1; \
|
|
|
|
|
done; \
|
|
|
|
|
echo "Server is ready; starting web dev server..."; \
|
2026-05-23 22:44:06 +08:00
|
|
|
$(MAKE) web-dev
|
|
|
|
|
|
|
|
|
|
test: ensure-spa
|
|
|
|
|
@$(GO) test ./...
|
|
|
|
|
|
|
|
|
|
check: test web-typecheck web-lint
|
|
|
|
|
|
|
|
|
|
clean:
|
|
|
|
|
@rm -f $(APP) $(APP)-linux-amd64 $(APP)-linux-arm64 $(APP)-darwin-amd64 $(APP)-darwin-arm64 $(APP)-windows-amd64.exe
|
|
|
|
|
|
|
|
|
|
clean-web:
|
|
|
|
|
@rm -rf $(WEB_DIR)/out
|
|
|
|
|
|
|
|
|
|
web-install:
|
|
|
|
|
@cd $(WEB_DIR) && $(PNPM) install --frozen-lockfile
|
|
|
|
|
|
|
|
|
|
web-dev:
|
|
|
|
|
@cd $(WEB_DIR) && $(PNPM) dev
|
|
|
|
|
|
|
|
|
|
web-build-spa:
|
|
|
|
|
@cd $(WEB_DIR) && $(PNPM) build:sdk && $(PNPM) build
|
|
|
|
|
|
|
|
|
|
ensure-spa:
|
|
|
|
|
@if [ ! -f "$(SPA_INDEX)" ]; then \
|
|
|
|
|
echo "SPA build missing; running web-build-spa..."; \
|
|
|
|
|
$(MAKE) web-build-spa; \
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
build-spa: web-build-spa
|
|
|
|
|
|
|
|
|
|
web-build-ssr:
|
|
|
|
|
@cd $(WEB_DIR) && $(PNPM) build
|
|
|
|
|
|
|
|
|
|
web-typecheck:
|
|
|
|
|
@cd $(WEB_DIR) && $(PNPM) typecheck
|
|
|
|
|
|
|
|
|
|
web-lint:
|
|
|
|
|
@cd $(WEB_DIR) && $(PNPM) lint
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
generator:
|
2026-05-23 22:44:06 +08:00
|
|
|
@$(GO) run ./cmd/generator/generator.go
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
enums:
|
2026-05-23 22:44:06 +08:00
|
|
|
@$(GO) run ./cmd/enums/generator.go
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
migration:
|
2026-05-23 22:44:06 +08:00
|
|
|
@$(GO) run ./cmd/migration
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
testdata:
|
2026-05-23 22:44:06 +08:00
|
|
|
@$(GO) run ./cmd/testdata
|