mirror of
https://github.com/acedanger/finance.git
synced 2025-12-05 22:50:12 -08:00
reformatted to adhere to the code format section of https://github.com/acedanger/finance/blob/main/.github/copilot-instructions.md#shell-scripts
This commit is contained in:
@@ -1,21 +1,67 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -euo pipefail
|
# 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
|
||||||
|
|
||||||
echo "Resetting finance development environment..."
|
# Constants
|
||||||
|
readonly SCRIPT_NAME="$(basename "$0")"
|
||||||
|
readonly WORK_DIR="/home/acedanger/dev/finance"
|
||||||
|
|
||||||
cd /home/acedanger/dev/finance || exit 1
|
# Functions
|
||||||
|
log() {
|
||||||
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $*"
|
||||||
|
}
|
||||||
|
|
||||||
npx prisma migrate reset --force || exit 1
|
error() {
|
||||||
|
echo "ERROR: $*" >&2
|
||||||
|
}
|
||||||
|
|
||||||
docker compose down
|
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
|
rm -f package-lock.json
|
||||||
[ -d dist ] && rm -rf dist || true
|
[[ -d dist ]] && rm -rf dist || true
|
||||||
[ -d node_modules ] && rm -rf node_modules || true
|
[[ -d node_modules ]] && rm -rf node_modules || true
|
||||||
npm install || exit 1
|
|
||||||
npm run build || exit 1
|
|
||||||
|
|
||||||
docker compose -f docker-compose.yml up -d
|
npm install || {
|
||||||
|
error "Failed to install npm dependencies"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
echo "$(date '+%Y-%m-%d %H:%M:%S') - Environment reset complete."
|
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."
|
||||||
Reference in New Issue
Block a user