修复打包

This commit is contained in:
aixianling
2023-02-16 17:05:35 +08:00
parent 2e5a162292
commit ddbf988698
2 changed files with 37 additions and 32 deletions

View File

@@ -47,23 +47,23 @@ const handleZip = (id, ws) => {
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([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)]) 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)])
.then(cmd => progress.set(30, cmd)) .then(cmd => progress.set(30, cmd))
.then(() => execute(`cd ${path}&&npm run apps&&node bin/pages.js ${id}&&npm run build`, 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(70, cmd))
.then(() => fse.emptyDir(dist)) .then(() => fse.emptyDir(dist))
.then(() => execute(`./shell/move.sh ${info.type} ${path} ${dist}`, signal)) .then(() => execute(`./shell/move.sh ${info.type} ${path} ${dist}`, signal))
.then(cmd => progress.set(90, cmd)) .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.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)
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 => progress.finish(row)) .then(row => progress.stop(row))
.catch(err => { .catch(() => 0)
console.log(err) })
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 => progress.stop(row))
.catch(() => 0)
})
} }
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)

View File

@@ -1,29 +1,34 @@
const {findFile} = require("../utils/fsUtils"); const {findFile} = require("../utils/fsUtils");
const chalk = require("chalk"); const chalk = require("chalk");
const dayjs = require("dayjs"); const dayjs = require("dayjs");
const {checkJson} = require("../tools");
const {log} = console const {log} = console
module.exports = { module.exports = {
init: ins => new Promise(resolve => ins.ws('/ws', ws => { init: ins => new Promise(resolve => {
log(`${chalk.bgBlue.black(" WEBSOCKET ")} 服务已启动!`)
ins.send('您已成功连接到node websocket')
let heartBeat = setInterval(() => wx.send(`heartBeat at ${dayjs().format("YYYY-MM-DD HH:mm:ss")}`), 5000)
ws.on('close', () => {
log(`${chalk.bgBlue.black(" WEBSOCKET ")} 连接已断开!`)
clearInterval(heartBeat)
})
let actions = {} let actions = {}
findFile('./src/websocket', file => { findFile('./src/websocket', file => {
if (!/index\.js/.test(file)) { if (!/index\.js/.test(file)) {
actions[ws.action] = ws.execute const item = require(file.replace(/src[\\\/]websocket/, '.'))
actions[item.action] = item.execute
} }
}).then(() => { }).then(() => {
ws.on('message', res => { ins.ws('/ws', ws => {
if (res?.data) { log(`${chalk.bgBlue.black(" WEBSOCKET ")} 服务已启动!`)
const data = JSON.parse(res.data) ws.send('您已成功连接到node websocket')
!!data?.action && actions[res.action]?.(ws, data) ws.onerror = () => ws.close()
} ws.on('close', () => {
log(`${chalk.bgRed.black(" WEBSOCKET ")} 连接已断开!`)
clearInterval(heartBeat)
})
ws.on('message', res => {
if (checkJson(res)) {
const data = JSON.parse(res)
!!data?.action && actions[data.action]?.(ws, data)
}
})
let heartBeat = setInterval(() => ws.send(`heartBeat at ${dayjs().format("YYYY-MM-DD HH:mm:ss")}`), 5000)
resolve()
}) })
resolve()
}) })
})) })
} }