Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fankaiLiu committed Dec 22, 2023
1 parent 40b6915 commit d883ad3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/utils/create_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ pub fn write_project_file(
}
templates.append(&mut db_templates);
}
templates.append(vec![("src/README.md", include_str!("../template/README.md"))].as_mut());
templates.append(vec![("README.md", include_str!("../template/README.md"))].as_mut());

let directory_contents = write_directory_contents_to_markdown(&project_path.join("README.md"))?;
data["directory_contents"] = handlebars::JsonValue::String(directory_contents);
Expand Down
46 changes: 22 additions & 24 deletions src/utils/directory2md.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,32 @@ use std::fs::{self};
use std::path::Path;
use walkdir::WalkDir;

// 使用 once_cell 创建静态的 HashMap,存储全路径和描述
static PATH_DESCRIPTIONS: Lazy<HashMap<String, String>> = Lazy::new(|| {
let mut m = HashMap::new();
m.insert("/Cargo.toml".to_string(), t!("cargo_toml"));
m.insert("/.env".to_string(), t!("dot_env"));
m.insert("/config/config.toml".to_string(), t!("config_config_toml"));
m.insert("Cargo.toml".to_string(), t!("cargo_toml"));
m.insert(".env".to_string(), t!("dot_env"));
m.insert("config/config.toml".to_string(), t!("config_config_toml"));

m.insert("/migrations".to_string(), t!("migrations"));
m.insert("/config".to_string(), t!("config"));
m.insert("/config/certs".to_string(), t!("config_certs"));
m.insert("/templates".to_string(), t!("templates"));
m.insert("/data".to_string(), t!("data"));
m.insert("/assets".to_string(), t!("assets"));
m.insert("/src".to_string(), t!("src"));
m.insert("migrations".to_string(), t!("migrations"));
m.insert("config".to_string(), t!("config"));
m.insert("config/certs".to_string(), t!("config_certs"));
m.insert("templates".to_string(), t!("templates"));
m.insert("data".to_string(), t!("data"));
m.insert("assets".to_string(), t!("assets"));
m.insert("src".to_string(), t!("src"));
m.insert(
"/src/app_response.rs".to_string(),
"src/app_response.rs".to_string(),
t!("src_app_response_rs"),
);
m.insert("/src/routers".to_string(), t!("src_routers"));
m.insert("/src/middleware".to_string(), t!("src_middleware"));
m.insert("/src/utils".to_string(), t!("src_utils"));
m.insert("/src/dtos".to_string(), t!("src_dtos"));
m.insert("/src/entities".to_string(), t!("src_entities"));
m.insert("/src/services".to_string(), t!("src_services"));
m.insert("/src/config.rs".to_string(), t!("src_config_rs"));
m.insert("/src/app_error.rs".to_string(), t!("src_app_error_rs"));
m.insert("/src/main.rs".to_string(), t!("src_main_rs"));
m.insert("src/routers".to_string(), t!("src_routers"));
m.insert("src/middleware".to_string(), t!("src_middleware"));
m.insert("src/utils".to_string(), t!("src_utils"));
m.insert("src/dtos".to_string(), t!("src_dtos"));
m.insert("src/entities".to_string(), t!("src_entities"));
m.insert("src/services".to_string(), t!("src_services"));
m.insert("src/config.rs".to_string(), t!("src_config_rs"));
m.insert("src/app_error.rs".to_string(), t!("src_app_error_rs"));
m.insert("src/main.rs".to_string(), t!("src_main_rs"));
m
});

Expand Down Expand Up @@ -72,7 +71,6 @@ pub fn write_directory_contents_to_markdown(output_file: &Path) -> Result<String
)?
.to_string_lossy()
.into_owned();
dbg!(&full_path);
let description = PATH_DESCRIPTIONS.get(&*full_path);
let description = description
.map(|s| format!(" ({})", s))
Expand All @@ -81,13 +79,13 @@ pub fn write_directory_contents_to_markdown(output_file: &Path) -> Result<String
writeln!(
output,
"{}- **{}:** {} {}",
indent, "dir", file_name_str, description
indent, t!("dir"), file_name_str, description
)?;
} else {
writeln!(
output,
"{}- *{}:* {} {}",
indent, "file", file_name_str, description
indent, t!("file"), file_name_str, description
)?;
}
}
Expand Down

0 comments on commit d883ad3

Please sign in to comment.