#!/bin/bash

# QZMusic-Web 一键部署脚本
# 端口：10096

echo "=========================================="
echo "   QZMusic-Web 一键部署"
echo "=========================================="
echo ""

# 检查Node.js是否安装
if ! command -v node &> /dev/null; then
    echo "❌ Node.js 未安装！请先安装 Node.js"
    exit 1
fi

echo "✅ Node.js 版本: $(node -v)"

# 检查npm是否安装
if ! command -v npm &> /dev/null; then
    echo "❌ npm 未安装！"
    exit 1
fi

echo "✅ npm 版本: $(npm -v)"
echo ""

# 安装依赖
echo "📦 正在安装依赖..."
npm install

if [ $? -ne 0 ]; then
    echo "❌ 依赖安装失败！"
    exit 1
fi

echo "✅ 依赖安装成功！"
echo ""

# 构建项目
echo "🔨 正在构建项目..."
npm run build

if [ $? -ne 0 ]; then
    echo "❌ 构建失败！"
    exit 1
fi

echo "✅ 项目构建成功！"
echo ""

echo "=========================================="
echo "   部署完成！"
echo "=========================================="
echo ""
echo "📂 构建产物目录: ./dist"
echo ""
echo "🚀 启动方式："
echo "   开发模式: npm run dev"
echo "   预览模式: npm run preview"
echo ""
echo "🌐 访问地址: http://localhost:10096"
echo ""
