use std::{process::Termination, time::Instant};
use rustc_hash::FxHashMap;
#[derive(Debug)]
pub struct PageOutput {
pub route: String,
pub file_path: String,
pub params: Option<FxHashMap<String, Option<String>>>,
pub cached: bool,
}
#[derive(Debug)]
pub struct StaticAssetOutput {
pub file_path: String,
pub original_path: String,
}
#[derive(Debug)]
pub struct BuildOutput {
pub start_time: Instant,
pub pages: Vec<PageOutput>,
pub assets: Vec<String>,
pub static_files: Vec<StaticAssetOutput>,
pub(crate) removed_pages: usize,
}
impl BuildOutput {
pub fn new(start_time: Instant) -> Self {
Self {
start_time,
pages: Vec::new(),
assets: Vec::new(),
static_files: Vec::new(),
removed_pages: 0,
}
}
pub(crate) fn add_page(
&mut self,
route: String,
file_path: String,
params: Option<FxHashMap<String, Option<String>>>,
cached: bool,
) {
self.pages.push(PageOutput {
route,
file_path,
params,
cached,
});
}
pub(crate) fn add_asset(&mut self, file_path: String) {
self.assets.push(file_path);
}
pub(crate) fn add_static_file(&mut self, file_path: String, original_path: String) {
self.static_files.push(StaticAssetOutput {
file_path,
original_path,
});
}
pub fn has_changes(&self) -> bool {
self.removed_pages > 0 || self.pages.iter().any(|p| !p.cached)
}
}
impl Default for BuildOutput {
fn default() -> Self {
Self::new(Instant::now())
}
}
impl Termination for BuildOutput {
fn report(self) -> std::process::ExitCode {
0.into()
}
}