72 lines
1.9 KiB
JavaScript
72 lines
1.9 KiB
JavaScript
import { Client } from 'ssh2';
|
|
import fs from 'fs';
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
console.log('=== 重新部署前端 ===\n');
|
|
|
|
conn.exec('rm -rf /www/huishou/dist/build/h5/assets/*', (err, stream) => {
|
|
if (err) {
|
|
console.log('清理失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream.on('close', () => {
|
|
console.log('已清理旧文件');
|
|
|
|
conn.exec('cd /www/huishou && npm run build:h5 2>&1', (err, stream2) => {
|
|
if (err) {
|
|
console.log('构建失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
let buildOutput = '';
|
|
stream2.on('data', (data) => {
|
|
buildOutput += data.toString();
|
|
});
|
|
|
|
stream2.on('close', () => {
|
|
console.log('构建输出:', buildOutput.substring(0, 500));
|
|
|
|
conn.exec('ls -la /www/huishou/dist/build/h5/', (err, stream3) => {
|
|
if (err) {
|
|
console.log('检查构建结果失败:', err.message);
|
|
} else {
|
|
stream3.on('data', (data3) => {
|
|
console.log('\n构建结果:', data3.toString());
|
|
});
|
|
}
|
|
|
|
stream3.on('close', () => {
|
|
conn.exec('/www/server/nginx/sbin/nginx -s reload', (err, stream4) => {
|
|
if (err) {
|
|
console.log('重启失败:', err.message);
|
|
} else {
|
|
console.log('Nginx已重启');
|
|
}
|
|
|
|
stream4.on('close', () => {
|
|
conn.end();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
console.log('连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect({
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
}); |