refactor: make the default build workflow a part of SabryBuilder API

This commit is contained in:
Yiffy Dev 2024-11-03 17:51:24 +05:00 • committed by spushk
commit 2febb2b3c0
Signed by: spushk
GPG key ID: 7797B761E105E8AA

View file

@ -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<Item = StyleModule>) -> 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<Item = StyleModule>,
) -> 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);
}