追加跟踪细粒度
This commit is contained in:
@@ -1,38 +0,0 @@
|
|||||||
const {exec} = require("child_process");
|
|
||||||
|
|
||||||
class Process {
|
|
||||||
constructor(cmd, cb) {
|
|
||||||
this.cmd = cmd
|
|
||||||
this.pid = exec(cmd, {windowsHide: true, encoding: "utf8"});
|
|
||||||
this.callback = cb
|
|
||||||
}
|
|
||||||
|
|
||||||
static new(cmd) {
|
|
||||||
return new Promise((resolve, reject) => exec(cmd, {windowsHide: true}, (err) => {
|
|
||||||
if (!err) {
|
|
||||||
resolve()
|
|
||||||
} else reject(err)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
ins() {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.pid.on('close', (code, err) => {
|
|
||||||
if (code == 0 && !err) {
|
|
||||||
resolve()
|
|
||||||
} else reject(err)
|
|
||||||
})
|
|
||||||
this.pid.on('exit', (code, err) => {
|
|
||||||
if (code == 0 && !err) {
|
|
||||||
resolve()
|
|
||||||
} else reject(err)
|
|
||||||
})
|
|
||||||
this.pid.stdout.on('data', data => {
|
|
||||||
console.log(data)
|
|
||||||
this.callback?.()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Process
|
|
||||||
@@ -1,20 +1,12 @@
|
|||||||
const {exec} = require("child_process");
|
const cp = require("child_process");
|
||||||
const execute = cmd => new Promise((resolve, reject) => {
|
const execute = (cmd, signal) => new Promise((resolve, reject) => {
|
||||||
let pid = exec(cmd, {windowsHide: true}, (err) => {
|
const pid = cp.exec(cmd, {windowsHide: true, signal}, (err) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
resolve()
|
resolve(cmd)
|
||||||
} else reject(err)
|
} else reject(err)
|
||||||
})
|
})
|
||||||
pid.on('close', (code, err) => {
|
|
||||||
if (code == 0 && !err) {
|
|
||||||
resolve()
|
|
||||||
} else reject()
|
|
||||||
})
|
|
||||||
pid.stdout.on('data', data => {
|
pid.stdout.on('data', data => {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
})
|
})
|
||||||
pid.stderr.on('data', data => {
|
|
||||||
console.log(data)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
module.exports = execute
|
module.exports = execute
|
||||||
|
|||||||
@@ -1,37 +1,66 @@
|
|||||||
const db = require("../../utils/dbUitls");
|
const db = require("../../utils/dbUitls");
|
||||||
const execute = require("../../tools/exec")
|
const execute = require("../../tools/exec")
|
||||||
const process = require("../../tools/childProcess")
|
|
||||||
const dayjs = require("dayjs")
|
const dayjs = require("dayjs")
|
||||||
const fse = require("fs-extra");
|
const fse = require("fs-extra");
|
||||||
let pid
|
|
||||||
|
const controller = new AbortController()
|
||||||
const handleZip = (id, ws) => {
|
const handleZip = (id, ws) => {
|
||||||
const uniCon = `id='${id}'`
|
const uniCon = `id='${id}'`
|
||||||
const sendMessage = data => ws.send(JSON.stringify(data))
|
const sendMessage = data => ws.send(JSON.stringify(data))
|
||||||
|
|
||||||
|
class counter {
|
||||||
|
constructor(remark) {
|
||||||
|
this.count = 0
|
||||||
|
this.timer = setInterval(() => {
|
||||||
|
sendMessage({code: 0, progress: ++this.count, remark})
|
||||||
|
}, 6000)
|
||||||
|
}
|
||||||
|
|
||||||
|
set(progress, remark) {
|
||||||
|
if (this.timer) clearInterval(this.timer)
|
||||||
|
this.count = progress
|
||||||
|
this.timer = setInterval(() => {
|
||||||
|
sendMessage({code: 0, progress: ++this.count, remark})
|
||||||
|
}, 4000)
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
if (this.timer) clearInterval(this.timer)
|
||||||
|
}
|
||||||
|
|
||||||
|
finish(remark) {
|
||||||
|
if (this.timer) clearInterval(this.timer)
|
||||||
|
sendMessage({code: 0, progress: 100, remark})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
db.detail({table: "node_custom_config", id}).then(info => {
|
db.detail({table: "node_custom_config", id}).then(info => {
|
||||||
if (info?.id) {
|
if (info?.id) {
|
||||||
sendMessage({code: 0, progress: 1, data: `正在处理 ${info.name} 的打包工作...`})
|
const {signal} = controller;
|
||||||
|
const progress = new counter(`正在处理 ${info.name} 的打包工作...`)
|
||||||
const buildPath = {
|
const buildPath = {
|
||||||
web: 'base-web',
|
web: 'base-web',
|
||||||
wxwork: 'base-wxcp',
|
wxwork: 'base-wxcp',
|
||||||
mp: 'dvcp_v2_wxmp'
|
mp: 'dvcp_v2_wxmp'
|
||||||
}[info.type] || {}
|
}[info.type] || {}
|
||||||
let path = `../${buildPath}`, {dist} = info, progress = 30
|
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}`),
|
db.query(`update node_custom_config set download=null,error=null,zipTime='${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where ${uniCon}`),
|
||||||
process.new(`./shell/update.sh ${info.name} ${path}`)])
|
execute(`./shell/update.sh ${info.name} ${path}`, signal)
|
||||||
.then(() => sendMessage({code: 0, progress}))
|
])
|
||||||
.then(() => pid = new process(`cd ${path}&&npm run apps&&node bin/pages.js ${id}&&npm run build`), () => sendMessage({code: 0, progress: ++progress}))
|
.then(cmd => progress.set(30, cmd))
|
||||||
.then(() => pid.ins())
|
.then(() => execute(`cd ${path}&&npm run apps&&node bin/pages.js ${id}&&npm run build`, signal))
|
||||||
|
.then(cmd => progress.set(70, cmd))
|
||||||
.then(() => fse.emptyDir(dist))
|
.then(() => fse.emptyDir(dist))
|
||||||
.then(() => progress = 70, sendMessage({code: 0, progress}))
|
.then(() => execute(`./shell/move.sh ${info.type} ${path} ${dist}`, signal))
|
||||||
.then(() => pid = new process(`./shell/move.sh ${info.type} ${path} ${dist}`), () => sendMessage({code: 0, progress: ++progress})).then(() => pid.ins())
|
.then(cmd => progress.set(90, cmd))
|
||||||
.then(() => progress = 90, sendMessage({code: 0, progress}))
|
|
||||||
.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(() => db.detail({table: "node_custom_config", id}))
|
||||||
.then(row => sendMessage({code: 0, progress: 100, row}))
|
.then(row => progress.finish(row))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
|
progress.stop()
|
||||||
const msg = `执行失败:${err.cmd}`
|
const msg = `执行失败:${err.cmd}`
|
||||||
return db.query(`update node_custom_config set error='${msg}',zipTime=null where ${uniCon}`)
|
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}))
|
||||||
@@ -53,12 +82,11 @@ module.exports = {
|
|||||||
if (res?.data) {
|
if (res?.data) {
|
||||||
const data = JSON.parse(res.data)
|
const data = JSON.parse(res.data)
|
||||||
if (data.cid == id) {
|
if (data.cid == id) {
|
||||||
pid.unref()
|
controller.abort()
|
||||||
} else if (id == data.id) {
|
} else if (id == data.id) {
|
||||||
pid.unref()
|
|
||||||
handleZip(id, ws)
|
handleZip(id, ws)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user