Skip to content

Commit

Permalink
refactor(utils): improve directories analyzer
Browse files Browse the repository at this point in the history
- move `src_analyzer.rs` and `dist_analyzer.rs` to `analyzer` module.
- improve their documentation.
- add  more test-cases.
  • Loading branch information
hulxv committed Sep 18, 2024
1 parent c701d04 commit 827cafa
Show file tree
Hide file tree
Showing 14 changed files with 672 additions and 262 deletions.
6 changes: 5 additions & 1 deletion crates/metassr-build/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use hydrator::Hydrator;

use metassr_bundler::WebBundler;
use metassr_utils::{
cache_dir::CacheDir, src_analyzer::special_entries, src_analyzer::SourceDir, traits::AnalyzeDir,
analyzer::{
src_dir::{special_entries, SourceDir},
DirectoryAnalyzer,
},
cache_dir::CacheDir,
};
use std::{
collections::HashMap,
Expand Down
4 changes: 2 additions & 2 deletions crates/metassr-build/src/server/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use metassr_utils::{
analyzer::dist_dir::{DistDirContainer, PageEntry},
cache_dir::CacheDir,
dist_analyzer::{DistDirContainer, PageEntry},
};
use serde::{Deserialize, Serialize};
use serde_json::to_string_pretty;
Expand Down Expand Up @@ -121,7 +121,7 @@ impl ManifestGenerator {
pub fn generate<H: AsRef<OsStr> + ?Sized>(&self, head: &H) -> Result<Manifest> {
let global = GlobalEntry::new(head, &self.cache.dir_path())?;
let mut manifest = Manifest::new(global);

for (path, &id) in self.targets.iter() {
let route = match path
.strip_prefix(self.cache.dir_path().join("pages"))?
Expand Down
8 changes: 5 additions & 3 deletions crates/metassr-build/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ use manifest::ManifestGenerator;

use metassr_bundler::WebBundler;
use metassr_utils::{
analyzer::{
dist_dir::DistDir,
src_dir::{special_entries, SourceDir},
DirectoryAnalyzer,
},
cache_dir::CacheDir,
dist_analyzer::DistDir,
src_analyzer::{special_entries, SourceDir},
traits::AnalyzeDir,
};
use pages_generator::PagesGenerator;
use renderer::head::HeadRenderer;
Expand Down
6 changes: 4 additions & 2 deletions crates/metassr-build/src/server/pages_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use std::{

use anyhow::{anyhow, Result};
use metassr_utils::{
analyzer::{
dist_dir::{DistDir, DistDirContainer},
DirectoryAnalyzer,
},
cache_dir::CacheDir,
dist_analyzer::{DistDir, DistDirContainer},
traits::AnalyzeDir,
};

use crate::traits::Exec;
Expand Down
2 changes: 1 addition & 1 deletion crates/metassr-build/src/server/renderer/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use html_generator::{
html_props::HtmlProps,
template::HtmlTemplate,
};
use metassr_utils::dist_analyzer::PageEntry;
use metassr_utils::analyzer::dist_dir::PageEntry;

pub struct HtmlRenderer<'a> {
head: String,
Expand Down
2 changes: 1 addition & 1 deletion crates/metassr-build/src/server/renderer/page.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ffi::OsStr;

use anyhow::Result;
use metassr_utils::{cache_dir::CacheDir, dist_analyzer::PageEntry};
use metassr_utils::{analyzer::dist_dir::PageEntry, cache_dir::CacheDir};

use crate::{
server::{manifest::Manifest, render_exec::RenderExec},
Expand Down
2 changes: 1 addition & 1 deletion crates/metassr-build/src/server/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use anyhow::Result;
use metassr_utils::{cache_dir::CacheDir, src_analyzer::PagesEntriesType};
use metassr_utils::{analyzer::src_dir::PagesEntriesType, cache_dir::CacheDir};

use crate::{traits::Generate, utils::setup_page_path};

Expand Down
6 changes: 3 additions & 3 deletions crates/metassr-server/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use axum::{
routing::get,
};
use metassr_build::server::renderer::page::PageRenderer;
use metassr_utils::{
dist_analyzer::{DistDir, PageEntry},
traits::AnalyzeDir,
use metassr_utils::analyzer::{
dist_dir::{DistDir, PageEntry},
DirectoryAnalyzer,
};
use std::{collections::HashMap, fs::read_to_string, path::PathBuf};

Expand Down
Loading

0 comments on commit 827cafa

Please sign in to comment.