[tools]
go = "1.24.2"
node = "24"
pnpm = "10.10.0"

[tasks.web-install]
description = "Install web dependencies"
dir = "apps/web"
run = "pnpm install --frozen-lockfile"

[tasks.web-build]
description = "Build the web app"
depends = ["web-install"]
dir = "apps/web"
run = "pnpm run build"

[tasks.web-dev]
description = "Start the Vite dev server"
dir = "apps/web"
run = "pnpm run dev"

[tasks.server-run]
description = "Run the Go server"
dir = "apps/server"
run = "CGO_ENABLED=1 go run ./cmd/cairnquire"

[tasks.server-build]
description = "Build the Go server"
dir = "apps/server"
run = "mkdir -p bin && CGO_ENABLED=1 go build -trimpath -o bin/cairnquire ./cmd/cairnquire"

[tasks.server-test]
description = "Run Go tests"
dir = "apps/server"
run = "CGO_ENABLED=1 go test ./..."

[tasks.dev-server]
description = "Run the Go server with air"
dir = "apps/server"
run = "CAIRNQUIRE_DEV_VITE_URL=http://localhost:5173 air"

[tasks.dev-web]
description = "Alias for the Vite dev server"
depends = ["web-dev"]
run = "true"

[tasks.dev]
description = "Run the Go and Vite dev servers"
run = '''
printf 'Starting dev servers...\n'
printf '  - Go server (with air live reload) on http://localhost:8080\n'
printf '  - Vite dev server on http://localhost:5173\n\n'
printf 'Access the app at http://localhost:8080/app/\n\n'

mise run dev-server &
server_pid=$!
mise run dev-web &
web_pid=$!

cleanup() {
  kill "$server_pid" "$web_pid" 2>/dev/null || true
}

trap cleanup EXIT INT TERM
wait "$server_pid" "$web_pid"
'''

[tasks.docker-build]
description = "Build the Docker image"
run = "docker build -t cairnquire:dev ."

[tasks.fmt]
description = "Run format checks"
run = '''
cd apps/server
go fmt ./...
cd ../web
pnpm run format
'''

[tasks.ci]
description = "Run the core CI checks"
depends = ["web-build", "server-test", "server-build"]
run = "true"

[tasks.vulncheck]
description = "Run govulncheck"
dir = "apps/server"
run = "go run golang.org/x/vuln/cmd/govulncheck@v1.1.4 ./..."
