# reqlite tasks. Install `just` and `cargo-deny`:
#   cargo install --locked just cargo-deny

set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]

# The quality bar: format, lint, test, licenses/advisories.
check: fmt-check clippy test deny

fmt:
    cargo fmt --all

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

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

test:
    cargo test --workspace

deny:
    cargo deny check

# Accept changed insta snapshots after reviewing them.
snapshots:
    INSTA_UPDATE=always cargo test --workspace

# Static release build of the GUI and the CLI (libcurl is linked in).
release:
    cargo build --release --workspace
    @echo "Binaries are in target/release/: reqlite-gui and reqlite"

# The GUI with the OpenGL renderer, for old GPUs, VMs and remote desktops.
release-glow:
    cargo build --release -p reqlite-app --features glow

run *ARGS:
    cargo run -p reqlite-app -- {{ARGS}}

cli *ARGS:
    cargo run -p reqlite-cli -- {{ARGS}}

# Install a git pre-push hook that runs `just check`.
install-hook:
    printf '#!/bin/sh\nexec just check\n' > .git/hooks/pre-push
    chmod +x .git/hooks/pre-push

# Linux tarball: target/dist/reqlite-<version>-linux-<arch>.tar.gz
package-linux: release
    #!/usr/bin/env sh
    set -eu
    version=$(cargo pkgid -p reqlite-app | sed 's/.*[#@]//')
    name="reqlite-${version}-linux-$(uname -m)"
    dir="target/dist/${name}"
    rm -rf "$dir" && mkdir -p "$dir"
    cp target/release/reqlite-gui target/release/reqlite "$dir/"
    cp crates/app/assets/icon.png "$dir/reqlite.png"
    cp crates/app/assets/reqlite.desktop README.md "$dir/"
    tar -C target/dist -czf "target/dist/${name}.tar.gz" "$name"
    echo "target/dist/${name}.tar.gz"

# Windows portable zip: target\dist\reqlite-<version>-windows-x86_64.zip
package-windows: release
    $version = (cargo pkgid -p reqlite-app) -replace '.*[#@]', ''; \
    $dir = "target/dist/reqlite-$version-windows-x86_64"; \
    New-Item -ItemType Directory -Force -Path $dir | Out-Null; \
    Copy-Item target/release/reqlite-gui.exe, target/release/reqlite.exe, README.md -Destination $dir; \
    Compress-Archive -Force -Path $dir -DestinationPath "$dir.zip"; \
    Write-Output "$dir.zip"
