#!/bin/bash
# 打包脚本

set -e

echo "📦 开始构建 bilibili-dl 包..."
echo ""

# 1. 清理旧构建
echo "🧹 清理旧构建文件..."
rm -rf build/ dist/ *.egg-info
echo "✅ 清理完成"
echo ""

# 2. 检查依赖
echo "🔍 检查打包工具..."
if ! command -v python3 &> /dev/null; then
    echo "❌ 错误: 未找到 python3"
    exit 1
fi

# 安装打包工具
echo "📥 安装/更新打包工具..."
python3 -m pip install --upgrade pip build twine setuptools wheel --quiet
echo "✅ 工具就绪"
echo ""

# 3. 构建包
echo "🔨 构建分发包..."
python3 -m build
echo "✅ 构建完成"
echo ""

# 4. 检查包
echo "🔍 检查包完整性..."
python3 -m twine check dist/*
echo ""

# 5. 显示构建结果
echo "📊 构建结果:"
echo "----------------------------------------"
ls -lh dist/
echo "----------------------------------------"
echo ""

# 6. 提示后续步骤
echo "✅ 打包完成!"
echo ""
echo "📝 后续步骤:"
echo ""
echo "1️⃣  本地测试安装:"
echo "   pip install dist/bilibili_dl-*.whl"
echo ""
echo "2️⃣  上传到测试 PyPI:"
echo "   twine upload --repository testpypi dist/*"
echo ""
echo "3️⃣  上传到正式 PyPI:"
echo "   twine upload dist/*"
echo ""
echo "4️⃣  安装测试:"
echo "   pip install bilibili-dl"
echo ""
