From cee86bc453f085b4510f040c7d0bc717a39ea3f5 Mon Sep 17 00:00:00 2001 From: Northword Date: Thu, 8 Feb 2024 17:51:42 +0800 Subject: [PATCH] feat: start devtool --- src/lib/serve.ts | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/lib/serve.ts b/src/lib/serve.ts index 7740167..71c2d95 100644 --- a/src/lib/serve.ts +++ b/src/lib/serve.ts @@ -19,11 +19,11 @@ export default class Serve extends Base { async run() { // build - this.builder.run(); + await this.builder.run(); // start Zotero - // this.startZotero(); - this.startZoteroWebExt(); + this.startZotero(); + // this.startZoteroWebExt(); // watch await this.config.extraServer(this.config); @@ -78,7 +78,8 @@ export default class Serve extends Base { }); } - startZotero() { + async startZotero() { + let isZoteroReady = false; if (!fs.existsSync(this.zoteroBinPath)) { throw new Error("Zotero binary does not exist."); } @@ -87,6 +88,8 @@ export default class Serve extends Base { throw new Error("The given Zotero profile does not exist."); } + this.prepareDevEnv(); + const zoteroProcess = spawn(this.zoteroBinPath, [ "--debugger", "--purgecaches", @@ -94,6 +97,23 @@ export default class Serve extends Base { this.profilePath, ]); + zoteroProcess.stdout?.on("data", (data) => { + if ( + !isZoteroReady && + data + .toString() + .includes( + `Calling bootstrap method 'startup' for plugin ${this.addonID}`, + ) + ) { + console.log(data.toString()); + isZoteroReady = true; + setTimeout(() => { + this.openDevTool(); + }, 1000); + } + }); + zoteroProcess.on("close", (code) => { this.logger.info(`Zotero terminated with code ${code}.`); exit(0); @@ -104,6 +124,8 @@ export default class Serve extends Base { zoteroProcess.kill(); exit(); }); + + return zoteroProcess; } /** @@ -266,11 +288,11 @@ export default class Serve extends Base { } private get zoteroBinPath() { - this.logger.debug("zoteroBinPath", process.env.zoteroBinPath); + // this.logger.debug("zoteroBinPath", process.env.zoteroBinPath); return process.env.zoteroBinPath ?? ""; } private get profilePath() { - this.logger.debug("profilePath", process.env.profilePath); + // this.logger.debug("profilePath", process.env.profilePath); return process.env.profilePath ?? ""; } private get dataDir() {