69 lines
1.7 KiB
Bash
69 lines
1.7 KiB
Bash
|
|
#!/bin/bash
|
|||
|
|
|
|||
|
|
# 本地构建并推送到仓库的脚本
|
|||
|
|
# 使用方法: ./scripts/deploy/build-and-push.sh
|
|||
|
|
|
|||
|
|
set -e
|
|||
|
|
|
|||
|
|
echo "🚀 Starting local build and push process..."
|
|||
|
|
|
|||
|
|
# 1. 检查是否在项目根目录
|
|||
|
|
if [ ! -f "package.json" ]; then
|
|||
|
|
echo "❌ Error: Please run this script from project root"
|
|||
|
|
exit 1
|
|||
|
|
fi
|
|||
|
|
|
|||
|
|
# 2. 清理旧的构建产物
|
|||
|
|
echo "📦 Cleaning old build artifacts..."
|
|||
|
|
rm -rf apps/web-antd/dist
|
|||
|
|
|
|||
|
|
# 3. 安装依赖(如果需要)
|
|||
|
|
if [ ! -d "node_modules" ]; then
|
|||
|
|
echo "📥 Installing dependencies..."
|
|||
|
|
pnpm install
|
|||
|
|
fi
|
|||
|
|
|
|||
|
|
# 4. 构建项目
|
|||
|
|
echo "🔨 Building project..."
|
|||
|
|
pnpm build:antd
|
|||
|
|
|
|||
|
|
# 5. 检查构建结果
|
|||
|
|
if [ ! -d "apps/web-antd/dist" ] || [ -z "$(ls -A apps/web-antd/dist)" ]; then
|
|||
|
|
echo "❌ Error: Build failed, dist directory is empty"
|
|||
|
|
exit 1
|
|||
|
|
fi
|
|||
|
|
|
|||
|
|
echo "✅ Build successful!"
|
|||
|
|
|
|||
|
|
# 6. 显示构建产物大小
|
|||
|
|
BUILD_SIZE=$(du -sh apps/web-antd/dist | cut -f1)
|
|||
|
|
echo "📊 Build size: $BUILD_SIZE"
|
|||
|
|
|
|||
|
|
# 7. 提交并推送(可选)
|
|||
|
|
read -p "Do you want to commit and push to repository? (y/n) " -n 1 -r
|
|||
|
|
echo
|
|||
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|||
|
|
# 检查是否有未提交的更改
|
|||
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|||
|
|
echo "📝 Staging build artifacts..."
|
|||
|
|
git add apps/web-antd/dist
|
|||
|
|
git add -A # 添加其他更改
|
|||
|
|
|
|||
|
|
echo "💾 Committing changes..."
|
|||
|
|
git commit -m "chore: build and deploy web-antd [skip ci]" || true
|
|||
|
|
|
|||
|
|
echo "📤 Pushing to repository..."
|
|||
|
|
git push origin master
|
|||
|
|
|
|||
|
|
echo "✅ Build artifacts pushed successfully!"
|
|||
|
|
echo "⏳ Waiting for CI/CD to deploy..."
|
|||
|
|
else
|
|||
|
|
echo "ℹ️ No changes to commit"
|
|||
|
|
fi
|
|||
|
|
else
|
|||
|
|
echo "ℹ️ Skipping git push. You can manually commit and push later."
|
|||
|
|
fi
|
|||
|
|
|
|||
|
|
echo "✨ Done!"
|
|||
|
|
|