Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fankaiLiu committed Dec 19, 2023
1 parent c039e4d commit 3700bb5
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ unicode-xid = "0.2.4"
rust-i18n = "2"
itertools = "0.12.0"
reqwest = "0.11.22"
tokio = { version = "1", features = ["full"] }
tokio = { version = "1", features = ["full"] }
walkdir = "2.4.0"
Empty file added src/template/README.md
Empty file.
2 changes: 2 additions & 0 deletions src/utils/create_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{
};

use super::{
directory2md::write_directory_contents_to_markdown,
get_selection::{get_user_selected, DbConnectionType, DbType, TemplateType, UserSelected},
print_util, restricted_names, warning,
};
Expand Down Expand Up @@ -471,6 +472,7 @@ pub fn write_project_file(
for (file_name, template) in &templates {
render_and_write_to_file(&handlebars, template, &data, project_path.join(file_name))?;
}
write_directory_contents_to_markdown(&project_path.join("README.md"))?;
Ok(())
}

Expand Down
32 changes: 32 additions & 0 deletions src/utils/directory2md.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::fs::{self, File};
use std::io::{Result, Write};
use std::path::Path;
use walkdir::WalkDir;

pub fn write_directory_contents_to_markdown(output_file: &Path) -> Result<()> {
let mut file = File::create(output_file)?;
writeln!(file, "# Directory Contents\n")?;
for entry in WalkDir::new(output_file.parent().unwrap())
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| e.path() != Path::new("./READEME.md"))
// Exclude the output file itself
{
let depth = entry.depth();
let indent = " ".repeat(depth.saturating_sub(1)); // Markdown uses 4 spaces for each list level
let path = entry.path();
let metadata = fs::metadata(path)?;
dbg!(&path);
if let Some(file_name) = path.file_name() {
let file_name = file_name.to_string_lossy();
if metadata.is_dir() {
// Use `**Dir:**` to denote directories
writeln!(file, "{}- **Dir:** {}", indent, file_name)?;
} else {
// Use `*File:*` to denote files
writeln!(file, "{}- *File:* {}", indent, file_name)?;
}
}
}
Ok(())
}
1 change: 1 addition & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod check_for_updates;
pub mod create_project;
mod directory2md;
pub mod get_selection;
mod print_util;
mod restricted_names;
Expand Down

0 comments on commit 3700bb5

Please sign in to comment.