Rust library to generate static websites
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: return a build output manifest from coronate

+75 -13
-5
Cargo.toml
··· 1 1 [workspace] 2 2 members = ["crates/*"] 3 3 resolver = "2" 4 - 5 - [profile.release] 6 - opt-level = 3 7 - lto = "fat" 8 - codegen-units = 1
+73 -6
crates/framework/src/lib.rs
··· 15 15 fs::{self, File}, 16 16 io::{self, Write}, 17 17 path::{Path, PathBuf}, 18 + process::Termination, 18 19 str::FromStr, 19 20 time::SystemTime, 20 21 }; ··· 36 37 }; 37 38 } 38 39 39 - pub fn coronate(routes: Vec<&dyn FullPage>) -> Result<(), Box<dyn std::error::Error>> { 40 + #[derive(Debug)] 41 + pub struct PageOutput { 42 + pub route: String, 43 + pub file_path: String, 44 + pub params: Option<FxHashMap<String, String>>, 45 + } 46 + 47 + #[derive(Debug)] 48 + pub struct StaticAssetOutput { 49 + pub file_path: String, 50 + pub original_path: String, 51 + } 52 + 53 + #[derive(Debug)] 54 + pub struct BuildOutput { 55 + pub start_time: SystemTime, 56 + pub pages: Vec<PageOutput>, 57 + pub assets: Vec<String>, 58 + pub static_files: Vec<StaticAssetOutput>, 59 + } 60 + 61 + impl Termination for BuildOutput { 62 + fn report(self) -> std::process::ExitCode { 63 + 0.into() 64 + } 65 + } 66 + 67 + pub fn coronate(routes: Vec<&dyn FullPage>) -> Result<BuildOutput, Box<dyn std::error::Error>> { 40 68 tokio::runtime::Builder::new_multi_thread() 41 69 .enable_all() 42 70 .build() ··· 44 72 .block_on(async { build(routes).await }) 45 73 } 46 74 47 - pub async fn build(routes: Vec<&dyn FullPage>) -> Result<(), Box<dyn std::error::Error>> { 75 + pub async fn build(routes: Vec<&dyn FullPage>) -> Result<BuildOutput, Box<dyn std::error::Error>> { 48 76 let build_start = SystemTime::now(); 49 77 let logging_env = Env::default().filter_or("RUST_LOG", "info"); 50 78 Builder::from_env(logging_env) ··· 95 123 ..Default::default() 96 124 }; 97 125 126 + let mut build_metadata = BuildOutput { 127 + start_time: build_start, 128 + pages: Vec::new(), 129 + assets: Vec::new(), 130 + static_files: Vec::new(), 131 + }; 132 + 98 133 let mut build_pages_assets: FxHashSet<Box<dyn Asset>> = FxHashSet::default(); 99 134 let mut build_pages_scripts: FxHashSet<assets::Script> = FxHashSet::default(); 100 135 ··· 118 153 119 154 build_pages_assets.extend(page_assets.assets); 120 155 build_pages_scripts.extend(page_assets.scripts); 156 + 157 + build_metadata.pages.push(PageOutput { 158 + route: route.route_raw().to_string(), 159 + file_path: file_path.to_string_lossy().to_string(), 160 + params: None, 161 + }); 121 162 } 122 163 false => { 123 164 info!(target: "build", "{}", route.route_raw().to_string().bold()); ··· 134 175 135 176 let formatted_elasped_time = format_elapsed_time(route_start.elapsed(), &route_format_options).unwrap(); 136 177 info!(target: "build", "├─ {} {}", file_path.to_string_lossy().dimmed(), formatted_elasped_time); 178 + 179 + build_metadata.pages.push(PageOutput { 180 + route: route.route_raw(), 181 + file_path: file_path.to_string_lossy().to_string(), 182 + params: Some(ctx.params.0.clone()), 183 + }); 137 184 }); 138 185 139 186 build_pages_assets.extend(pages_assets.assets); ··· 151 198 152 199 build_pages_assets.iter().for_each(|asset| { 153 200 asset.process(); 201 + 202 + // TODO: Add outputted assets to build_metadata, might need dedicated fs methods for this 154 203 }); 155 204 156 205 let bundler_inputs = build_pages_scripts ··· 171 220 }); 172 221 173 222 let _result = bundler.write().await.unwrap(); 223 + 224 + // TODO: Add outputted chunks to build_metadata 174 225 } 175 226 176 227 let formatted_elasped_time = ··· 183 234 info!(target: "SKIP_FORMAT", "{}", " copying assets ".on_green().bold()); 184 235 185 236 // Copy the static directory to the dist directory 186 - copy_recursively("./static", "./dist")?; 237 + copy_recursively("./static", "./dist", &mut build_metadata)?; 187 238 188 239 let formatted_elasped_time = 189 240 format_elapsed_time(assets_start.elapsed(), &FormatElapsedTimeOptions::default())?; ··· 194 245 format_elapsed_time(build_start.elapsed(), &section_format_options)?; 195 246 info!(target: "build", "{}", format!("Build completed in {}", formatted_elasped_time).bold()); 196 247 197 - Ok(()) 248 + Ok(build_metadata) 198 249 } 199 250 200 - fn copy_recursively(source: impl AsRef<Path>, destination: impl AsRef<Path>) -> io::Result<()> { 251 + fn copy_recursively( 252 + source: impl AsRef<Path>, 253 + destination: impl AsRef<Path>, 254 + build_metadata: &mut BuildOutput, 255 + ) -> io::Result<()> { 201 256 fs::create_dir_all(&destination)?; 202 257 for entry in fs::read_dir(source)? { 203 258 let entry = entry?; 204 259 let filetype = entry.file_type()?; 205 260 if filetype.is_dir() { 206 - copy_recursively(entry.path(), destination.as_ref().join(entry.file_name()))?; 261 + copy_recursively( 262 + entry.path(), 263 + destination.as_ref().join(entry.file_name()), 264 + build_metadata, 265 + )?; 207 266 } else { 208 267 fs::copy(entry.path(), destination.as_ref().join(entry.file_name()))?; 268 + build_metadata.static_files.push(StaticAssetOutput { 269 + original_path: entry.path().to_string_lossy().to_string(), 270 + file_path: destination 271 + .as_ref() 272 + .join(entry.file_name()) 273 + .to_string_lossy() 274 + .to_string(), 275 + }); 209 276 } 210 277 } 211 278 Ok(())
+2 -2
crates/user-example/src/main.rs
··· 1 - use maudit::{coronate, generate_pages_mod, routes}; 1 + use maudit::{coronate, generate_pages_mod, routes, BuildOutput}; 2 2 3 3 generate_pages_mod!(); 4 4 5 - fn main() -> Result<(), Box<dyn std::error::Error>> { 5 + fn main() -> Result<BuildOutput, Box<dyn std::error::Error>> { 6 6 coronate(routes![Index, DynamicExample, Endpoint]) 7 7 }