打包业务

This commit is contained in:
aixianling
2022-03-31 18:25:48 +08:00
parent 82f09d89c8
commit 94ce411071
5 changed files with 89 additions and 0 deletions

39
rest/autodeploy/getZip.js Normal file
View File

@@ -0,0 +1,39 @@
const dbUtils = require("../../utils/dbUitls");
const {exec} = require("child_process");
const fse = require('fs-extra')
const execute = cmd => new Promise((resolve, reject) => {
exec(cmd, (err, stdout) => {
if (!err) {
console.log(stdout)
resolve()
} else reject(err)
})
})
module.exports = {
action: "/node/autodeploy/getZip",
method: "post",
execute: (request, response) => {
let id = request.query?.id, sql = `select * from node_autodeploy where id='${id}'`
dbUtils.query(sql).then(res => {
let info = res?.[0]
if (info?.id) {
response.send({code: 0})
fse.emptyDir('../zips/' + info.id, err => {
if (!err) {
execute(`cd ../zips&&git clone ${info.git} ./${info.id}`)
.then(() => execute(`cd ../zips/${info.id}&&git checkout ${info.branch}`))
.then(() => execute(`cd ../zips/${info.id}&&npm i&&npm run build`))
.catch(err => {
console.log(err)
})
} else {
console.log(err)
}
})
} else response.send({code: 1, err: "无法找到git信息"})
}).catch(err => {
console.log(err)
response.send({code: 1, err: err.sqlMessage})
})
}
}