-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-run.sh
More file actions
executable file
·71 lines (63 loc) · 3.16 KB
/
dev-run.sh
File metadata and controls
executable file
·71 lines (63 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
set -eu
ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
cd "$ROOT_DIR"
mkdir -p logs data
touch logs/.gitkeep
if [ ! -f .env ]; then
echo "[dev-run] Missing .env in $ROOT_DIR" >&2
exit 1
fi
# Validate Node.js version (must be >= 20)
NODE_MAJOR=$(node -v 2>/dev/null | sed 's/v\([0-9]*\).*/\1/' || echo 0)
if [ "$NODE_MAJOR" -lt 20 ] 2>/dev/null; then
echo "[dev-run] ERROR: Node.js 20+ required. Found: $(node -v 2>/dev/null || echo 'not found')" >&2
exit 1
fi
# Optionally pull latest code (off by default in dev to preserve local changes).
# Reads RUNEWAGER_AUTO_UPDATE from environment first, then from .env as fallback.
# Set RUNEWAGER_AUTO_UPDATE=1 in environment or .env to enable auto-pull.
_AUTO_UPD_DOTENV=$(grep -E '^RUNEWAGER_AUTO_UPDATE=' "$ROOT_DIR/.env" 2>/dev/null | head -1 | cut -d= -f2 | cut -d'#' -f1 | tr -d '"' | tr -d "'" | tr -d ' ' || true)
_AUTO_UPDATE="${RUNEWAGER_AUTO_UPDATE:-${_AUTO_UPD_DOTENV:-0}}"
if [ "$_AUTO_UPDATE" = "1" ]; then
echo "[dev-run] Fetching latest code from origin main..."
if git -C "$ROOT_DIR" fetch origin main 2>&1; then
# Read RUNEWAGER_FORCE_RESET from env then .env fallback (default: off).
# Only perform the destructive reset --hard when explicitly opted in.
_FORCE_RST_DOTENV=$(grep -E '^RUNEWAGER_FORCE_RESET=' "$ROOT_DIR/.env" 2>/dev/null | head -1 | cut -d= -f2 | cut -d'#' -f1 | tr -d '"' | tr -d "'" | tr -d ' ' || true)
_FORCE_RESET="${RUNEWAGER_FORCE_RESET:-${_FORCE_RST_DOTENV:-0}}"
if [ "$_FORCE_RESET" = "1" ]; then
echo "[dev-run] RUNEWAGER_FORCE_RESET=1 — running git reset --hard origin/main..."
if git -C "$ROOT_DIR" reset --hard origin/main 2>&1; then
echo "[dev-run] Code hard-reset to $(git -C "$ROOT_DIR" rev-parse --short HEAD)"
else
echo "[dev-run] WARN: git reset --hard failed — starting with local copy"
fi
else
if git -C "$ROOT_DIR" merge --ff-only origin/main 2>&1; then
echo "[dev-run] Code updated to $(git -C "$ROOT_DIR" rev-parse --short HEAD)"
else
echo "[dev-run] WARN: fast-forward merge failed (local commits diverged?). Set RUNEWAGER_FORCE_RESET=1 to hard-reset."
fi
fi
else
echo "[dev-run] WARN: git fetch failed — starting with local copy"
fi
else
echo "[dev-run] RUNEWAGER_AUTO_UPDATE not set — skipping git pull (set to 1 in .env or environment to enable)"
fi
# Refresh tooltips
TOOLTIP_SCRIPT="$ROOT_DIR/generate_tooltips.sh"
if [ -x "$TOOLTIP_SCRIPT" ]; then
echo "[dev-run] Refreshing tooltips..."
RUNEWAGER_DIR="$ROOT_DIR" sh "$TOOLTIP_SCRIPT" >/dev/null 2>&1 \
|| echo "[dev-run] WARN: generate_tooltips.sh failed (non-fatal)"
fi
# Kill anything blocking port 3000 (or PORT from .env)
DEV_PORT=$(grep -E '^PORT=' "$ROOT_DIR/.env" 2>/dev/null | head -1 | cut -d= -f2 | cut -d'#' -f1 | tr -d '"' | tr -d "'" | tr -d ' ' || true)
DEV_PORT="${DEV_PORT:-3000}"
bash "$ROOT_DIR/scripts/helpers/free_port.sh" "$DEV_PORT" "runewager.service" \
|| echo "[dev-run] WARN: free_port.sh failed (non-fatal)"
# Foreground local run (Termux-safe). Runtime env is loaded by index.js via dotenv.
echo "[dev-run] Starting Runewager in foreground (Node $(node -v))..."
exec node index.js