Add svelte as a view engine to swaf #33

Merged
ashpie merged 97 commits from svelte into develop 2021-11-09 19:31:22 +01:00
Showing only changes of commit 423f19de68 - Show all commits

View File

@ -11,6 +11,8 @@ export default abstract class AssetPreCompiler {
private afterPreCompileHandlers: ((watch: boolean) => Promise<void>)[] = []; private afterPreCompileHandlers: ((watch: boolean) => Promise<void>)[] = [];
private inputChangeHandler?: (restart: boolean) => Promise<void>; private inputChangeHandler?: (restart: boolean) => Promise<void>;
private hadError: boolean = false;
/** /**
* @param targetDir The directory to put pre-compiled assets into. * @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. * @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<void> { public async preCompileAll(watch: boolean): Promise<void> {
if (watch) {
await this.watch();
}
logger.info(`Pre-compiling ${this.extension} views...`); logger.info(`Pre-compiling ${this.extension} views...`);
// List all views // List all views
@ -84,16 +90,26 @@ export default abstract class AssetPreCompiler {
} }
// Deduplicate and pre-compile // Deduplicate and pre-compile
const hasInputChanged = this.hadError;
this.hadError = false;
for (const canonicalName of [...new Set<string>(views)]) { for (const canonicalName of [...new Set<string>(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); await this.afterPreCompile(watch);
if (watch) { if (this.hadError && !watch) throw new Error('Errors while precompiling assets.');
await this.watch();
} }
}
public async watch(): Promise<void> { public async watch(): Promise<void> {
const watchedPaths = this.assetPaths.map(p => `${p}/**/*.${this.getExtension()}`); const watchedPaths = this.assetPaths.map(p => `${p}/**/*.${this.getExtension()}`);