[tools]
# REMEMBER TO UPDATE .tool-versions TOO
go = "1.24.4"
pnpm = "10.4.0"
node = "22.16"

[tasks.copy-wasm-shim]
alias = ["gojs"]
description = "Copies Go's wasm_exec.js to the public directory"
run = [
	"echo // $(go version) > app/wasm_exec.js",
	"cat $(go env GOROOT)/lib/wasm/wasm_exec.js >> app/wasm_exec.js",
]

[tasks.build-go-wasm]
alias = ["wasm"]
depends = ["copy-wasm-shim"]
description = "Builds the Go WebAssembly module for Tailscale SSH"
env = { GOOS = "js", GOARCH = "wasm" }
run = "go build -o app/hp_ssh.wasm ./cmd/hp_ssh"

[tasks.build-go-agent]
alias = ["agent"]
description = "Builds the Go agent for HostInfo"
run = "go build -o build/hp_agent ./cmd/hp_agent"
# env = { CGO_ENABLED = "1" }
# run = "go build -o build/hp_agent.so -buildmode=c-shared ./cmd/hp_agent"


[tasks.build-fake-shell]
alias = ["fake-shell"]
description = "Builds the fake shell for Distroless docker images"
run = [
	'test -n "$IMAGE_TAG" || (echo "IMAGE_TAG is not set" && exit 1)',
	'go build -ldflags="-s -w -X main.imageTag=$IMAGE_TAG" -o build/sh ./cmd/fake_sh'
]

[tasks.build-nixos-docs]
alias = ["nixos-docs"]
description = "Builds NixOS module documentation"
run = [
	'nix build .#headplane-nixos-docs',
	'cp --dereference --force ./result ./docs/NixOS-options.md',
	'sed -i "s;\[/nix.*;\[nix/options.nix\](https://github.com/tale/headplane/blob/main/nix/options.nix);" ./docs/NixOS-options.md'
]

[tasks.generate-caddy-certs]
alias = ["mkcert"]
dir = "{{cwd}}/test/caddy/certs"
run = [
	"mkdir -p {{cwd}}/test/caddy/certs",
	"mkcert -install",
	"mkcert localhost"
]

[tasks.ci]
description = "Runs the CI pipeline"
depends = ["build-go-wasm"]
depends_post = ["build-go-agent"]
run = [
	"pnpm install",
	"pnpm run build"
]
