#!/usr/bin/env bash # Safety settings set -o errexit # Exit on error set -o errtrace # Exit on error inside functions set -o nounset # Error on undefined variables set -o pipefail # Error if any command in a pipe fails # Constants readonly SCRIPT_NAME="$(basename "$0")" readonly WORK_DIR="/home/acedanger/dev/finance" # Functions log() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $*" } error() { echo "ERROR: $*" >&2 } validate_dependencies() { command -v npx >/dev/null || error "npx is not installed" && exit 1 command -v docker >/dev/null || error "docker is not installed" && exit 1 command -v npm >/dev/null || error "npm is not installed" && exit 1 } # Main script logic log "Resetting finance development environment..." cd "$WORK_DIR" || { error "Failed to change directory to $WORK_DIR" exit 1 } validate_dependencies if ! npx prisma migrate reset --force; then error "Prisma migration reset failed" exit 1 fi docker compose down || { error "Failed to take down Docker containers" exit 1 } rm -f package-lock.json [[ -d dist ]] && rm -rf dist || true [[ -d node_modules ]] && rm -rf node_modules || true npm install || { error "Failed to install npm dependencies" exit 1 } npm run build || { error "Failed to build the project" exit 1 } docker compose -f docker-compose.yml up -d || { error "Failed to bring up Docker containers" exit 1 } log "Environment reset complete."