#!/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..." # 确保使用生产环境模式构建,避免使用开发环境配置 export NODE_ENV=production 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 # 只检查 dist 目录的变化,不检查其他文件 DIST_STATUS=$(git status --porcelain apps/web-antd/dist) if [ -n "$DIST_STATUS" ]; then echo "📝 Staging build artifacts..." # 只添加 dist 目录,不添加其他文件 # 使用 -f 强制添加被 .gitignore 忽略的 dist 目录 git add -f apps/web-antd/dist echo "💾 Committing changes..." # 使用 --no-verify 跳过 pre-commit hooks,避免检查大量构建产物文件 # 注意:不要使用 [skip ci],否则 CI/CD 不会触发 git commit --no-verify -m "chore: build and deploy web-antd" || 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 in dist directory to commit" echo "Note: Only dist directory changes will be committed, other files are ignored" fi else echo "ℹ️ Skipping git push. You can manually commit and push later." fi echo "✨ Done!"