#!/usr/bin/env bash # # Full project check: formatting, linting, type-checking, building and tests for # both the Rust backend and the SvelteKit frontend. Run by the pre-push hook # (.githooks/pre-push) and usable by hand or in CI. # # Usage: # scripts/check.sh # check everything # scripts/check.sh backend # backend only # scripts/check.sh frontend # frontend only # # Backend integration tests (tests/api.rs) need a throwaway Postgres database. # Point TEST_DATABASE_URL at one to run them; otherwise they skip: # TEST_DATABASE_URL=postgres://shoplist:devpass@localhost:5432/shoplist_test \ # scripts/check.sh backend set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" TARGET="${1:-all}" # Pretty section headers. section() { printf '\n\033[1;35m▸ %s\033[0m\n' "$1"; } ok() { printf '\033[1;32m✓ %s\033[0m\n' "$1"; } check_backend() { section "Backend (Rust)" cd "$ROOT/backend" echo "• cargo fmt --check" cargo fmt --all -- --check echo "• cargo clippy (-D warnings)" cargo clippy --all-targets --all-features -- -D warnings echo "• cargo build" cargo build --all-targets if [ -n "${TEST_DATABASE_URL:-}" ]; then echo "• cargo test (with integration DB)" else echo "• cargo test (unit only — set TEST_DATABASE_URL for integration)" fi cargo test --all-targets ok "backend" } check_frontend() { section "Frontend (SvelteKit)" cd "$ROOT/frontend" # Make sure deps are present (lockfile-faithful) before checking. if [ ! -d node_modules ]; then echo "• pnpm install" pnpm install --frozen-lockfile fi echo "• prettier --check" pnpm run format:check echo "• eslint" pnpm run lint echo "• svelte-check" pnpm run check echo "• vitest" pnpm test echo "• vite build" pnpm run build ok "frontend" } case "$TARGET" in backend) check_backend ;; frontend) check_frontend ;; all) check_backend; check_frontend ;; *) echo "unknown target: $TARGET (use: all | backend | frontend)" >&2; exit 2 ;; esac printf '\n\033[1;32m✓ all checks passed\033[0m\n'