#!/bin/bash
# 开发服务日志记录脚本

LOG_DIR="logs/dev-logs"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
mkdir -p "$LOG_DIR"

CURRENT_LOG="$LOG_DIR/dev-current.log"
ARCHIVE_LOG="$LOG_DIR/dev-$TIMESTAMP.log"

# Session 分隔符
echo "" >> "$CURRENT_LOG"
echo "===== SESSION START: $(date) =====" >> "$CURRENT_LOG"

# 运行并记录到两个文件（current + timestamped）
pnpm run build:mini-ui-packages && concurrently \
  "pnpm run dev:mini" \
  "pnpm run dev:mini-talent" \
  "pnpm run dev:weapp" \
  "pnpm run dev:weapp-talent" \
  "pnpm run dev:web" \
  2>&1 | tee -a "$CURRENT_LOG" > "$ARCHIVE_LOG"

# 清理超过 7 天的旧日志
find "$LOG_DIR" -name "dev-*.log" -mtime +7 -delete
