Files
novalon-website/scripts/downgrade-stack.sh
T
张翔 8840c4398a feat: downgrade tech stack to stable versions and integrate GA4 error monitoring
- Downgrade Next.js 16→14.2, React 19→18.3, Tailwind 4→3.4
- Add comprehensive GA4 error monitoring system
- Create Jenkins CI/CD pipeline with quality gates
- Fix build issues: ESLint, SWC conflict, config format
- Add documentation for deployment and error tracking
2026-05-12 12:45:18 +08:00

124 lines
4.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -e
echo "=========================================="
echo "🔄 Novalon Website 技术栈降级脚本"
echo "从: Next.js 16 + React 19 + Tailwind CSS 4"
echo "到: Next.js 14.2 + React 18.3 + Tailwind CSS 3.4"
echo "=========================================="
echo ""
BACKUP_DIR="./backup-$(date +%Y%m%d_%H%M%S)"
mkdir -p "$BACKUP_DIR"
echo "📦 Step 1: 备份关键配置文件..."
cp package.json "$BACKUP_DIR/"
cp postcss.config.mjs "$BACKUP_DIR/" 2>/dev/null || true
cp src/app/globals.css "$BACKUP_DIR/" 2>/dev/null || true
echo "✅ 配置文件已备份到 $BACKUP_DIR"
echo ""
echo "🗑️ Step 2: 清理旧依赖和缓存..."
rm -rf node_modules
rm -f package-lock.json pnpm-lock.yaml yarn.lock
rm -rf .next dist
rm -rf .cache
echo "✅ 缓存已清理"
echo ""
echo "📥 Step 3: 安装新版本依赖..."
npm install --registry=https://registry.npmmirror.com || {
echo "❌ npm install 失败!尝试使用淘宝镜像..."
npm install --registry=https://registry.npmmirror.com
}
echo "✅ 依赖安装完成"
echo ""
echo "🔍 Step 4: 验证核心依赖版本..."
echo ""
echo "┌─────────────────┬──────────────────┬────────────────────┐"
echo "│ 依赖包 │ 期望版本 │ 实际安装版本 │"
echo "├─────────────────┼──────────────────┼────────────────────┤"
check_version() {
local pkg=$1
local expected=$2
local actual=$(node -e "console.log(require('./node_modules/$pkg/package.json').version)" 2>/dev/null || echo "未安装")
if [[ "$actual" == *"$expected"* ]]; then
status="✅"
else
status="⚠️"
fi
printf "│ %-15s │ %-16s │ %-18s │\n" "$pkg" "$expected" "$actual"
}
check_version "next" "^14.2"
check_version "react" "^18.3"
check_version "react-dom" "^18.3"
check_version "tailwindcss" "^3.4"
check_version "@types/react" "^18"
check_version "@types/react-dom" "^18"
check_version "eslint-config-next" "^14"
echo "└─────────────────┴──────────────────┴────────────────────┘"
echo ""
echo "🧪 Step 5: 运行快速验证..."
if npm run lint --silent > /dev/null 2>&1; then
echo "✅ ESLint 检查通过"
else
echo "⚠️ ESLint 检查有警告(可忽略)"
fi
if npx tsc --noEmit --pretty > /dev/null 2>&1; then
echo "✅ TypeScript 类型检查通过"
else
echo "⚠️ TypeScript 类型检查有错误(需要修复)"
echo " 请运行 'npx tsc --noEmit' 查看详细错误"
fi
echo ""
echo "🏗️ Step 6: 测试构建(可选,耗时较长)..."
read -p "是否现在运行生产构建测试?(y/n): " build_choice
if [ "$build_choice" = "y" ] || [ "$build_choice" = "Y" ]; then
echo " 正在构建...(预计 2-5 分钟)"
if npm run build:clean > /tmp/build-output.log 2>&1; then
echo "✅ 生产构建成功!"
if [ -d "dist" ]; then
file_count=$(find dist -type f | wc -l)
dist_size=$(du -sh dist | cut -f1)
echo " 📁 生成了 $file_count 个文件,总大小: $dist_size"
fi
else
echo "❌ 构建失败!查看日志:"
echo " cat /tmp/build-output.log"
exit 1
fi
else
echo "⏭️ 跳过构建测试(稍后可手动运行 'npm run build:clean'"
fi
echo ""
echo "=========================================="
echo "🎉 技术栈降级完成!"
echo "=========================================="
echo ""
echo "📋 后续操作:"
echo " 1. 运行 'npm run dev' 启动开发服务器验证"
echo " 2. 运行 'npm run test:unit' 执行单元测试"
echo " 3. 运行 'npm run test:e2e' 执行 E2E 测试"
echo " 4. 如果一切正常,提交代码到 Git"
echo ""
echo "📋 回滚方法(如果遇到问题):"
echo " cp $BACKUP_DIR/package.json ./package.json"
echo " # ... 恢复其他配置文件"
echo " rm -rf node_modules && npm install"
echo ""
echo "💡 备份位置: $BACKUP_DIR/"
echo ""