#!/bin/bash

# QZMusic-Web 启动脚本
# 端口：1219

echo "=========================================="
echo "   启动 QZMusic-Web"
echo "=========================================="
echo ""

# 检查是否已安装依赖
if [ ! -d "node_modules" ]; then
    echo "📦 依赖未安装，正在安装..."
    npm install
    if [ $? -ne 0 ]; then
        echo "❌ 依赖安装失败！"
        exit 1
    fi
fi

# 选择启动模式
echo "请选择启动模式："
echo "  1) 开发模式（带热更新）"
echo "  2) 生产模式（静态文件服务）"
read -p "请输入选项 (1/2，默认 2): " choice

case ${choice:-2} in
    1)
        echo ""
        echo "🚀 正在启动开发服务器..."
        echo "🌐 访问地址: http://localhost:1219"
        echo ""
        echo "按 Ctrl+C 停止服务器"
        echo ""
        npm run dev
        ;;
    2)
        # 检查是否已构建
        if [ ! -d "dist" ]; then
            echo "📦 未找到构建文件，正在构建..."
            npm run build
            if [ $? -ne 0 ]; then
                echo "❌ 构建失败！"
                exit 1
            fi
        fi
        echo ""
        echo "🚀 正在启动生产服务器..."
        echo "🌐 访问地址: http://[你的IP]:1219"
        echo ""
        echo "按 Ctrl+C 停止服务器"
        echo ""
        npm run serve
        ;;
    *)
        echo "❌ 无效选项！"
        exit 1
        ;;
esac
