.PHONY: all build build-fe build-be test test-fe test-be lint lint-fe lint-be run dev clean

all: build

# Build the webapp first so `webapp/dist` exists for the backend to serve,
# then build the Rust binary.
build: build-fe build-be

build-fe:
	cd webapp && npm install && npm run build

build-be:
	cargo build --release

test: test-be test-fe

test-be:
	cargo test

test-fe:
	cd webapp && npm run build

lint: lint-be lint-fe

lint-be:
	cargo fmt -- --check
	cargo clippy --all-targets -- -D warnings

lint-fe:
	cd webapp && npm run lint

# Run the built binary, serving the webapp from webapp/dist.
run: build
	./target/release/ottyl

# Frontend dev server with hot reload (proxy API calls to a separately
# running `cargo run` backend — see webapp/vite.config for the proxy setup).
dev:
	cd webapp && npm run dev

clean:
	cargo clean
	rm -rf webapp/dist webapp/node_modules
	rm profile.json.gz

