新版小程序打包
This commit is contained in:
@@ -3,26 +3,14 @@ module.exports = {
|
|||||||
action: "/node/wxmp/addOrUpdate",
|
action: "/node/wxmp/addOrUpdate",
|
||||||
method: "post",
|
method: "post",
|
||||||
execute: (request, response) => {
|
execute: (request, response) => {
|
||||||
let {appid, privateKey, projectPath, version, miniapp_appid, id: pid, npmScript} = request.body,
|
let {appid, privateKey, projectPath, version, versionName, id, npmScript} = request.body,
|
||||||
form = {appid, privateKey, projectPath, version, pid, npmScript}, sql
|
form = {appid, privateKey, projectPath, version, versionName, id, npmScript}
|
||||||
if (form.appid) {//编辑
|
dbUtils.addOrUpdate({
|
||||||
let arr = Object.keys(form).filter(e => form[e] != undefined).map(e => `${e}='${form[e]}'`)
|
table: 'node_wxmp_deploy', form
|
||||||
sql = `update node_wxmp_config set ${arr.join(",")} where appid='${form.appid}' and pid='${pid}'`
|
}).then(data => {
|
||||||
} else {//新增
|
response.send({code: 0, data})
|
||||||
let cols = [], arr = []
|
|
||||||
form.appid = miniapp_appid
|
|
||||||
Object.keys(form).map(e => {
|
|
||||||
if (form[e]) {
|
|
||||||
cols.push(e)
|
|
||||||
arr.push(`'${form[e]}'`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
sql = `insert into node_wxmp_config (${cols.join(",")}) values(${arr.join(",")})`
|
|
||||||
}
|
|
||||||
dbUtils.query(sql).then(() => {
|
|
||||||
response.send({code: 0})
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
response.send({code: 1, err: err.sqlMessage})
|
response.send({code: 1, err: err?.sqlMessage || err || ""})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ module.exports = {
|
|||||||
action: "/node/wxmp/download",
|
action: "/node/wxmp/download",
|
||||||
method: "post",
|
method: "post",
|
||||||
execute: (request, response) => {
|
execute: (request, response) => {
|
||||||
let {pid, appid: aid} = request.query, appid = [aid, pid].join("_")
|
let {id} = request.query
|
||||||
if (appid) {
|
if (id) {
|
||||||
let path = `/home/deploy/wxmpZips/${appid}/`, zipPath = `/home/deploy/wxmpZips/${appid}.zip`
|
let path = `/home/deploy/node_deploy/zips/${id}/`, zipPath = `/home/deploy/node_deploy/zips/${id}.zip`
|
||||||
fse.removeSync(zipPath)
|
fse.removeSync(zipPath)
|
||||||
fse.pathExists(path, (err, exists) => {
|
fse.pathExists(path, (err, exists) => {
|
||||||
console.log(`${path}=========>${exists}`)
|
console.log(`${path}=========>${exists}`)
|
||||||
if (exists) {
|
if (exists) {
|
||||||
execute(`cd ${path}&&zip -r ${appid}.zip .`)
|
execute(`cd ${path}&&zip -r ${id}.zip .`)
|
||||||
.then(() => execute(`cd ${path}&&mv ${appid}.zip /home/deploy/wxmpZips`))
|
.then(() => execute(`cd ${path}&&mv ${id}.zip /home/deploy/node_deploy/zips`))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('压缩完成!')
|
console.log('压缩完成!')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@@ -7,19 +7,17 @@ module.exports = {
|
|||||||
action: "/node/wxmp/getZip",
|
action: "/node/wxmp/getZip",
|
||||||
method: "post",
|
method: "post",
|
||||||
execute: (request, response) => {
|
execute: (request, response) => {
|
||||||
let {appid, id} = request.query, uniCon = `appid='${appid}' and pid='${id}'`, uid = [appid, id].join("_")
|
const {id, appid} = request.query
|
||||||
db.query(`select * from node_dvcp_config where id='${id}'`).then(res => {
|
db.query(`select * from node_wxmp_deploy where id='${id}'`).then(res => {
|
||||||
let info = res?.[0], sql
|
let info = res?.[0], sql
|
||||||
if (info?.appid && info?.pid) {
|
if (info?.id) {
|
||||||
sql = `update node_wxmp_config set error=null where appid='${info.appid}' and pid='${info.pid}'`
|
sql = `update node_wxmp_deploy set error=null where id='${id}'`
|
||||||
} else if (info?.miniapp_appid) {
|
|
||||||
sql = `insert into node_wxmp_config ('appid','pid') values('${info?.miniapp_appid}','${info.id}')`
|
|
||||||
} else return response.send({code: 1, err: "无法找到小程序信息"})
|
} else return response.send({code: 1, err: "无法找到小程序信息"})
|
||||||
db.query(sql).then(() => setTimeout(() => {
|
db.query(sql).then(() => setTimeout(() => {
|
||||||
response.send({code: 0})
|
response.send({code: 0})
|
||||||
}, 2000))
|
}, 2000))
|
||||||
const path = info.projectPath || (isDev ? 'E:\\code\\cunwei\\dvcp_v2_wechat' : '/home/deploy/node-service/dvcp_v2_wxmp'),
|
const path = info.projectPath || (isDev ? 'E:\\code\\cunwei\\dvcp_v2_wechat' : '/home/deploy/node_deploy/dvcp_v2_wechat'),
|
||||||
dest = (isDev ? `E:\\wxmpZips\\${uid}` : `/home/deploy/wxmpZips/${uid}/`),
|
dest = (isDev ? `E:\\wxmpZips\\${id}` : `/home/deploy/node_deploy/zips/${id}/`),
|
||||||
processEnv = info.npmScript || 'build',
|
processEnv = info.npmScript || 'build',
|
||||||
dist = info.npmScript ? `${path}/dist/${info.npmScript}/` : `${path}/dist/build/mp-weixin/`
|
dist = info.npmScript ? `${path}/dist/${info.npmScript}/` : `${path}/dist/build/mp-weixin/`
|
||||||
execute(`cd ${path}&&npm run apps&&node bin/pages.js ${appid} ${id}&&npm run ${processEnv}`)
|
execute(`cd ${path}&&npm run apps&&node bin/pages.js ${appid} ${id}&&npm run ${processEnv}`)
|
||||||
@@ -28,10 +26,10 @@ module.exports = {
|
|||||||
.then(() => fse.copy(dist, dest))
|
.then(() => fse.copy(dist, dest))
|
||||||
.then(() => fse.emptyDir(dist))
|
.then(() => fse.emptyDir(dist))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
db.query(`update node_wxmp_config set error='打包时间:${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where ${uniCon}`)
|
db.query(`update node_wxmp_deploy set error='打包时间:${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where id='${id}'`)
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
db.query(`update node_wxmp_config set error='${err}' where ${uniCon}`)
|
db.query(`update node_wxmp_deploy set error='${err}' where id='${id}'`)
|
||||||
})
|
})
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
|
|||||||
@@ -3,26 +3,14 @@ module.exports = {
|
|||||||
action: "/node/wxmp/list",
|
action: "/node/wxmp/list",
|
||||||
method: "post",
|
method: "post",
|
||||||
execute: (request, response) => {
|
execute: (request, response) => {
|
||||||
let total = 0, records = [], {size, current, name} = request.query
|
const {size, current, name, type} = request.query
|
||||||
Promise.all([
|
dbUtils.list({
|
||||||
dbUtils.query(`select 1 from node_dvcp_config`).then(res => {
|
table: 'node_wxmp_deploy', con: name,
|
||||||
return total = res.length
|
search: {size, current, type}
|
||||||
}),
|
}).then(data => {
|
||||||
new Promise(resolve => {
|
response.send({code: 0, data})
|
||||||
let sql = `select * from node_dvcp_config where name like '%${name}%' or version like '%${name}%' or appid like '%${name}%' limit ${(current-1)*size},${size}`
|
}).catch(err => {
|
||||||
dbUtils.query(sql).then(res => {
|
response.send({code: 1, err: err?.sqlMessage || err || ""})
|
||||||
records = res
|
|
||||||
resolve()
|
|
||||||
}).catch(err => {
|
|
||||||
response.send({code: 1, err: err.sqlMessage})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
]).then(() => {
|
|
||||||
response.send({
|
|
||||||
code: 0,
|
|
||||||
data: {records, total}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/rest/wechat/sync.js
Normal file
21
src/rest/wechat/sync.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
const dbUtils = require("../../utils/dbUitls");
|
||||||
|
uid = e => [e.appid, e.corpId].join("_")
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/wxmp/sync",
|
||||||
|
method: "post",
|
||||||
|
execute: (request, response) => {
|
||||||
|
let records = {}, meta = []
|
||||||
|
Promise.all([
|
||||||
|
dbUtils.query("select * from app_dvcp_config").then(res => meta = res),
|
||||||
|
dbUtils.query("select * from node_wxmp_deploy").then(res => res?.map(e => records[uid(e)] = e))
|
||||||
|
]).then(() => Promise.all(meta.map(e => {
|
||||||
|
const {name, miniapp_appid: appid, corp_id: corpId, web_url: webUrl} = e
|
||||||
|
const id = records[uid({appid, corpId})]?.id
|
||||||
|
delete e.system_info
|
||||||
|
return dbUtils.addOrUpdate({
|
||||||
|
table: 'node_wxmp_deploy',
|
||||||
|
form: {id, name, appid, corpId, webUrl, dvcpConfig: e}
|
||||||
|
})
|
||||||
|
}))).finally(() => response.send({code: 0, data: ""}))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user