新版小程序打包
This commit is contained in:
@@ -3,26 +3,14 @@ module.exports = {
|
||||
action: "/node/wxmp/addOrUpdate",
|
||||
method: "post",
|
||||
execute: (request, response) => {
|
||||
let {appid, privateKey, projectPath, version, miniapp_appid, id: pid, npmScript} = request.body,
|
||||
form = {appid, privateKey, projectPath, version, pid, npmScript}, sql
|
||||
if (form.appid) {//编辑
|
||||
let arr = Object.keys(form).filter(e => form[e] != undefined).map(e => `${e}='${form[e]}'`)
|
||||
sql = `update node_wxmp_config set ${arr.join(",")} where appid='${form.appid}' and pid='${pid}'`
|
||||
} else {//新增
|
||||
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})
|
||||
let {appid, privateKey, projectPath, version, versionName, id, npmScript} = request.body,
|
||||
form = {appid, privateKey, projectPath, version, versionName, id, npmScript}
|
||||
dbUtils.addOrUpdate({
|
||||
table: 'node_wxmp_deploy', form
|
||||
}).then(data => {
|
||||
response.send({code: 0, data})
|
||||
}).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",
|
||||
method: "post",
|
||||
execute: (request, response) => {
|
||||
let {pid, appid: aid} = request.query, appid = [aid, pid].join("_")
|
||||
if (appid) {
|
||||
let path = `/home/deploy/wxmpZips/${appid}/`, zipPath = `/home/deploy/wxmpZips/${appid}.zip`
|
||||
let {id} = request.query
|
||||
if (id) {
|
||||
let path = `/home/deploy/node_deploy/zips/${id}/`, zipPath = `/home/deploy/node_deploy/zips/${id}.zip`
|
||||
fse.removeSync(zipPath)
|
||||
fse.pathExists(path, (err, exists) => {
|
||||
console.log(`${path}=========>${exists}`)
|
||||
if (exists) {
|
||||
execute(`cd ${path}&&zip -r ${appid}.zip .`)
|
||||
.then(() => execute(`cd ${path}&&mv ${appid}.zip /home/deploy/wxmpZips`))
|
||||
execute(`cd ${path}&&zip -r ${id}.zip .`)
|
||||
.then(() => execute(`cd ${path}&&mv ${id}.zip /home/deploy/node_deploy/zips`))
|
||||
.then(() => {
|
||||
console.log('压缩完成!')
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -7,19 +7,17 @@ module.exports = {
|
||||
action: "/node/wxmp/getZip",
|
||||
method: "post",
|
||||
execute: (request, response) => {
|
||||
let {appid, id} = request.query, uniCon = `appid='${appid}' and pid='${id}'`, uid = [appid, id].join("_")
|
||||
db.query(`select * from node_dvcp_config where id='${id}'`).then(res => {
|
||||
const {id, appid} = request.query
|
||||
db.query(`select * from node_wxmp_deploy where id='${id}'`).then(res => {
|
||||
let info = res?.[0], sql
|
||||
if (info?.appid && info?.pid) {
|
||||
sql = `update node_wxmp_config set error=null where appid='${info.appid}' and pid='${info.pid}'`
|
||||
} else if (info?.miniapp_appid) {
|
||||
sql = `insert into node_wxmp_config ('appid','pid') values('${info?.miniapp_appid}','${info.id}')`
|
||||
if (info?.id) {
|
||||
sql = `update node_wxmp_deploy set error=null where id='${id}'`
|
||||
} else return response.send({code: 1, err: "无法找到小程序信息"})
|
||||
db.query(sql).then(() => setTimeout(() => {
|
||||
response.send({code: 0})
|
||||
}, 2000))
|
||||
const path = info.projectPath || (isDev ? 'E:\\code\\cunwei\\dvcp_v2_wechat' : '/home/deploy/node-service/dvcp_v2_wxmp'),
|
||||
dest = (isDev ? `E:\\wxmpZips\\${uid}` : `/home/deploy/wxmpZips/${uid}/`),
|
||||
const path = info.projectPath || (isDev ? 'E:\\code\\cunwei\\dvcp_v2_wechat' : '/home/deploy/node_deploy/dvcp_v2_wechat'),
|
||||
dest = (isDev ? `E:\\wxmpZips\\${id}` : `/home/deploy/node_deploy/zips/${id}/`),
|
||||
processEnv = info.npmScript || 'build',
|
||||
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}`)
|
||||
@@ -28,10 +26,10 @@ module.exports = {
|
||||
.then(() => fse.copy(dist, dest))
|
||||
.then(() => fse.emptyDir(dist))
|
||||
.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 => {
|
||||
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 => {
|
||||
console.log(err)
|
||||
|
||||
@@ -3,26 +3,14 @@ module.exports = {
|
||||
action: "/node/wxmp/list",
|
||||
method: "post",
|
||||
execute: (request, response) => {
|
||||
let total = 0, records = [], {size, current, name} = request.query
|
||||
Promise.all([
|
||||
dbUtils.query(`select 1 from node_dvcp_config`).then(res => {
|
||||
return total = res.length
|
||||
}),
|
||||
new Promise(resolve => {
|
||||
let sql = `select * from node_dvcp_config where name like '%${name}%' or version like '%${name}%' or appid like '%${name}%' limit ${(current-1)*size},${size}`
|
||||
dbUtils.query(sql).then(res => {
|
||||
records = res
|
||||
resolve()
|
||||
}).catch(err => {
|
||||
response.send({code: 1, err: err.sqlMessage})
|
||||
})
|
||||
})
|
||||
|
||||
]).then(() => {
|
||||
response.send({
|
||||
code: 0,
|
||||
data: {records, total}
|
||||
})
|
||||
const {size, current, name, type} = request.query
|
||||
dbUtils.list({
|
||||
table: 'node_wxmp_deploy', con: name,
|
||||
search: {size, current, type}
|
||||
}).then(data => {
|
||||
response.send({code: 0, data})
|
||||
}).catch(err => {
|
||||
response.send({code: 1, err: err?.sqlMessage || err || ""})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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