From 2febb2b3c08c15e8a100f72afcb846f831db97fc Mon Sep 17 00:00:00 2001 From: Yiffy Dev Date: Sun, 3 Nov 2024 17:51:24 +0500 Subject: [PATCH] refactor: make the default build workflow a part of SabryBuilder API --- sabry_build/src/buildmagic.rs | 48 +++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/sabry_build/src/buildmagic.rs b/sabry_build/src/buildmagic.rs index be71ab7..7ea2af9 100644 --- a/sabry_build/src/buildmagic.rs +++ b/sabry_build/src/buildmagic.rs @@ -47,27 +47,9 @@ type BuilderResult = Result<(), SabryBuildError>; /// /// This function is intended to run at build time, however, you're free to use it however you please pub fn buildy(inline_side_modules: impl IntoIterator) -> BuilderResult { - println!("🧙: This is probably the stderr. Something went wrong:"); - let config = SabryConfig::require()?; let mut builder = SabryBuilder::new(config); - - println!("🧙 loading preludes"); - builder.load_preludes()?; - - println!("🧙 loading `buildy` modules"); - for (name, code) in inline_side_modules { - builder.load_side_module(name, code)?; - } - - println!("🧙 loading this crate"); - builder.load_styles_from_this_crate()?; - - println!("🧙 compiling CSS"); - builder.compile_everything()?; - - println!("🧙 writing an output"); - builder.generate_output()?; + builder.build(inline_side_modules)?; Ok(()) } @@ -108,6 +90,33 @@ impl SabryBuilder { } } + /// Default building workflow implementation + pub fn build( + &mut self, + inline_side_modules: impl IntoIterator, + ) -> BuilderResult { + println!("🧙: This is probably the stderr. Something went wrong:"); + + println!("🧙 loading preludes"); + self.load_preludes()?; + + println!("🧙 loading `buildy` modules"); + for (name, code) in inline_side_modules { + self.load_side_module(name, code)?; + } + + println!("🧙 loading this crate"); + self.load_styles_from_this_crate()?; + + println!("🧙 compiling CSS"); + self.compile_everything()?; + + println!("🧙 writing an output"); + self.generate_output()?; + + Ok(()) + } + /// Write all the loaded CSS /// /// - Bundle file (if configured) @@ -228,6 +237,7 @@ impl SabryBuilder { let entry_path = entry.path(); let ext = entry_path.extension().unwrap_or_default(); if ext == "rs" { + println!(".. reading {entry_path:?}"); let visitor = filevisit::visit_file(entry_path)?; self.state.loaded_stylyses.extend(visitor.found_stylys); }