From 8089ebcb9025398d614f99405aa34f7a7dba22d9 Mon Sep 17 00:00:00 2001 From: lzdyes Date: Sat, 14 May 2022 20:05:32 +0800 Subject: [PATCH 1/2] feat: add clear console function in watch script --- scripts/watch.mjs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/watch.mjs b/scripts/watch.mjs index a78cecd..b8de749 100644 --- a/scripts/watch.mjs +++ b/scripts/watch.mjs @@ -6,6 +6,14 @@ import readline from 'readline' const query = new URLSearchParams(import.meta.url.split('?')[1]) 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} */ @@ -25,6 +33,7 @@ function watchMain(server) { const startElectron = { name: 'electron-main-watcher', writeBundle() { + clearConsole() electronProcess && electronProcess.kill() electronProcess = spawn(electron, ['.'], { stdio: 'inherit', env }) }, @@ -50,6 +59,7 @@ function watchPreload(server) { plugins: [{ name: 'electron-preload-watcher', writeBundle() { + clearConsole() server.ws.send({ type: 'full-reload' }) }, }], From 56b59c9702335befada956f88230568c1d01a3c4 Mon Sep 17 00:00:00 2001 From: lzdyes Date: Sat, 14 May 2022 20:09:22 +0800 Subject: [PATCH 2/2] feat: exit the command when closing the application --- scripts/watch.mjs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/watch.mjs b/scripts/watch.mjs index b8de749..fe65433 100644 --- a/scripts/watch.mjs +++ b/scripts/watch.mjs @@ -27,6 +27,7 @@ function watchMain(server) { VITE_DEV_SERVER_HOST: address.address, VITE_DEV_SERVER_PORT: address.port, }) + /** * @type {import('vite').Plugin} */ @@ -34,8 +35,15 @@ function watchMain(server) { name: 'electron-main-watcher', writeBundle() { clearConsole() - electronProcess && electronProcess.kill() + + if (electronProcess) { + electronProcess.removeAllListeners() + electronProcess.kill() + electronProcess = null + } + electronProcess = spawn(electron, ['.'], { stdio: 'inherit', env }) + electronProcess.on('exit', process.exit) }, }