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:
13
crates/adapters/file-writer/Cargo.toml
Normal file
13
crates/adapters/file-writer/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "archlens-file-writer"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
archlens-domain.workspace = true
|
||||
thiserror.workspace = true
|
||||
tracing.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile.workspace = true
|
||||
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;
|
||||
35
crates/adapters/file-writer/tests/file_writer_tests.rs
Normal file
35
crates/adapters/file-writer/tests/file_writer_tests.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use std::fs;
|
||||
|
||||
use archlens_domain::{RenderOutput, RenderedFile, ports::OutputWriter};
|
||||
use archlens_file_writer::FileOutputWriter;
|
||||
|
||||
#[test]
|
||||
fn writes_single_file_to_directory() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let writer = FileOutputWriter::new(dir.path().to_path_buf());
|
||||
|
||||
let file = RenderedFile::new("arch.mmd", "classDiagram").unwrap();
|
||||
let output = RenderOutput::single(file);
|
||||
|
||||
writer.write(&output).unwrap();
|
||||
|
||||
let content = fs::read_to_string(dir.path().join("arch.mmd")).unwrap();
|
||||
assert_eq!(content, "classDiagram");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn writes_multiple_files_to_directory() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let writer = FileOutputWriter::new(dir.path().to_path_buf());
|
||||
|
||||
let files = vec![
|
||||
RenderedFile::new("overview.mmd", "graph TD").unwrap(),
|
||||
RenderedFile::new("orders.mmd", "classDiagram").unwrap(),
|
||||
];
|
||||
let output = RenderOutput::new(files);
|
||||
|
||||
writer.write(&output).unwrap();
|
||||
|
||||
assert!(dir.path().join("overview.mmd").exists());
|
||||
assert!(dir.path().join("orders.mmd").exists());
|
||||
}
|
||||
Reference in New Issue
Block a user