You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

82 lines
2.1 KiB

// @ts-nocheck
import * as chalk from "chalk"
import { devVite } from "./code/runVite"
import { devElectron } from "./code/runElectron"
import {logStats,electronLog} from "./log"
import { ChildProcess } from "child_process"
import { watch } from "rollup"
import options from "./rollup.config"
const { startMain } = require("./webpack/runMain")
;(async () => {
let vitePorcess = await devVite()
logStats("vite","vite ready.")
let child: ChildProcess | null
let manualRestart = false
startMain(async () => {
if (child && child.kill) {
manualRestart = true
child.kill()
child = null
setTimeout(() => {
manualRestart = false
}, 5000)
}
try {
child = await devElectron()
electronLog("electron ready.","green")
child.on("close", () => {
if (!manualRestart) {
// https://juejin.cn/post/6844904071682326535
vitePorcess.kill()
child.kill()
process.exit()
}
})
} catch (ev) {
console.log(ev.error)
vitePorcess.kill()
child.kill()
process.exit()
}
})
})()
// const watcher = watch(opts)
// let child: ChildProcess | null
// let manualRestart = false
// watcher.on("change", filename => {
// const log = chalk.green(`change -- ${filename}`)
// console.log(TAG, log)
// })
// watcher.on("event",async ev => {
// if (ev.code === "END") {
// if (child && child.kill) {
// manualRestart = true
// child.kill()
// child = null
// setTimeout(() => {
// manualRestart = false
// }, 5000)
// }
// try {
// child = await runElectron()
// console.log('[electron]', chalk.green(`electron ready.`))
// child.on("close", () => {
// if (!manualRestart) {
// vitePorcess.kill()
// child.kill()
// process.exit()
// }
// })
// } catch (ev) {
// console.log(ev.error)
// vitePorcess.kill()
// child.kill()
// process.exit()
// }
// } else if (ev.code === "ERROR") {
// console.log(ev.error)
// }
// })