优化打包流程

This commit is contained in:
aixianling
2022-05-24 09:29:38 +08:00
parent 585e6deb89
commit 9e9afb9c35

View File

@@ -6,24 +6,27 @@ module.exports = {
action: "/node/wxmp/getZip",
method: "post",
execute: (request, response) => {
let id = request.query?.appid, sql = `select * from node_dvcp_config where appid='${id}'`
let id = request.query?.appid, sql = `select * from node_dvcp_config where miniapp_appid='${id}'`
db.query(sql).then(res => {
let info = res?.[0]
let info = res?.[0], sql
if (info?.appid) {
db.query(`update node_wxmp_config set error=null where appid='${info.appid}'`).then(() => setTimeout(() => {
response.send({code: 0})
}, 2000))
execute(`cd /root/node-service/dvcp_v2_wechat&&node bin/pages.js ${id}&&npm run build`)
.then(() => fse.emptyDir(`../wxmpZips/${id}/`))
.then(() => fse.copy('../dvcp_v2_wechat/dist/build/mp-weixin/', `../wxmpZips/${id}/`))
.then(() => fse.emptyDir('../dvcp_v2_wechat/dist/build'))
.then(() => {
db.query(`update node_wxmp_config set error='打包时间:${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where appid='${info.appid}'`)
}).catch(err => {
console.log(err)
db.query(`update node_wxmp_config set error='${err}' where appid='${info.appid}'`)
})
} else response.send({code: 1, err: "无法找到小程序信息"})
sql = `update node_wxmp_config set error=null where appid='${info.appid}'`
} else if (info?.miniapp_appid) {
sql = `insert into node_wxmp_config ('appid') values('${info?.miniapp_appid}')`
} else return response.send({code: 1, err: "无法找到小程序信息"})
db.query(sql).then(() => setTimeout(() => {
response.send({code: 0})
}, 2000))
execute(`cd /root/node-service/dvcp_v2_wechat&&node bin/pages.js ${id}&&npm run build`)
.then(() => fse.emptyDir(`../wxmpZips/${id}/`))
.then(() => fse.copy('../dvcp_v2_wechat/dist/build/mp-weixin/', `../wxmpZips/${id}/`))
.then(() => fse.emptyDir('../dvcp_v2_wechat/dist/build'))
.then(() => {
db.query(`update node_wxmp_config set error='打包时间:${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where appid='${info.appid}'`)
}).catch(err => {
console.log(err)
db.query(`update node_wxmp_config set error='${err}' where appid='${info.appid}'`)
})
}).catch(err => {
console.log(err)
response.send({code: 1, err: err.sqlMessage})