.PHONY: build check test fmt clippy run deploy ts

build:
	cargo build --release

check: fmt clippy test

fmt:
	cargo fmt --all -- --check

clippy:
	cargo clippy --workspace --all-targets -- -D warnings

test:
	cargo test --workspace

run:
	cargo run -- --data data serve

# TypeScript declarations of the API types, for the VS Code extensions.
ts:
	cargo run -q -p hub-api --bin hub-api-typescript > crates/hub-api/ts/index.d.ts

# Developer edition on Earth (docs/deploy.md).
deploy:
	rsync -a --delete --exclude target --exclude node_modules --exclude .oxy/objects/loose --exclude images/rust/vendor --exclude images/rust/npm-cache --exclude images/rust/warm ../oxygen ../oxygenflow ../oxygenhub claude@earth:src/
	B="$$(oxy --plain describe 2>/dev/null)"; ssh claude@earth "source ~/.cargo/env && cd src/oxygenhub && OXY_BUILD='$$B' cargo build --release && sudo install -m 0755 target/release/oxygenhub /usr/local/bin/oxygenhub && sudo systemctl restart oxygenhub && systemctl is-active oxygenhub"

# Move the pinned oxygenflow (deps/oxygenflow) to its main on Earth, with the
# oxygen it pins; the next commit records the new pin. Push oxygen, then
# oxygenflow (with `make pins` there), first.
.PHONY: pins
pins:
	cd deps/oxygenflow && oxy --plain pull origin && oxy --plain submodule update --init
