# Justfile — project-wide build and dev commands
# Install with: cargo install just
# Usage: just <recipe>

# Default: list all recipes
default:
    @just --list

# ── Setup ──────────────────────────────────────────────────────────────────────

# Install all required tools
setup:
    @echo "Installing build tools..."
    cargo install trunk          # WASM bundler
    cargo install wasm-bindgen-cli
    rustup target add wasm32-unknown-unknown
    @echo "All tools installed!"

# ── Native builds ──────────────────────────────────────────────────────────────

# Run the asset viewer (native, debug)
run:
    cargo run --bin sylpheed-viewer

# Run with hot-reloading enabled (faster iteration)
run-dev:
    cargo run --bin sylpheed-viewer --features sylpheed-viewer/dev

# Build native release
build-native:
    cargo build --release --bin sylpheed-viewer

# Run the CLI
cli *ARGS:
    cargo run --bin sylpheed-cli -- {{ARGS}}

# ── WASM / Web builds ──────────────────────────────────────────────────────────

# Start WASM dev server with hot-reload
web:
    trunk serve

# Build WASM release bundle (output in ./dist/)
build-web:
    trunk build --release

# ── Extraction shortcuts ───────────────────────────────────────────────────────

# Extract an ISO to ./assets/ (required before running the viewer)
# Usage: just extract path/to/game.iso
extract ISO:
    cargo run --bin sylpheed-cli -- extract {{ISO}} ./assets/
    @echo "Extraction complete. Run: just run"

# List files in an ISO
# Usage: just list path/to/game.iso
list ISO:
    cargo run --bin sylpheed-cli -- list {{ISO}}

# Sniff file formats in ./assets/
sniff:
    cargo run --bin sylpheed-cli -- sniff ./assets/

# Sniff but only show unknown formats (focus RE effort)
sniff-unknown:
    cargo run --bin sylpheed-cli -- sniff ./assets/ --unknown-only

# ── Testing ────────────────────────────────────────────────────────────────────

# Run all tests
test:
    cargo test --workspace

# Run tests including ISO integration tests (requires SYLPHEED_ISO env var)
test-integration:
    SYLPHEED_ISO=./game.iso cargo test --workspace -- --include-ignored

# ── Code quality ──────────────────────────────────────────────────────────────

# Format all code
fmt:
    cargo fmt --all

# Lint
lint:
    cargo clippy --workspace -- -D warnings

# Check everything compiles (faster than full build)
check:
    cargo check --workspace
    cargo check --workspace --target wasm32-unknown-unknown

# ── All platforms CI check ────────────────────────────────────────────────────

# Full CI: format check + lint + test + WASM compile check
ci:
    cargo fmt --all -- --check
    cargo clippy --workspace -- -D warnings
    cargo test --workspace
    cargo check --target wasm32-unknown-unknown -p sylpheed-viewer
    @echo "All CI checks passed!"
