Skip to content

Commit ee60a71

Browse files
authored
Merge pull request #127 from lzdyes/main
Adjust the watch script
2 parents 41eafc6 + 56b59c9 commit ee60a71

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

scripts/watch.mjs

Lines changed: 19 additions & 1 deletion
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
*/
@@ -19,14 +27,23 @@ function watchMain(server) {
1927
VITE_DEV_SERVER_HOST: address.address,
2028
VITE_DEV_SERVER_PORT: address.port,
2129
})
30+
2231
/**
2332
* @type {import('vite').Plugin}
2433
*/
2534
const startElectron = {
2635
name: 'electron-main-watcher',
2736
writeBundle() {
28-
electronProcess && electronProcess.kill()
37+
clearConsole()
38+
39+
if (electronProcess) {
40+
electronProcess.removeAllListeners()
41+
electronProcess.kill()
42+
electronProcess = null
43+
}
44+
2945
electronProcess = spawn(electron, ['.'], { stdio: 'inherit', env })
46+
electronProcess.on('exit', process.exit)
3047
},
3148
}
3249

@@ -50,6 +67,7 @@ function watchPreload(server) {
5067
plugins: [{
5168
name: 'electron-preload-watcher',
5269
writeBundle() {
70+
clearConsole()
5371
server.ws.send({ type: 'full-reload' })
5472
},
5573
}],

0 commit comments

Comments
 (0)