From 423f19de68ae249208411e63d42e3810e0f6749f Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Tue, 11 May 2021 15:14:36 +0200 Subject: [PATCH] Only crash when not watching after everything is pre-compiled --- src/frontend/AssetPreCompiler.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/frontend/AssetPreCompiler.ts b/src/frontend/AssetPreCompiler.ts index fc09716..d051160 100644 --- a/src/frontend/AssetPreCompiler.ts +++ b/src/frontend/AssetPreCompiler.ts @@ -11,6 +11,8 @@ export default abstract class AssetPreCompiler { private afterPreCompileHandlers: ((watch: boolean) => Promise)[] = []; private inputChangeHandler?: (restart: boolean) => Promise; + private hadError: boolean = false; + /** * @param targetDir The directory to put pre-compiled assets into. * @param assetType This must be the assets sub-directory name of the asset type this pre-compiler will handle. @@ -71,6 +73,10 @@ export default abstract class AssetPreCompiler { } public async preCompileAll(watch: boolean): Promise { + if (watch) { + await this.watch(); + } + logger.info(`Pre-compiling ${this.extension} views...`); // List all views @@ -84,16 +90,26 @@ export default abstract class AssetPreCompiler { } // Deduplicate and pre-compile + const hasInputChanged = this.hadError; + this.hadError = false; for (const canonicalName of [...new Set(views)]) { - await this.preCompile(canonicalName, false); + try { + await this.preCompile(canonicalName, false); + } catch (e) { + logger.error(e); + this.hadError = true; + } + } + + // If previous preCompileAll had errors, not all output files were generated. + if (hasInputChanged) { + await this.inputChangeHandler?.(false); } await this.afterPreCompile(watch); - if (watch) { - await this.watch(); + if (this.hadError && !watch) throw new Error('Errors while precompiling assets.'); } - } public async watch(): Promise { const watchedPaths = this.assetPaths.map(p => `${p}/**/*.${this.getExtension()}`);