Skip to content

Commit 42467b3

Browse files
committed
Watch plugin and restart when it changes
1 parent 361e710 commit 42467b3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ci/dev/watch.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Watcher {
3737

3838
const vscode = cp.spawn("yarn", ["watch"], { cwd: this.vscodeSourcePath })
3939
const tsc = cp.spawn("tsc", ["--watch", "--pretty", "--preserveWatchOutput"], { cwd: this.rootPath })
40+
const plugin = cp.spawn("yarn", ["build", "--watch"], { cwd: process.env.PLUGIN_DIR })
4041
const bundler = this.createBundler()
4142

4243
const cleanup = (code?: number | null): void => {
@@ -48,6 +49,10 @@ class Watcher {
4849
tsc.removeAllListeners()
4950
tsc.kill()
5051

52+
Watcher.log("killing plugin")
53+
plugin.removeAllListeners()
54+
plugin.kill()
55+
5156
if (server) {
5257
Watcher.log("killing server")
5358
server.removeAllListeners()
@@ -69,6 +74,10 @@ class Watcher {
6974
Watcher.log("tsc terminated unexpectedly")
7075
cleanup(code)
7176
})
77+
plugin.on("exit", (code) => {
78+
Watcher.log("plugin terminated unexpectedly")
79+
cleanup(code)
80+
})
7281
const bundle = bundler.bundle().catch(() => {
7382
Watcher.log("parcel watcher terminated unexpectedly")
7483
cleanup(1)
@@ -82,6 +91,7 @@ class Watcher {
8291

8392
vscode.stderr.on("data", (d) => process.stderr.write(d))
8493
tsc.stderr.on("data", (d) => process.stderr.write(d))
94+
plugin.stderr.on("data", (d) => process.stderr.write(d))
8595

8696
// From https://github.com/chalk/ansi-regex
8797
const pattern = [
@@ -140,6 +150,16 @@ class Watcher {
140150
bundle.then(restartServer)
141151
}
142152
})
153+
154+
onLine(plugin, (line, original) => {
155+
// tsc outputs blank lines; skip them.
156+
if (line !== "") {
157+
console.log("[plugin]", original)
158+
}
159+
if (line.includes("Watching for file changes")) {
160+
bundle.then(restartServer)
161+
}
162+
})
143163
}
144164

145165
private createBundler(out = "dist"): Bundler {

0 commit comments

Comments
 (0)