cli: Refactor to use build directory.
This commit is contained in:
parent
636adae4ad
commit
cdabc662d7
|
@ -19,19 +19,14 @@ pub fn serve_site(
|
||||||
let project_directory = project.root_dir();
|
let project_directory = project.root_dir();
|
||||||
|
|
||||||
// Check if build directory is available.
|
// 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() {
|
if !build_directory.exists() || !build_directory.is_dir() {
|
||||||
caution_message("This project needs a build first!");
|
caution_message("This project needs a build first!");
|
||||||
header_message("Attempting to build the site...");
|
header_message("Attempting to build the site...");
|
||||||
build_site(project_directory.clone(), true)?;
|
build_site(project_directory.clone(), true)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let watched_folder = project_directory
|
let watched_folder = project_directory.to_str().unwrap_or_default().to_string();
|
||||||
.canonicalize()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.to_str()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.to_string();
|
|
||||||
spawn(move || watch(watched_folder));
|
spawn(move || watch(watched_folder));
|
||||||
|
|
||||||
success_message("Found a built site to serve!");
|
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);
|
let project = Project::new(&watch_path);
|
||||||
setup_watchers(&mut watcher, &project)?;
|
setup_watchers(&mut watcher, &project)?;
|
||||||
|
|
||||||
let build_dir = project_root_dir.join("build");
|
let build_dir = project.build_dir();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match rx.recv() {
|
match rx.recv() {
|
||||||
|
|
|
@ -26,6 +26,9 @@ impl Project {
|
||||||
pub fn root_dir(&self) -> PathBuf {
|
pub fn root_dir(&self) -> PathBuf {
|
||||||
Path::new(&self.root).to_path_buf()
|
Path::new(&self.root).to_path_buf()
|
||||||
}
|
}
|
||||||
|
pub fn build_dir(&self) -> PathBuf {
|
||||||
|
self.root_dir().join("build")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Project {
|
impl Default for Project {
|
||||||
|
|
Loading…
Reference in New Issue