diff --git a/ci/dev/watch.ts b/ci/dev/watch.ts index 0bd3c5673..6f7291099 100644 --- a/ci/dev/watch.ts +++ b/ci/dev/watch.ts @@ -2,7 +2,7 @@ import { spawn, fork, ChildProcess } from "child_process" import del from "del" import { promises as fs } from "fs" import * as path from "path" -import { CompilationStats, onLine, OnLineCallback, VSCodeCompileStatus } from "../../src/node/util" +import { CompilationStats, onLine, OnLineCallback } from "../../src/node/util" interface DevelopmentCompilers { [key: string]: ChildProcess | undefined @@ -52,24 +52,18 @@ class Watcher { plugins: this.paths.pluginDir ? spawn("yarn", ["build", "--watch"], { cwd: this.paths.pluginDir }) : undefined, } - private vscodeCompileStatus = VSCodeCompileStatus.Loading - public async initialize(): Promise { for (const event of ["SIGINT", "SIGTERM"]) { process.on(event, () => this.dispose(0)) } - if (!this.hasVerboseLogging) { - console.log("\n[Watcher]", "Compiler logs will be minimal. Pass --log to show all output.") - } - this.cleanFiles() for (const [processName, devProcess] of Object.entries(this.compilers)) { if (!devProcess) continue devProcess.on("exit", (code) => { - this.log(`[${processName}]`, "Terminated unexpectedly") + console.log(`[${processName}]`, "Terminated unexpectedly") this.dispose(code) }) @@ -91,33 +85,14 @@ class Watcher { //#region Line Parsers private parseVSCodeLine: OnLineCallback = (strippedLine, originalLine) => { - if (!strippedLine.includes("watch-extensions") || this.hasVerboseLogging) { - console.log("[VS Code]", originalLine) - } + if (!strippedLine.length) return - switch (this.vscodeCompileStatus) { - case VSCodeCompileStatus.Loading: - // Wait for watch-client since "Finished compilation" will appear multiple - // times before the client starts building. - if (strippedLine.includes("Starting 'watch-client'")) { - console.log("[VS Code] 🚧 Compiling 🚧", "(This may take a moment!)") - this.vscodeCompileStatus = VSCodeCompileStatus.Compiling - } - break - case VSCodeCompileStatus.Compiling: - if (strippedLine.includes("Finished compilation")) { - console.log("[VS Code] ✨ Finished compiling! ✨", "(Refresh your web browser ♻️)") - this.vscodeCompileStatus = VSCodeCompileStatus.Compiled + console.log("[VS Code]", originalLine) - this.emitCompilationStats() - this.reloadWebServer() - } - break - case VSCodeCompileStatus.Compiled: - console.log("[VS Code] 🔔 Finished recompiling! 🔔", "(Refresh your web browser ♻️)") - this.emitCompilationStats() - this.reloadWebServer() - break + if (strippedLine.includes("Finished compilation with")) { + console.log("[VS Code] ✨ Finished compiling! ✨", "(Refresh your web browser ♻️)") + this.emitCompilationStats() + this.reloadWebServer() } } @@ -128,7 +103,6 @@ class Watcher { if (strippedLine.includes("Watching for file changes")) { console.log("[Compiler][Code Server]", "Finished compiling!", "(Refresh your web browser ♻️)") - this.reloadWebServer() } } @@ -153,11 +127,7 @@ class Watcher { private cleanFiles(): Promise { console.log("[Watcher]", "Cleaning files from previous builds...") - return del([ - "out/**/*", - // Included because the cache can sometimes enter bad state when debugging compiled files. - ".cache/**/*", - ]) + return del(["out/**/*"]) } /** @@ -166,31 +136,22 @@ class Watcher { */ private emitCompilationStats(): Promise { const stats: CompilationStats = { - status: this.vscodeCompileStatus, lastCompiledAt: new Date(), } - this.log("Writing watcher stats...") + console.log("Writing watcher stats...") return fs.writeFile(this.paths.compilationStatsFile, JSON.stringify(stats, null, 2)) } - private log(...entries: string[]) { - process.stdout.write(entries.join(" ")) - } - private dispose(code: number | null): void { for (const [processName, devProcess] of Object.entries(this.compilers)) { - this.log(`[${processName}]`, "Killing...\n") + console.log(`[${processName}]`, "Killing...\n") devProcess?.removeAllListeners() devProcess?.kill() } process.exit(typeof code === "number" ? code : 0) } - private get hasVerboseLogging() { - return process.argv.includes("--log") - } - //#endregion } diff --git a/src/node/util.ts b/src/node/util.ts index d12ba6f0c..24cd8b30e 100644 --- a/src/node/util.ts +++ b/src/node/util.ts @@ -524,14 +524,7 @@ export const loadAMDModule = async (amdPath: string, exportName: string): Pro return module[exportName] as T } -export const enum VSCodeCompileStatus { - Loading = "Loading", - Compiling = "Compiling", - Compiled = "Compiled", -} - export interface CompilationStats { - status: VSCodeCompileStatus lastCompiledAt: Date }