From 42467b3e6668bd1296c9a413e5b7e16eb8720046 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 31 Jul 2020 16:27:32 -0500 Subject: [PATCH] Watch plugin and restart when it changes --- ci/dev/watch.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ci/dev/watch.ts b/ci/dev/watch.ts index 8a7372d0..ba386b75 100644 --- a/ci/dev/watch.ts +++ b/ci/dev/watch.ts @@ -37,6 +37,7 @@ class Watcher { const vscode = cp.spawn("yarn", ["watch"], { cwd: this.vscodeSourcePath }) const tsc = cp.spawn("tsc", ["--watch", "--pretty", "--preserveWatchOutput"], { cwd: this.rootPath }) + const plugin = cp.spawn("yarn", ["build", "--watch"], { cwd: process.env.PLUGIN_DIR }) const bundler = this.createBundler() const cleanup = (code?: number | null): void => { @@ -48,6 +49,10 @@ class Watcher { tsc.removeAllListeners() tsc.kill() + Watcher.log("killing plugin") + plugin.removeAllListeners() + plugin.kill() + if (server) { Watcher.log("killing server") server.removeAllListeners() @@ -69,6 +74,10 @@ class Watcher { Watcher.log("tsc terminated unexpectedly") cleanup(code) }) + plugin.on("exit", (code) => { + Watcher.log("plugin terminated unexpectedly") + cleanup(code) + }) const bundle = bundler.bundle().catch(() => { Watcher.log("parcel watcher terminated unexpectedly") cleanup(1) @@ -82,6 +91,7 @@ class Watcher { vscode.stderr.on("data", (d) => process.stderr.write(d)) tsc.stderr.on("data", (d) => process.stderr.write(d)) + plugin.stderr.on("data", (d) => process.stderr.write(d)) // From https://github.com/chalk/ansi-regex const pattern = [ @@ -140,6 +150,16 @@ class Watcher { bundle.then(restartServer) } }) + + onLine(plugin, (line, original) => { + // tsc outputs blank lines; skip them. + if (line !== "") { + console.log("[plugin]", original) + } + if (line.includes("Watching for file changes")) { + bundle.then(restartServer) + } + }) } private createBundler(out = "dist"): Bundler {