const { execSync } = require('child_process'); const USER = 'root'; const HOST = '47.111.130.18'; const PORT = '58222'; const TARGET_DIR = '/home/gpustack-ui/dist'; const LOCAL_DIR = 'dist'; function run(cmd) { console.log(`👉 ${cmd}`); execSync(cmd, { stdio: 'inherit' }); } try { console.log('🚀 开始构建 React 项目...'); run('npm run build'); console.log('🧹 清理服务器旧 dist...'); run(`ssh -p ${PORT} ${USER}@${HOST} "rm -rf ${TARGET_DIR}"`); console.log('📂 上传 dist 到服务器...'); run(`scp -P ${PORT} -r ${LOCAL_DIR} ${USER}@${HOST}:${TARGET_DIR}`); console.log('🔧 执行服务器构建和服务重启...'); run( `ssh -p ${PORT} ${USER}@${HOST} "cd /home/gpustack && make build && bash /home/gpustack-service/gpustack-reinstall.sh && bash /home/gpustack-service/gpustack-start.sh"` ); console.log('✅ 部署完成!服务已重启。'); } catch (err) { console.error('❌ 部署失败:', err.message); process.exit(1); }