cli: Refactor to use build directory.

This commit is contained in:
Dorian 2020-01-24 19:27:33 -05:00
parent 636adae4ad
commit cdabc662d7
2 changed files with 6 additions and 8 deletions

View File

@ -19,19 +19,14 @@ pub fn serve_site(
let project_directory = project.root_dir();
// Check if build directory is available.
let build_directory = project_directory.clone().join("build");
let build_directory = project.build_dir();
if !build_directory.exists() || !build_directory.is_dir() {
caution_message("This project needs a build first!");
header_message("Attempting to build the site...");
build_site(project_directory.clone(), true)?;
}
let watched_folder = project_directory
.canonicalize()
.unwrap_or_default()
.to_str()
.unwrap_or_default()
.to_string();
let watched_folder = project_directory.to_str().unwrap_or_default().to_string();
spawn(move || watch(watched_folder));
success_message("Found a built site to serve!");
@ -85,7 +80,7 @@ fn watch(watch_path: String) -> notify::Result<()> {
let project = Project::new(&watch_path);
setup_watchers(&mut watcher, &project)?;
let build_dir = project_root_dir.join("build");
let build_dir = project.build_dir();
loop {
match rx.recv() {

View File

@ -26,6 +26,9 @@ impl Project {
pub fn root_dir(&self) -> PathBuf {
Path::new(&self.root).to_path_buf()
}
pub fn build_dir(&self) -> PathBuf {
self.root_dir().join("build")
}
}
impl Default for Project {