AssetPreCompiler: watch all view directories instead of the first one
This commit is contained in:
parent
42f7ebba05
commit
8884f70a24
@ -60,11 +60,6 @@ export default abstract class AssetPreCompiler {
|
|||||||
return this.assetPaths;
|
return this.assetPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getPrimaryAssetPath(): string {
|
|
||||||
if (this.assetPaths.length === 0) throw new Error('No asset path was found.');
|
|
||||||
return this.assetPaths[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract preCompile(canonicalName: string, alsoCompileDependents: boolean): Promise<void>;
|
public abstract preCompile(canonicalName: string, alsoCompileDependents: boolean): Promise<void>;
|
||||||
|
|
||||||
public onPreCompile(afterPreCompileHandler: (watch: boolean) => Promise<void>): void {
|
public onPreCompile(afterPreCompileHandler: (watch: boolean) => Promise<void>): void {
|
||||||
@ -101,39 +96,34 @@ export default abstract class AssetPreCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async watch(): Promise<void> {
|
public async watch(): Promise<void> {
|
||||||
this.watcher = chokidar.watch(this.getPrimaryAssetPath(), {persistent: true});
|
const watchedPaths = this.assetPaths.map(p => `${p}/**/*.${this.getExtension()}`);
|
||||||
|
this.watcher = chokidar.watch(watchedPaths, {persistent: true});
|
||||||
this.watcher.on('ready', () => {
|
this.watcher.on('ready', () => {
|
||||||
if (!this.watcher) return;
|
if (!this.watcher) return;
|
||||||
|
|
||||||
logger.info(`Watching ${this.extension} assets for changes`);
|
logger.info(`Watching ${this.extension} assets for changes in ${watchedPaths}`);
|
||||||
|
|
||||||
this.watcher.on('add', (file) => {
|
this.watcher.on('add', (file) => {
|
||||||
if (file.endsWith('.' + this.extension)) {
|
|
||||||
this.onNewFile(file)
|
this.onNewFile(file)
|
||||||
.then(() => this.preCompile(this.toCanonicalName(file), true))
|
.then(() => this.preCompile(this.toCanonicalName(file), true))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return this.afterPreCompile(true);
|
return this.afterPreCompile(true);
|
||||||
})
|
})
|
||||||
.catch(err => logger.error(err));
|
.catch(err => logger.error(err));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.watcher.on('change', (file) => {
|
this.watcher.on('change', (file) => {
|
||||||
if (file.endsWith('.' + this.extension)) {
|
|
||||||
(this.onFileChange ? this.onFileChange(file) : Promise.resolve())
|
(this.onFileChange ? this.onFileChange(file) : Promise.resolve())
|
||||||
.then(() => this.preCompile(this.toCanonicalName(file), true))
|
.then(() => this.preCompile(this.toCanonicalName(file), true))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return this.afterPreCompile(true);
|
return this.afterPreCompile(true);
|
||||||
})
|
})
|
||||||
.catch(err => logger.error(err));
|
.catch(err => logger.error(err));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.watcher.on('unlink', (file) => {
|
this.watcher.on('unlink', (file) => {
|
||||||
if (file.endsWith('.' + this.extension)) {
|
|
||||||
this.onFileRemove(file)
|
this.onFileRemove(file)
|
||||||
.catch(err => logger.error(err));
|
.catch(err => logger.error(err));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user