Files
managing-apps/scripts/vibe-dev-server.sh

144 lines
4.6 KiB
Bash
Executable File

#!/bin/bash
# scripts/vibe-dev-server.sh
# Minimal script for Vibe Kanban worktrees
# This script runs from the worktree and uses main repo scripts for Docker setup
TASK_ID=${1:-"DEV-$(date +%Y%m%d-%H%M%S)"}
PORT_OFFSET=${2:-0}
# Detect worktree root
WORKTREE_ROOT="$(pwd)"
# Check if we're in a nested structure (Vibe Kanban worktree)
if [ -d "$WORKTREE_ROOT/managing-apps" ] && [ -d "$WORKTREE_ROOT/managing-apps/src/Managing.Api" ]; then
WORKTREE_PROJECT_ROOT="$WORKTREE_ROOT/managing-apps"
elif [ -d "$WORKTREE_ROOT/src/Managing.Api" ]; then
WORKTREE_PROJECT_ROOT="$WORKTREE_ROOT"
else
echo "❌ Cannot find project structure in worktree"
echo " Current directory: $WORKTREE_ROOT"
exit 1
fi
echo "📁 Worktree project root: $WORKTREE_PROJECT_ROOT"
# Find main repository (try common locations)
MAIN_REPO_PATHS=(
"/Users/oda/Desktop/Projects/managing-apps"
"$(git -C "$WORKTREE_PROJECT_ROOT" rev-parse --show-toplevel 2>/dev/null || echo '')"
"$(dirname "$WORKTREE_ROOT" 2>/dev/null)/managing-apps"
)
MAIN_REPO=""
for path in "${MAIN_REPO_PATHS[@]}"; do
if [ -n "$path" ] && [ -d "$path" ] && [ -d "$path/scripts" ] && [ -f "$path/scripts/start-task-docker.sh" ]; then
MAIN_REPO="$path"
break
fi
done
if [ -z "$MAIN_REPO" ]; then
echo "❌ Cannot find main repository with scripts"
echo "💡 Tried:"
for path in "${MAIN_REPO_PATHS[@]}"; do
echo " - $path"
done
exit 1
fi
echo "📁 Main repository: $MAIN_REPO"
echo "🚀 Starting dev environment..."
echo " Task ID: $TASK_ID"
echo " Port offset: $PORT_OFFSET"
# Export worktree path so main repo scripts know where to run dotnet from
export VIBE_WORKTREE_ROOT="$WORKTREE_PROJECT_ROOT"
# Call main repo's start script
bash "$MAIN_REPO/scripts/start-task-docker.sh" "$TASK_ID" "$PORT_OFFSET"
# Determine log file paths (logs are created in the worktree root)
PID_DIR="$WORKTREE_PROJECT_ROOT/.task-pids"
API_LOG="$PID_DIR/api-${TASK_ID}.log"
WORKERS_LOG="$PID_DIR/workers-${TASK_ID}.log"
# Wait for log files to be created
echo ""
echo "⏳ Waiting for services to start and log files to be created..."
for i in {1..30}; do
if [ -f "$API_LOG" ] && [ -f "$WORKERS_LOG" ]; then
echo "✅ Log files found"
break
fi
if [ $i -eq 30 ]; then
echo "⚠️ Log files not found after 30 seconds"
echo " API log: $API_LOG"
echo " Workers log: $WORKERS_LOG"
echo " Continuing anyway..."
fi
sleep 1
done
# Show logs with labels
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📋 Showing API and Workers logs (Press Ctrl+C to stop)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Check if log files exist
if [ ! -f "$API_LOG" ] && [ ! -f "$WORKERS_LOG" ]; then
echo "❌ No log files found"
echo " API log: $API_LOG"
echo " Workers log: $WORKERS_LOG"
echo "💡 Services may still be starting. You can manually view logs with:"
echo " tail -f $API_LOG"
echo " tail -f $WORKERS_LOG"
exit 1
fi
# Use multitail if available for better viewing, otherwise use simple tail
if command -v multitail >/dev/null 2>&1; then
echo "📋 Using multitail for split-screen log viewing..."
if [ -f "$API_LOG" ] && [ -f "$WORKERS_LOG" ]; then
multitail -s 2 \
-ci green -T "API" "$API_LOG" \
-ci yellow -T "Workers" "$WORKERS_LOG"
elif [ -f "$API_LOG" ]; then
tail -f "$API_LOG"
elif [ -f "$WORKERS_LOG" ]; then
tail -f "$WORKERS_LOG"
fi
else
# Simple approach: tail both files with prefixes
# Use a subshell to manage background processes
(
# Start tailing API logs in background
if [ -f "$API_LOG" ]; then
tail -f "$API_LOG" 2>/dev/null | while IFS= read -r line; do
echo "[API] $line"
done &
TAIL_API_PID=$!
fi
# Start tailing Workers logs in background
if [ -f "$WORKERS_LOG" ]; then
tail -f "$WORKERS_LOG" 2>/dev/null | while IFS= read -r line; do
echo "[WORKERS] $line"
done &
TAIL_WORKERS_PID=$!
fi
# Clean up background processes on exit
cleanup() {
[ -n "$TAIL_API_PID" ] && kill "$TAIL_API_PID" 2>/dev/null
[ -n "$TAIL_WORKERS_PID" ] && kill "$TAIL_WORKERS_PID" 2>/dev/null
exit
}
trap cleanup INT TERM EXIT
# Wait for background processes
wait
)
fi