[web] Ignore changes in *.ttf files in felt build watch mode (#13634)

This commit is contained in:
Mouad Debbar 2019-11-05 13:31:51 -08:00 committed by GitHub
parent 5b87cd0773
commit f6e24a00cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,6 +60,8 @@ class BuildCommand extends Command<bool> {
PipelineWatcher(
dir: libPath.absolute,
pipeline: buildPipeline,
// Ignore font files that are copied whenever tests run.
ignore: (event) => event.path.endsWith('.ttf'),
).start();
// Return a never-ending future.
return Completer<bool>().future;
@ -143,10 +145,13 @@ class Pipeline {
}
}
typedef WatchEventPredicate = bool Function(WatchEvent event);
class PipelineWatcher {
PipelineWatcher({
@required this.dir,
@required this.pipeline,
this.ignore,
}) : watcher = DirectoryWatcher(dir);
/// The path of the directory to watch for changes.
@ -158,6 +163,10 @@ class PipelineWatcher {
/// Used to watch a directory for any file system changes.
final DirectoryWatcher watcher;
/// A callback that determines whether to rerun the pipeline or not for a
/// given [WatchEvent] instance.
final WatchEventPredicate ignore;
void start() {
watcher.events.listen(_onEvent);
}
@ -166,6 +175,10 @@ class PipelineWatcher {
Timer _scheduledPipeline;
void _onEvent(WatchEvent event) {
if (ignore != null && ignore(event)) {
return;
}
final String relativePath = path.relative(event.path, from: dir);
print('- [${event.type}] ${relativePath}');