Skip to content

Commit

Permalink
feat: In-memory provider
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoh committed Nov 3, 2024
1 parent ef9c18f commit 444b2db
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 51 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ path-clean = "1.0.1"
[features]
default = []
cli = ["fs_provider", "dep:mimalloc", "dep:tokio", "dep:clap", "dep:tracing-subscriber", "dep:notify-debouncer-full", "dep:actix-files", "dep:actix-web"]
fs_provider = []
fs_provider = []
ram_provider = []
9 changes: 5 additions & 4 deletions src/fs_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use miette::IntoDiagnostic;
/// A provider of the Vox build system that reads & writes from the file system.
pub struct FsProvider;
impl VoxProvider for FsProvider {
fn read_to_string(path: impl AsRef<std::path::Path>) -> miette::Result<String> {
fn read_to_string(&self, path: impl AsRef<std::path::Path>) -> miette::Result<String> {
std::fs::read_to_string(path).into_diagnostic()
}
fn write_file(
&self,
path: impl AsRef<std::path::Path> + Clone,
contents: impl AsRef<[u8]>,
) -> miette::Result<()> {
Expand All @@ -17,16 +18,16 @@ impl VoxProvider for FsProvider {
}
std::fs::write(path, contents).into_diagnostic()
}
fn remove_file(path: impl AsRef<std::path::Path>) -> miette::Result<()> {
fn remove_file(&self, path: impl AsRef<std::path::Path>) -> miette::Result<()> {
std::fs::remove_file(path).into_diagnostic()
}
fn list_vox_files() -> miette::Result<Vec<std::path::PathBuf>> {
fn list_vox_files(&self) -> miette::Result<Vec<std::path::PathBuf>> {
Ok(glob::glob("**/*.vox")
.into_diagnostic()?
.filter_map(Result::ok)
.collect())
}
fn list_snippets() -> miette::Result<Vec<std::path::PathBuf>> {
fn list_snippets(&self) -> miette::Result<Vec<std::path::PathBuf>> {
Ok(glob::glob("snippets/**/*")
.into_diagnostic()?
.filter_map(Result::ok)
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ pub mod provider;
/// A provider of the Vox build system that reads & writes from the file system.
#[cfg(feature = "fs_provider")]
pub mod fs_provider;

/// A provider of the Vox build system that reads & writes from memory.
#[cfg(feature = "ram_provider")]
pub mod ram_provider;
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ async fn main() -> miette::Result<()> {

fn build(watch: bool, visualise_dag: bool, generate_syntax_css: bool) -> miette::Result<()> {
let parser = FS_PROVIDER.create_liquid_parser()?;
let global = FsProvider::get_global_context()?;
let (mut dag, mut pages, mut layouts) = FsProvider::generate_dag()?;
let global = FS_PROVIDER.get_global_context()?;
let (mut dag, mut pages, mut layouts) = FS_PROVIDER.generate_dag()?;

// Write the initial site to the output directory.
info!("Performing initial build … ");
let (_updated_pages, updated_dag) = FsProvider::generate_site(
let (_updated_pages, updated_dag) = FS_PROVIDER.generate_site(
parser.clone(),
global.0.clone(),
global.1,
Expand Down Expand Up @@ -293,7 +293,7 @@ fn build(watch: bool, visualise_dag: bool, generate_syntax_css: bool) -> miette:
.collect::<Vec<_>>()
);

(dag, pages, layouts) = FsProvider::incremental_regeneration(
(dag, pages, layouts) = FS_PROVIDER.incremental_regeneration(
global_or_snippets_changed,
parser.clone(),
visualise_dag,
Expand Down
Loading

0 comments on commit 444b2db

Please sign in to comment.