前端项目打包,自动部署
·
前端项目自动打包,自动部署,nginx提前配置,目录对应好
//deploy.js 放置项目根目录
const { NodeSSH } = require('node-ssh');
const scpClient = require('scp2');
const path = require('path');
const ssh = new NodeSSH();
const config = {
host: 'xxxx',
port: 22,
pathUrl: '/home',
userName: 'root',
password: 'xxxx'
};
const connectServer = function () {
ssh.connect({
host: config.host,
username: config.userName,
port: config.port,
password: config.password,
}).then(() => {
console.log('SSH login success, 服务器连接成功!');
ssh.execCommand('sh upgrade.sh', { cwd: config.pathUrl }).then((result) => {
// console.log(`The update message is: ${result.stderr}`);
console.log('%j', result);
if (!result.stderr) {
console.log('sh upgrade.sh 脚本执行完成!');
syncUpload()
} else {
console.log('Something wrong:', result);
}
})
})
}
const syncUpload = function () {
console.log('进入了',);
scpClient.scp(
'./dist',
{
host: config.host,
port: config.port,
username: config.userName,
password: config.password,
path: config.pathUrl+'/dist'
},
function (err) {
if (err) {
console.log('发布失败');
// throw err;
} else {
console.log('Success! 成功发布到' + config.host + '服务器! ');
}
},
function (aaa) {
console.log('aaa', aaa);
}
);
}
process.on('unhandledRejection', (reason, p) => {
console.log('Promise: ', p, 'Reason: ', reason)
// do something
})
connectServer()
//upgrade.sh 放置代码部署的目录下
rm -rf dist
rm -rf dist.zip
mkdir dist
//项目打包命令修改
xxxxx bulid && node ./deploy
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)