Skip to content

Commit 8089ebc

Browse files
committed
feat: add clear console function in watch script
1 parent 41eafc6 commit 8089ebc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

scripts/watch.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import readline from 'readline'
66
const query = new URLSearchParams(import.meta.url.split('?')[1])
77
const debug = query.has('debug')
88

9+
/** The log will display on the next screen */
10+
function clearConsole() {
11+
const blank = '\n'.repeat(process.stdout.rows)
12+
console.log(blank)
13+
readline.cursorTo(process.stdout, 0, 0)
14+
readline.clearScreenDown(process.stdout)
15+
}
16+
917
/**
1018
* @type {(server: import('vite').ViteDevServer) => Promise<import('rollup').RollupWatcher>}
1119
*/
@@ -25,6 +33,7 @@ function watchMain(server) {
2533
const startElectron = {
2634
name: 'electron-main-watcher',
2735
writeBundle() {
36+
clearConsole()
2837
electronProcess && electronProcess.kill()
2938
electronProcess = spawn(electron, ['.'], { stdio: 'inherit', env })
3039
},
@@ -50,6 +59,7 @@ function watchPreload(server) {
5059
plugins: [{
5160
name: 'electron-preload-watcher',
5261
writeBundle() {
62+
clearConsole()
5363
server.ws.send({ type: 'full-reload' })
5464
},
5565
}],

0 commit comments

Comments
 (0)