reactive_graph_generator_documentation/
fs.rs1use crate::error::DocumentationGenerationError;
2use reactive_graph_graph::NamespacedTypeGetter;
3use reactive_graph_graph::TypeDefinition;
4use std::path::PathBuf;
5use workspace_root::get_workspace_root;
6
7pub const DOCS_DIRECTORY: &str = "docs";
8
9pub fn get_workspace_root_docs_path() -> PathBuf {
10 get_workspace_root().join(DOCS_DIRECTORY)
11}
12
13pub fn create_and_get_documentation_path<T: Into<TypeDefinition>>(base_path: &PathBuf, ty: T) -> Result<PathBuf, DocumentationGenerationError> {
14 let type_definition = ty.into();
15 let parent_dir = base_path
16 .join(type_definition.path().relative_path());
19 if !parent_dir.exists() {
20 std::fs::create_dir_all(parent_dir.clone()).map_err(|_| DocumentationGenerationError::PathError(parent_dir.clone()))?;
21 }
22 Ok(parent_dir.join(format!("{}.md", type_definition.namespaced_type.type_name)))
23}