优化打包流程

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