重新调整websocket的配置
This commit is contained in:
@@ -41,34 +41,29 @@ const handleZip = (id, ws) => {
|
|||||||
const {signal} = controller;
|
const {signal} = controller;
|
||||||
const progress = new counter(`正在处理 ${info.name} 的打包工作...`)
|
const progress = new counter(`正在处理 ${info.name} 的打包工作...`)
|
||||||
const buildPath = {
|
const buildPath = {
|
||||||
web: 'base-web',
|
web: 'base-web', wxwork: 'base-wxcp', mp: 'dvcp_v2_wxmp'
|
||||||
wxwork: 'base-wxcp',
|
|
||||||
mp: 'dvcp_v2_wxmp'
|
|
||||||
}[info.type] || {}
|
}[info.type] || {}
|
||||||
let path = `../${buildPath}`, {dist} = info
|
let path = `../${buildPath}`, {dist} = info
|
||||||
dist = dist || `../zips/${info.name}v${info.version || "1.0.0"}`
|
dist = dist || `../zips/${info.name}v${info.version || "1.0.0"}`
|
||||||
Promise.all([
|
Promise.all([db.query(`update node_custom_config set download=null,error=null,zipTime='${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where ${uniCon}`), execute(`./shell/update.sh ${info.name} ${path}`, signal)])
|
||||||
db.query(`update node_custom_config set download=null,error=null,zipTime='${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where ${uniCon}`),
|
.then(cmd => progress.set(30, cmd))
|
||||||
execute(`./shell/update.sh ${info.name} ${path}`, signal)
|
.then(() => execute(`cd ${path}&&npm run apps&&node bin/pages.js ${id}&&npm run build`, signal))
|
||||||
])
|
.then(cmd => progress.set(70, cmd))
|
||||||
.then(cmd => progress.set(30, cmd))
|
.then(() => fse.emptyDir(dist))
|
||||||
.then(() => execute(`cd ${path}&&npm run apps&&node bin/pages.js ${id}&&npm run build`, signal))
|
.then(() => execute(`./shell/move.sh ${info.type} ${path} ${dist}`, signal))
|
||||||
.then(cmd => progress.set(70, cmd))
|
.then(cmd => progress.set(90, cmd))
|
||||||
.then(() => fse.emptyDir(dist))
|
.then(() => db.query(`update node_custom_config set download='${dayjs().format("YYYY-MM-DD HH:mm:ss")}',error='' where ${uniCon}`))
|
||||||
.then(() => execute(`./shell/move.sh ${info.type} ${path} ${dist}`, signal))
|
|
||||||
.then(cmd => progress.set(90, cmd))
|
|
||||||
.then(() => db.query(`update node_custom_config set download='${dayjs().format("YYYY-MM-DD HH:mm:ss")}',error='' where ${uniCon}`))
|
|
||||||
.then(() => db.detail({table: "node_custom_config", id}))
|
|
||||||
.then(row => progress.finish(row))
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err)
|
|
||||||
progress.stop()
|
|
||||||
const msg = `执行失败:${err.cmd}`
|
|
||||||
return db.query(`update node_custom_config set error='${msg}',zipTime=null where ${uniCon}`)
|
|
||||||
.then(() => db.detail({table: "node_custom_config", id}))
|
.then(() => db.detail({table: "node_custom_config", id}))
|
||||||
.then(row => sendMessage({code: 1, row}))
|
.then(row => progress.finish(row))
|
||||||
.catch(() => 0)
|
.catch(err => {
|
||||||
})
|
console.log(err)
|
||||||
|
progress.stop()
|
||||||
|
const msg = `执行失败:${err.cmd}`
|
||||||
|
return db.query(`update node_custom_config set error='${msg}',zipTime=null where ${uniCon}`)
|
||||||
|
.then(() => db.detail({table: "node_custom_config", id}))
|
||||||
|
.then(row => sendMessage({code: 1, row}))
|
||||||
|
.catch(() => 0)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
@@ -76,20 +71,13 @@ const handleZip = (id, ws) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
action: "/custom/getZip",
|
action: "/custom/getZip", execute: (ws, request) => {
|
||||||
execute: (ws, request) => {
|
const {id, cid} = request.params
|
||||||
const {id} = request.query
|
if (cid) {
|
||||||
handleZip(id, ws)
|
controller.abort()
|
||||||
ws.onmessage = res => {
|
controller = new AbortController()
|
||||||
if (res?.data) {
|
} else if (id) {
|
||||||
const data = JSON.parse(res.data)
|
handleZip(id, ws)
|
||||||
if (data.cid == id) {
|
|
||||||
controller.abort()
|
|
||||||
controller = new AbortController()
|
|
||||||
} else if (id == data.id) {
|
|
||||||
handleZip(id, ws)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,27 @@
|
|||||||
const {findFile} = require("../utils/fsUtils");
|
const {findFile} = require("../utils/fsUtils");
|
||||||
const chalk = require("chalk");
|
const chalk = require("chalk");
|
||||||
|
const dayjs = require("dayjs");
|
||||||
const {log} = console
|
const {log} = console
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: ins => {
|
init: ins => {
|
||||||
return findFile('./src/websocket', file => {
|
ins.ws('/ws', ws => {
|
||||||
if (!/index\.js/.test(file)) {
|
log(`${chalk.bgBlue.black(" WEBSOCKET ")} 服务已启动!`)
|
||||||
const ws = require(file.replace(/src[\\\/]websocket/, '.'))
|
ins.send('您已成功连接到node websocket')
|
||||||
log(`${chalk.bgBlue.black(" WEBSOCKET ")} ${ws.action}`)
|
let heartBeat = setInterval(() => wx.send(`heartBeat at ${dayjs().format("YYYY-MM-DD HH:mm:ss")}`), 5000)
|
||||||
ins.ws(ws.action, ws.execute)
|
ws.on('close', () => {
|
||||||
}
|
log(`${chalk.bgBlue.black(" WEBSOCKET ")} 连接已断开!`)
|
||||||
|
clearInterval(heartBeat)
|
||||||
|
})
|
||||||
|
let actions = {}
|
||||||
|
return findFile('./src/websocket', file => {
|
||||||
|
if (!/index\.js/.test(file)) {
|
||||||
|
actions[ws.action] = ws.execute
|
||||||
|
}
|
||||||
|
}).then(() => ws.on('message', res => {
|
||||||
|
if (res?.action) {
|
||||||
|
actions[res.action]?.(ws, JSON.parse(res))
|
||||||
|
}
|
||||||
|
}))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user