From 936e91517f64ec91304400783a9c8fc70aa41ea3 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Wed, 11 Dec 2019 19:05:08 -0500 Subject: [PATCH] cli: Prepare for rebuilding the site via file watcher. --- src/main.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4a90273..9480edd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ use chrono::prelude::*; use colored::Colorize; use docopt::Docopt; -use notify::{RecommendedWatcher, RecursiveMode, Watcher}; +use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher}; use rookeries::{ cli::{ @@ -210,19 +210,47 @@ fn watch(watch_path: String) -> notify::Result<()> { let plugins_dir = project_root_dir.join("plugins"); watcher.watch(plugins_dir, RecursiveMode::NonRecursive)?; + let build_dir = project_root_dir.join("build"); + loop { match rx.recv() { - // TODO: Add calls to build_site() // TODO: Add more fine-grained control to avoid a full rebuild for minor changes. - Ok(event) => details_message(&format!("{:?}", event)), + // TODO: Add in a safe place to build the site. + Ok(event) => { + details_message(&format!("{:?}", event)); + + match event { + DebouncedEvent::Rescan => (), + DebouncedEvent::Remove(path) => { + if path.starts_with(&build_dir) { + details_message("Build path"); + } + } + DebouncedEvent::Create(path) => { + if path.starts_with(&build_dir) { + details_message("Build path"); + } + } + _ => { + details_message("Not build path"); + } + } + } Err(e) => details_message(&format!("watch error: {:?}", e)), } } } +#[deprecated] fn build_site(args: &Args) -> Result { header_message("Building the site..."); let project_directory = get_project_directory(&args)?; + build_site_from_path(project_directory) +} + +// TODO: Update to be just build_site... +fn build_site_from_path(project_directory: PathBuf) -> Result { + header_message("Building the site..."); // Check if project manifest is available. let project_manifest = project_directory.clone().join("site.toml");