Files
qurani/scripts/run-tests.sh
T
2026-11-11 20:25:21 +01:00

33 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Lint, typecheck and tests for every application.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
source "$ROOT/scripts/config.sh"
log() { printf '==> %s\n' "$*"; }
fail() { printf 'ERROR: %s\n' "$*" >&2; exit 1; }
detect_pm() {
local dir="$1"
if [ -f "$dir/pnpm-lock.yaml" ]; then echo pnpm
elif [ -f "$dir/yarn.lock" ]; then echo yarn
elif [ -f "$dir/package-lock.json" ]; then echo npm
else fail "No lockfile in $dir."
fi
}
for d in $APP_DIRS; do
[ -f "$d/package.json" ] || fail "$d/package.json does not exist yet (task T-006)."
pm="$(detect_pm "$d")"
[ -d "$d/node_modules" ] || { log "Installing dependencies in $d"; (cd "$d" && "$pm" install --frozen-lockfile 2>/dev/null || (cd "$d" && npm ci)); }
for s in lint typecheck test; do
if (cd "$d" && node -e "process.exit(require('./package.json').scripts && require('./package.json').scripts['$s'] ? 0 : 1)"); then
log "Running '$s' in $d"
(cd "$d" && "$pm" run "$s")
else
fail "Script '$s' is missing in $d/package.json."
fi
done
done
log "SUCCESS (all checks passed)"