#
# Just configuration.
#
# https://just.systems/man/en
#

# List recipes.
help:
    just --list

# Prepare the toolchain.
prepare-toolchain:
    # Install JavaScript dependencies.
    if [[ -z "${CI:-}" ]]; then bun install; else bun install --frozen-lockfile; fi

# Start the frontend server.
start-frontend: prepare-toolchain
    # Start the frontend server.
    bun run vite dev

# Start the backend server.
start-backend:
    # Start the backend server.
    just ../multi-storage-client/start-explorer

# Run static analysis (format, lint).
analyze: prepare-toolchain
    # Format + lint.
    if [[ -z "${CI:-}" ]]; then bun run eslint --fix; else bun run eslint; fi

# Run unit tests.
run-unit-tests: prepare-toolchain
    # Remove test artifacts.
    rm -rf .reports/unit
    # Run unit tests.
    bun run vitest run --coverage

# Create frontend bundle.
bundle: prepare-toolchain
    # Remove frontend bundle.
    rm -rf ../multi-storage-client/src/multistorageclient/explorer/static
    # Create frontend bundle.
    bun run vite build

# Release build.
build: analyze run-unit-tests bundle
