Files
vstats/scripts/start-dev.sh
zsai001 efff762dc6 feat: 迁移到 Go 实现,移除 Rust 构建
- 添加 Go 版本的 server 和 agent 实现
- 移除 Rust 构建工作流 (release.yml)
- 更新 start-dev.sh 使用 Go 版本
- 更新 build-release.sh 使用 Go 版本
- 添加 FreeBSD 支持
- 添加 GitHub Actions 工作流用于 Go 构建和发布
- 支持多平台构建 (Linux, macOS, Windows, FreeBSD)
- 支持版本号注入到二进制文件
2025-12-03 00:35:35 +08:00

101 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
#
# Development server start script
# Rebuilds frontend and backend, then starts the server
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
SERVER_DIR="$PROJECT_ROOT/server-go"
AGENT_DIR="$PROJECT_ROOT/agent-go"
WEB_DIR="$PROJECT_ROOT/web"
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo -e "${BLUE} vStats Development Server ${NC}"
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo ""
# Check if Go is installed
if ! command -v go &> /dev/null; then
echo -e "${RED}Error: Go is not installed. Please install Go 1.22 or later.${NC}"
exit 1
fi
# Build frontend
echo -e "${YELLOW}[1/4]${NC} Building frontend..."
cd "$WEB_DIR"
if [ ! -d "node_modules" ]; then
npm install
fi
npm run build
echo -e "${GREEN}✓ Frontend built${NC}"
echo ""
# Build backend
echo -e "${YELLOW}[2/4]${NC} Building backend..."
cd "$SERVER_DIR"
go build -o "$PROJECT_ROOT/vstats-server-dev" .
echo -e "${GREEN}✓ Backend built${NC}"
echo ""
# Build agent (optional, for testing)
echo -e "${YELLOW}[3/4]${NC} Building agent..."
cd "$AGENT_DIR"
go build -o "$PROJECT_ROOT/vstats-agent-dev" .
echo -e "${GREEN}✓ Agent built${NC}"
echo ""
# Set environment variables
export VSTATS_PORT=3001
export VSTATS_WEB_DIR="$WEB_DIR/dist"
SERVER_BINARY="$PROJECT_ROOT/vstats-server-dev"
# Kill existing vstats-server processes
echo -e "${YELLOW}[0/4]${NC} Stopping existing services..."
if pgrep -f "vstats-server" > /dev/null 2>&1; then
echo -e "${YELLOW} Found running vstats-server processes, stopping...${NC}"
pkill -f "vstats-server" || true
sleep 1
# Force kill if still running
if pgrep -f "vstats-server" > /dev/null 2>&1; then
pkill -9 -f "vstats-server" || true
sleep 0.5
fi
echo -e "${GREEN}✓ Old services stopped${NC}"
else
echo -e "${GREEN}✓ No existing services found${NC}"
fi
echo ""
# Reset password to get a fresh one for development
echo -e "${YELLOW}[4/4]${NC} Resetting admin password..."
PASSWORD_OUTPUT=$("$SERVER_BINARY" --reset-password 2>&1)
# Extract password from output (format: "New admin password: {password}")
ADMIN_PASSWORD=$(echo "$PASSWORD_OUTPUT" | grep "New admin password:" | sed -E 's/.*New admin password: +([^ ]+).*/\1/' | tr -d ' ')
if [ -z "$ADMIN_PASSWORD" ]; then
ADMIN_PASSWORD="admin"
fi
echo -e "${GREEN}✓ Password reset${NC}"
echo ""
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo -e "${GREEN}Server: http://localhost:3001${NC}"
echo -e "${GREEN}Web: $VSTATS_WEB_DIR${NC}"
echo -e "${GREEN}Pass: ${ADMIN_PASSWORD}${NC}"
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo ""
# Change to project root and run
cd "$PROJECT_ROOT"
"$SERVER_BINARY"