use std::path::Path;
pub(crate) fn template_files(dir: &Path) -> std::io::Result<Vec<String>> {
let mut files = Vec::new();
collect(dir, "", &mut files)?;
files.sort_unstable();
Ok(files)
}
fn collect(dir: &Path, prefix: &str, files: &mut Vec<String>) -> std::io::Result<()> {
for entry in std::fs::read_dir(dir)? {
let entry = entry?;
let name = entry.file_name();
let Some(name) = name.to_str() else {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!("non-UTF-8 template file name in {}", dir.display()),
));
};
if name.starts_with('.') {
continue;
}
let relative = format!("{prefix}{name}");
if entry.file_type()?.is_dir() {
collect(&entry.path(), &format!("{relative}/"), files)?;
} else {
files.push(relative);
}
}
Ok(())
}