cli: Prepare for rebuilding the site via file watcher.

This commit is contained in:
Dorian 2019-12-11 19:05:08 -05:00
parent ad01c42ac2
commit 936e91517f
1 changed files with 31 additions and 3 deletions

View File

@ -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");