Skip to content

Commit

Permalink
Add support for watching additional directories
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Oct 28, 2022
1 parent 1a08927 commit fb0cbc9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cmd/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ where
// Add the book.toml file to the watcher if it exists
let _ = watcher.watch(book.root.join("book.toml"), NonRecursive);

for dir in &book.config.build.extra_watch_dirs {
let _ = watcher.watch(dir, Recursive);
}

info!("Listening for changes...");

loop {
Expand Down
5 changes: 5 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ pub struct BuildConfig {
/// Should the default preprocessors always be used when they are
/// compatible with the renderer?
pub use_default_preprocessors: bool,
/// Extra directories to trigger rebuild when watching/serving
pub extra_watch_dirs: Vec<PathBuf>,
}

impl Default for BuildConfig {
Expand All @@ -445,6 +447,7 @@ impl Default for BuildConfig {
build_dir: PathBuf::from("book"),
create_missing: true,
use_default_preprocessors: true,
extra_watch_dirs: Vec::new(),
}
}
}
Expand Down Expand Up @@ -770,6 +773,7 @@ mod tests {
build_dir: PathBuf::from("outputs"),
create_missing: false,
use_default_preprocessors: true,
extra_watch_dirs: Vec::new(),
};
let rust_should_be = RustConfig { edition: None };
let playground_should_be = Playground {
Expand Down Expand Up @@ -980,6 +984,7 @@ mod tests {
build_dir: PathBuf::from("my-book"),
create_missing: true,
use_default_preprocessors: true,
extra_watch_dirs: Vec::new(),
};

let html_should_be = HtmlConfig {
Expand Down

0 comments on commit fb0cbc9

Please sign in to comment.