43 lines
1.7 KiB
JavaScript
43 lines
1.7 KiB
JavaScript
const db = require("../../utils/dbUitls");
|
|
const execute = require("../../tools/exec")
|
|
const dayjs = require("dayjs")
|
|
const fse = require("fs-extra");
|
|
module.exports = {
|
|
action: "/node/custom/getZip",
|
|
method: "post",
|
|
execute: (request, response) => {
|
|
let {id} = request.query, uniCon = `id='${id}'`
|
|
db.query(`select * from node_custom_config where id='${id}'`).then(res => {
|
|
let info = res?.[0], sql
|
|
if (info?.id) {
|
|
sql = `update node_custom_config set download=null,error=null,zipTime='${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where ${uniCon}`
|
|
const buildPath = {
|
|
web: 'base-web',
|
|
wxwork: 'base-wxcp',
|
|
mp: 'dvcp_v2_wxmp'
|
|
}[info.type] || {}
|
|
const path = `../${buildPath}`,
|
|
{dist = `../zips/${info.name}v${info.version}`} = info
|
|
Promise.all([
|
|
execute(`./shell/update.sh ${info.name} ${path}`),
|
|
db.query(sql)
|
|
]).then(() => setTimeout(() => {
|
|
response.send({code: 0})
|
|
}, 1000))
|
|
execute(`cd ${path}&&npm run apps&&node bin/pages.js ${id}&&npm run build`)
|
|
.then(() => fse.emptyDir(dist))
|
|
.then(() => execute(`./shell/move.sh ${info.type} ${path} ${dist}`))
|
|
.then(() => {
|
|
return db.query(`update node_custom_config set download='${dayjs().format("YYYY-MM-DD HH:mm:ss")}',error='' where ${uniCon}`)
|
|
}).catch(err => {
|
|
console.log(err)
|
|
return db.query(`update node_custom_config set error='${err}',zipTime=null where ${uniCon}`)
|
|
})
|
|
} else return response.send({code: 1, err: "无法找到定制项目信息"})
|
|
}).catch(err => {
|
|
console.log(err)
|
|
response.send({code: 1, err: err.sqlMessage})
|
|
})
|
|
}
|
|
}
|