# Veola build.
#
# Requires the `templ` CLI (go install github.com/a-h/templ/cmd/templ@latest).
# The Tailwind standalone CLI is fetched on demand into bin/ (gitignored) — no
# node toolchain required. static/css/tailwind.css is a committed build
# artifact so a plain `go build` deploy still has styles; run `make css`
# (or `make build`) after touching templates or static/css/input.css.

TAILWIND_VERSION := v3.4.17
TAILWIND_BIN     := bin/tailwindcss
# linux-x64 only; change the asset name for other platforms.
TAILWIND_URL     := https://github.com/tailwindlabs/tailwindcss/releases/download/$(TAILWIND_VERSION)/tailwindcss-linux-x64
TEMPL            := $(shell go env GOPATH)/bin/templ

.PHONY: all generate css build run test clean

all: build

$(TAILWIND_BIN):
	mkdir -p bin
	curl -sL --fail $(TAILWIND_URL) -o $(TAILWIND_BIN)
	chmod +x $(TAILWIND_BIN)

# Compile Tailwind utilities (scanned from the .templ sources) into
# static/css/tailwind.css. The hand-written component layer is app.css.
css: $(TAILWIND_BIN)
	$(TAILWIND_BIN) -c tailwind.config.js -i static/css/input.css -o static/css/tailwind.css --minify

# Regenerate templ Go from the .templ sources.
generate:
	$(TEMPL) generate

build: generate css
	go build -o veola-bin .

run: build
	./veola-bin -config config.toml

test:
	go test ./...

clean:
	rm -f veola-bin
