init: archlens — architecture diagram generator
Some checks failed
CI / Check / Test (push) Failing after 1m24s
Some checks failed
CI / Check / Test (push) Failing after 1m24s
Hex arch + DDD, tree-sitter parsing, Mermaid/ASCII output. Supports Rust + Python. 92 tests. CI, diff, --check for staleness detection.
This commit is contained in:
52
crates/adapters/file-writer/src/file_output_writer.rs
Normal file
52
crates/adapters/file-writer/src/file_output_writer.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use archlens_domain::{DomainError, RenderOutput, ports::OutputWriter};
|
||||
|
||||
pub struct FileOutputWriter {
|
||||
output_path: OutputPath,
|
||||
}
|
||||
|
||||
enum OutputPath {
|
||||
Directory(PathBuf),
|
||||
File(PathBuf),
|
||||
}
|
||||
|
||||
impl FileOutputWriter {
|
||||
pub fn new(output_dir: PathBuf) -> Self {
|
||||
Self {
|
||||
output_path: OutputPath::Directory(output_dir),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn single_file(path: PathBuf) -> Self {
|
||||
Self {
|
||||
output_path: OutputPath::File(path),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OutputWriter for FileOutputWriter {
|
||||
fn write(&self, output: &RenderOutput) -> Result<(), DomainError> {
|
||||
match &self.output_path {
|
||||
OutputPath::File(path) => {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent).map_err(|e| DomainError::IoError(e.to_string()))?;
|
||||
}
|
||||
let content = output.files().first().map(|f| f.content()).unwrap_or("");
|
||||
fs::write(path, content).map_err(|e| DomainError::IoError(e.to_string()))?;
|
||||
}
|
||||
OutputPath::Directory(dir) => {
|
||||
fs::create_dir_all(dir).map_err(|e| DomainError::IoError(e.to_string()))?;
|
||||
|
||||
for file in output.files() {
|
||||
let path = dir.join(file.name());
|
||||
fs::write(&path, file.content())
|
||||
.map_err(|e| DomainError::IoError(e.to_string()))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
3
crates/adapters/file-writer/src/lib.rs
Normal file
3
crates/adapters/file-writer/src/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
mod file_output_writer;
|
||||
|
||||
pub use file_output_writer::FileOutputWriter;
|
||||
Reference in New Issue
Block a user