feat: 重命名pm2.sh为deploy.sh并实现自动部署功能
- 重命名pm2.sh为deploy.sh - 实现自动从远程仓库拉取代码功能 - 添加自动构建功能 - 智能检测PM2进程状态,自动重载或创建进程 - 添加中文输出信息和错误处理 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -80,11 +80,28 @@ export function BatchOperations({ selectedCount, selectedAccounts, stats, onBatc
|
||||
};
|
||||
|
||||
const handleDownloadTxt = () => {
|
||||
const platforms = Array.from(new Set(selectedAccounts.map(account => account.platform)));
|
||||
const owners = Array.from(new Set(selectedAccounts.map(account => account.ownerId)));
|
||||
|
||||
// 构建文件名部分
|
||||
const platformPart = platforms.length === 1 ? platforms[0] : `${platforms.length}个平台`;
|
||||
const ownerPart = owners.length === 1 ? owners[0] : `${owners.length}个用户`;
|
||||
const countPart = `${exportData.count}个账户`;
|
||||
const datePart = new Date().toLocaleString('zh-CN', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit'
|
||||
}).replace(/[\/\s:]/g, '-');
|
||||
|
||||
const blob = new Blob([exportData.text], { type: 'text/plain;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = `accounts_export_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.txt`;
|
||||
link.download = `${platformPart}_${ownerPart}_${countPart}_${datePart}.txt`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
66
deploy.sh
Normal file
66
deploy.sh
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 部署脚本 - 自动拉取、构建、PM2重载/启动
|
||||
APP_NAME="accounts-manager-web"
|
||||
|
||||
echo "=========================================="
|
||||
echo " 开始部署 $APP_NAME"
|
||||
echo "=========================================="
|
||||
|
||||
# 1. 从远程仓库拉取最新代码
|
||||
echo "📦 正在从远程仓库拉取最新代码..."
|
||||
git pull origin master
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "❌ 拉取代码失败,请检查网络连接或仓库状态"
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ 代码拉取成功"
|
||||
|
||||
# 2. 安装依赖并构建项目
|
||||
echo "🔨 正在安装依赖并构建项目..."
|
||||
npm install
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "❌ 安装依赖失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
npm run build
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "❌ 项目构建失败"
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ 项目构建成功"
|
||||
|
||||
# 3. 检查PM2进程是否存在
|
||||
echo "🔍 正在检查PM2进程状态..."
|
||||
PM2_STATUS=$(pm2 list | grep -c "$APP_NAME")
|
||||
|
||||
if [ $PM2_STATUS -gt 0 ]; then
|
||||
# PM2进程存在,执行重载
|
||||
echo "🔄 PM2进程已存在,正在重载应用..."
|
||||
pm2 reload $APP_NAME
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✅ PM2应用重载成功"
|
||||
else
|
||||
echo "❌ PM2应用重载失败"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# PM2进程不存在,创建新进程
|
||||
echo "🚀 PM2进程不存在,正在启动新应用..."
|
||||
pm2 start npm --name $APP_NAME -- run start:prod
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✅ PM2应用启动成功"
|
||||
else
|
||||
echo "❌ PM2应用启动失败"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 4. 显示PM2状态
|
||||
echo "📊 当前PM2状态:"
|
||||
pm2 list
|
||||
|
||||
echo "=========================================="
|
||||
echo " 🎉 部署完成!"
|
||||
echo "=========================================="
|
||||
Reference in New Issue
Block a user