98 lines
3.2 KiB
Bash
98 lines
3.2 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
# ============================================================
|
||
|
|
# X-Financial Reimbursement Admin - Start Script
|
||
|
|
# ============================================================
|
||
|
|
|
||
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
|
|
cd "$SCRIPT_DIR"
|
||
|
|
|
||
|
|
# Colors
|
||
|
|
RED='\033[0;31m'
|
||
|
|
GREEN='\033[0;32m'
|
||
|
|
YELLOW='\033[1;33m'
|
||
|
|
NC='\033[0m'
|
||
|
|
|
||
|
|
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
|
||
|
|
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
|
||
|
|
error() { echo -e "${RED}[ERROR]${NC} $*"; exit 1; }
|
||
|
|
|
||
|
|
# ----------------------------------------------------------
|
||
|
|
# Check Node.js
|
||
|
|
# ----------------------------------------------------------
|
||
|
|
if ! command -v node &>/dev/null; then
|
||
|
|
error "Node.js is not installed. Install it first: https://nodejs.org"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if ! command -v npm &>/dev/null; then
|
||
|
|
error "npm is not installed. It should come with Node.js."
|
||
|
|
fi
|
||
|
|
|
||
|
|
info "Node.js $(node -v) | npm $(npm -v)"
|
||
|
|
|
||
|
|
# ----------------------------------------------------------
|
||
|
|
# Detect WSL + Windows node_modules platform mismatch
|
||
|
|
# ----------------------------------------------------------
|
||
|
|
is_wsl() {
|
||
|
|
grep -qi microsoft /proc/version 2>/dev/null
|
||
|
|
}
|
||
|
|
|
||
|
|
check_platform_mismatch() {
|
||
|
|
local rollup_dir="node_modules/@rollup"
|
||
|
|
if [ ! -d "$rollup_dir" ]; then
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
# List installed rollup platform packages
|
||
|
|
local platforms
|
||
|
|
platforms="$(ls -1 "$rollup_dir" 2>/dev/null | grep -E '^rollup-(win|linux)')"
|
||
|
|
if [ -z "$platforms" ]; then
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
# Running on WSL/Linux but has Windows rollup bindings
|
||
|
|
if echo "$platforms" | grep -q "win32"; then
|
||
|
|
return 0
|
||
|
|
fi
|
||
|
|
return 1
|
||
|
|
}
|
||
|
|
|
||
|
|
# ----------------------------------------------------------
|
||
|
|
# Install dependencies if node_modules is missing or mismatched
|
||
|
|
# ----------------------------------------------------------
|
||
|
|
NEED_INSTALL=false
|
||
|
|
|
||
|
|
if [ ! -d "node_modules" ]; then
|
||
|
|
warn "node_modules not found"
|
||
|
|
NEED_INSTALL=true
|
||
|
|
elif is_wsl && check_platform_mismatch; then
|
||
|
|
warn "Detected WSL with Windows node_modules (rollup platform mismatch)"
|
||
|
|
warn "Removing node_modules to reinstall with correct platform bindings..."
|
||
|
|
# WSL can't delete locked Windows .exe/.node files, use PowerShell instead
|
||
|
|
WIN_PATH="$(wslpath -w "$SCRIPT_DIR")"
|
||
|
|
if command -v powershell.exe &>/dev/null; then
|
||
|
|
powershell.exe -NoProfile -Command "Remove-Item -Recurse -Force '${WIN_PATH}\\node_modules','${WIN_PATH}\\package-lock.json'" 2>/dev/null || true
|
||
|
|
elif command -v cmd.exe &>/dev/null; then
|
||
|
|
cmd.exe /c "rd /s /q \"${WIN_PATH}\\node_modules\"" 2>/dev/null || true
|
||
|
|
cmd.exe /c "del /f /q \"${WIN_PATH}\\package-lock.json\"" 2>/dev/null || true
|
||
|
|
else
|
||
|
|
rm -rf node_modules package-lock.json 2>/dev/null || true
|
||
|
|
fi
|
||
|
|
# Fallback: clean up anything remaining via WSL
|
||
|
|
rm -rf node_modules package-lock.json 2>/dev/null || true
|
||
|
|
NEED_INSTALL=true
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ "$NEED_INSTALL" = true ]; then
|
||
|
|
info "Running npm install..."
|
||
|
|
npm install
|
||
|
|
fi
|
||
|
|
|
||
|
|
# ----------------------------------------------------------
|
||
|
|
# Start dev server
|
||
|
|
# ----------------------------------------------------------
|
||
|
|
info "Starting X-Financial Reimbursement Admin..."
|
||
|
|
info "Access: http://127.0.0.1:5173"
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
exec npm start
|