Fix --watch-only to actually rebuild the site

This commit is contained in:
Robert O'Callahan 2019-01-25 13:47:30 +13:00
parent 1e2dd9ce03
commit 986c49daf1

View file

@ -90,23 +90,25 @@ fn livereload_handler(_: &HttpRequest) -> &'static str {
LIVE_RELOAD LIVE_RELOAD
} }
fn rebuild_done_handling(broadcaster: &Sender, res: Result<()>, reload_path: &str) { fn rebuild_done_handling(broadcaster: &Option<Sender>, res: Result<()>, reload_path: &str) {
match res { match res {
Ok(_) => { Ok(_) => {
broadcaster if let Some(broadcaster) = broadcaster.as_ref() {
.send(format!( broadcaster
r#" .send(format!(
{{ r#"
"command": "reload", {{
"path": "{}", "command": "reload",
"originalPath": "", "path": "{}",
"liveCSS": true, "originalPath": "",
"liveImg": true, "liveCSS": true,
"protocol": ["http://livereload.com/protocols/official-7"] "liveImg": true,
}}"#, "protocol": ["http://livereload.com/protocols/official-7"]
reload_path }}"#,
)) reload_path
.unwrap(); ))
.unwrap();
}
} }
Err(e) => console::unravel_errors("Failed to build the site", &e), Err(e) => console::unravel_errors("Failed to build the site", &e),
} }
@ -293,14 +295,12 @@ pub fn serve(
format!("-> Template changed {}", path.display()) format!("-> Template changed {}", path.display())
}; };
console::info(&msg); console::info(&msg);
if let Some(ref broadcaster) = broadcaster { // Force refresh
// Force refresh rebuild_done_handling(
rebuild_done_handling( &broadcaster,
broadcaster, rebuild::after_template_change(site, &path),
rebuild::after_template_change(site, &path), "/x.js",
"/x.js", );
);
}
}; };
let reload_sass = |site: &Site, path: &Path, partial_path: &Path| { let reload_sass = |site: &Site, path: &Path, partial_path: &Path| {
@ -310,13 +310,11 @@ pub fn serve(
format!("-> Sass file changed {}", path.display()) format!("-> Sass file changed {}", path.display())
}; };
console::info(&msg); console::info(&msg);
if let Some(ref broadcaster) = broadcaster { rebuild_done_handling(
rebuild_done_handling( &broadcaster,
&broadcaster, site.compile_sass(&site.base_path),
site.compile_sass(&site.base_path), &partial_path.to_string_lossy(),
&partial_path.to_string_lossy(), );
);
}
}; };
let copy_static = |site: &Site, path: &Path, partial_path: &Path| { let copy_static = |site: &Site, path: &Path, partial_path: &Path| {
@ -332,20 +330,18 @@ pub fn serve(
}; };
console::info(&msg); console::info(&msg);
if let Some(ref broadcaster) = broadcaster { if path.is_dir() {
if path.is_dir() { rebuild_done_handling(
rebuild_done_handling( &broadcaster,
broadcaster, site.copy_static_directories(),
site.copy_static_directories(), &path.to_string_lossy(),
&path.to_string_lossy(), );
); } else {
} else { rebuild_done_handling(
rebuild_done_handling( &broadcaster,
broadcaster, copy_file(&path, &site.output_path, &site.static_path),
copy_file(&path, &site.output_path, &site.static_path), &partial_path.to_string_lossy(),
&partial_path.to_string_lossy(), );
);
}
} }
}; };
@ -373,14 +369,12 @@ pub fn serve(
match change_kind { match change_kind {
ChangeKind::Content => { ChangeKind::Content => {
console::info(&format!("-> Content renamed {}", path.display())); console::info(&format!("-> Content renamed {}", path.display()));
if let Some(ref broadcaster) = broadcaster { // Force refresh
// Force refresh rebuild_done_handling(
rebuild_done_handling( &broadcaster,
broadcaster, rebuild::after_content_rename(&mut site, &old_path, &path),
rebuild::after_content_rename(&mut site, &old_path, &path), "/x.js",
"/x.js", );
);
}
} }
ChangeKind::Templates => reload_templates(&mut site, &path), ChangeKind::Templates => reload_templates(&mut site, &path),
ChangeKind::StaticFiles => copy_static(&site, &path, &partial_path), ChangeKind::StaticFiles => copy_static(&site, &path, &partial_path),
@ -414,14 +408,12 @@ pub fn serve(
match detect_change_kind(&pwd, &path) { match detect_change_kind(&pwd, &path) {
(ChangeKind::Content, _) => { (ChangeKind::Content, _) => {
console::info(&format!("-> Content changed {}", path.display())); console::info(&format!("-> Content changed {}", path.display()));
if let Some(ref broadcaster) = broadcaster { // Force refresh
// Force refresh rebuild_done_handling(
rebuild_done_handling( &broadcaster,
broadcaster, rebuild::after_content_change(&mut site, &path),
rebuild::after_content_change(&mut site, &path), "/x.js",
"/x.js", );
);
}
} }
(ChangeKind::Templates, _) => reload_templates(&mut site, &path), (ChangeKind::Templates, _) => reload_templates(&mut site, &path),
(ChangeKind::StaticFiles, p) => copy_static(&site, &path, &p), (ChangeKind::StaticFiles, p) => copy_static(&site, &path, &p),