use std::fs;
use std::path::Path;
use console::style;
use crate::ui;
pub fn ensure_dir(path: &Path) -> Result<(), String> {
fs::create_dir_all(path).map_err(|e| format!("failed to create '{}': {e}", path.display()))
}
pub fn write_file(path: &Path, content: &str) -> Result<(), String> {
if let Some(parent) = path.parent() {
if !parent.as_os_str().is_empty() {
ensure_dir(parent)?;
}
}
fs::write(path, content).map_err(|e| format!("failed to write '{}': {e}", path.display()))
}
pub fn write_template(
path: &Path,
template: &str,
replacements: &[(&str, &str)],
) -> Result<(), String> {
let mut content = template.to_string();
for (placeholder, value) in replacements {
content = content.replace(placeholder, value);
}
write_file(path, &content)
}
pub fn scaffold_success(name: &str, path: &Path, next_steps: &[&str]) {
let _ = name;
eprintln!(
"\n{} created {}",
ui::ok(),
style(format!("{}/", path.display())).cyan().bold()
);
eprintln!();
eprintln!("{}", style("Next steps:").dim());
for step in next_steps {
eprintln!(" {step}");
}
}