feat: add clear console function in watch script

This commit is contained in:
lzdyes 2022-05-14 20:05:32 +08:00
parent 41eafc6252
commit 8089ebcb90
No known key found for this signature in database
GPG Key ID: 2FE62F8D86CEB3C5

View File

@ -6,6 +6,14 @@ import readline from 'readline'
const query = new URLSearchParams(import.meta.url.split('?')[1]) const query = new URLSearchParams(import.meta.url.split('?')[1])
const debug = query.has('debug') const debug = query.has('debug')
/** The log will display on the next screen */
function clearConsole() {
const blank = '\n'.repeat(process.stdout.rows)
console.log(blank)
readline.cursorTo(process.stdout, 0, 0)
readline.clearScreenDown(process.stdout)
}
/** /**
* @type {(server: import('vite').ViteDevServer) => Promise<import('rollup').RollupWatcher>} * @type {(server: import('vite').ViteDevServer) => Promise<import('rollup').RollupWatcher>}
*/ */
@ -25,6 +33,7 @@ function watchMain(server) {
const startElectron = { const startElectron = {
name: 'electron-main-watcher', name: 'electron-main-watcher',
writeBundle() { writeBundle() {
clearConsole()
electronProcess && electronProcess.kill() electronProcess && electronProcess.kill()
electronProcess = spawn(electron, ['.'], { stdio: 'inherit', env }) electronProcess = spawn(electron, ['.'], { stdio: 'inherit', env })
}, },
@ -50,6 +59,7 @@ function watchPreload(server) {
plugins: [{ plugins: [{
name: 'electron-preload-watcher', name: 'electron-preload-watcher',
writeBundle() { writeBundle() {
clearConsole()
server.ws.send({ type: 'full-reload' }) server.ws.send({ type: 'full-reload' })
}, },
}], }],