#!/usr/bin/env bash
set -euo pipefail

mode="${1:-full}"
case "$mode" in
    focused|full|build) ;;
    *)
        printf 'Usage: %s [focused|full|build]\n' "$0" >&2
        exit 64
        ;;
esac

root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root_dir/admin"

npm ci

case "$mode" in
    focused)
        npm run lint:js
        npm run build
        node --test ../tools/admin-dom-helper-imports.test.mjs
        npm test -- --run tests/admin-stores.test.js tests/data-region.test.js tests/data-region-states.test.js
        ;;
    full)
        npm run lint:js
        npm run build
        node --test ../tools/admin-dom-helper-imports.test.mjs
        npm test -- --run
        ;;
    build)
        npm run build
        ;;
    *)
        printf 'Usage: %s [focused|full|build]\n' "$0" >&2
        exit 64
        ;;
esac
