-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from salvo-rs/add_readme
Add readme
- Loading branch information
Showing
8 changed files
with
1,130 additions
and
141 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# {{introduction}} | ||
{{introduction_text}} | ||
{{#if is_sqlite}} | ||
{{/if}} | ||
``` shell | ||
//{{run_the_project}} | ||
cargo run | ||
//{{run_the_tests}} | ||
cargo test | ||
``` | ||
{{#if need_db_conn}} | ||
# {{tip_title}} | ||
- {{password_tip}} | ||
{{# if is_sea_orm_or_sqlx}} | ||
- {{config_tip}} | ||
{{/if}} | ||
# {{orm_title}} | ||
{{#if is_sqlx}} | ||
{{sqlx_website}} | ||
## sqlx_cli | ||
{{sqlx_cli}} https://github.com/launchbadge/sqlx/blob/main/sqlx-cli/README.md | ||
## {{initialization}} | ||
{{#if is_sqlite}} | ||
{{seleted_sqlite}} | ||
{{else}} | ||
- {{initialization_sqlx_cli_not_sqlite}} | ||
{{/if}} | ||
{{/if}} | ||
{{#if is_sea_orm}} | ||
{{sea_orm_website}} | ||
## sea_orm_cli | ||
{{sea_orm_cli_website}} | ||
## {{initialization}} | ||
{{/if}} | ||
{{#if is_sea_orm}} | ||
{{#if is_sqlite}} | ||
{{seleted_sqlite}} | ||
{{else}} | ||
- {{initialization_seaorm_cli_not_sqlite}} | ||
{{/if}} | ||
{{/if}} | ||
{{#if is_diesel}} | ||
{{diesel_website}} | ||
## diesel_cli | ||
{{diesel_cli_website}} | ||
## {{initialization}} | ||
{{#if is_sqlite}} | ||
{{seleted_sqlite}} | ||
{{else}} | ||
- {{initialization_diesel_cli_not_sqlite}} | ||
{{/if}} | ||
{{/if}} | ||
{{#if is_rbatis}} | ||
{{rbatis_website}} | ||
## {{initialization}} | ||
{{#if is_sqlite}} | ||
{{seleted_sqlite}} | ||
{{else}} | ||
- {{initialization_rbatis_cli_not_sqlite}} | ||
{{/if}} | ||
{{/if}} | ||
{{#if is_mongodb}} | ||
{{mongodb_website}} | ||
## {{initialization}} | ||
- {{mongodb_usage_import_user_data}} | ||
{{/if}} | ||
{{/if}} | ||
# {{project_dir_description}} | ||
{{directory_contents}} | ||
# {{about_salvo}} | ||
{{about_salvo_text}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use anyhow::anyhow; | ||
use anyhow::Result; | ||
use once_cell::sync::Lazy; | ||
use rust_i18n::t; | ||
use std::collections::HashMap; | ||
use std::fmt::Write; | ||
use std::fs::{self}; | ||
use std::path::Path; | ||
use walkdir::WalkDir; | ||
|
||
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("migrations".to_string(), t!("migrations")); | ||
m.insert("migration".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(), 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/models".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 | ||
}); | ||
|
||
pub fn write_directory_contents_to_markdown(output_file: &Path) -> Result<String> { | ||
let mut output = String::new(); | ||
let project_name = output_file | ||
.parent() | ||
.ok_or(anyhow!("Parent directory not found."))? | ||
.file_name() | ||
.ok_or(anyhow!("Project name not found."))? | ||
.to_string_lossy(); | ||
|
||
writeln!(output, "# {}", project_name)?; | ||
|
||
for entry in WalkDir::new( | ||
output_file | ||
.parent() | ||
.ok_or(anyhow!("Parent directory not found."))?, | ||
) | ||
.into_iter() | ||
.filter_map(|e| e.ok()) | ||
.filter(|e| e.file_name().to_string_lossy() != "README.md") | ||
{ | ||
let depth = entry.depth(); | ||
let indent = " ".repeat(depth.saturating_sub(1)); | ||
let path = entry.path(); | ||
let metadata = fs::metadata(path)?; | ||
if let Some(file_name) = path.file_name() { | ||
let file_name_str = file_name.to_string_lossy(); | ||
let full_path = path | ||
.strip_prefix( | ||
output_file | ||
.parent() | ||
.ok_or(anyhow!("Parent directory not found."))?, | ||
)? | ||
.to_string_lossy() | ||
.into_owned(); | ||
let description = PATH_DESCRIPTIONS.get(&*full_path); | ||
let description = description | ||
.map(|s| format!(" ({})", s)) | ||
.unwrap_or_default(); | ||
if metadata.is_dir() { | ||
writeln!( | ||
output, | ||
"{}- **{}:** {} {}", | ||
indent, | ||
t!("dir"), | ||
file_name_str, | ||
description | ||
)?; | ||
} else { | ||
writeln!( | ||
output, | ||
"{}- *{}:* {} {}", | ||
indent, | ||
t!("file"), | ||
file_name_str, | ||
description | ||
)?; | ||
} | ||
} | ||
} | ||
Ok(output) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters