2023-05-14 20:20:52 +01:00
|
|
|
use std::{collections::HashMap, path::PathBuf};
|
2023-05-01 11:18:15 +01:00
|
|
|
|
|
|
|
use anyhow::Result;
|
2023-03-24 11:38:27 +00:00
|
|
|
use include_dir::Dir;
|
|
|
|
|
2023-05-08 12:13:34 +01:00
|
|
|
use self::definitions::DefinitionsTree;
|
|
|
|
|
2023-03-24 11:51:37 +00:00
|
|
|
mod gitbook_dir;
|
2023-05-08 12:13:34 +01:00
|
|
|
mod typedef_files;
|
2023-01-27 00:36:06 +00:00
|
|
|
|
2023-02-22 09:53:00 +00:00
|
|
|
pub mod definitions;
|
2023-02-21 20:06:11 +00:00
|
|
|
|
2023-05-01 11:18:15 +01:00
|
|
|
pub async fn generate_gitbook_dir_from_definitions(dir: &Dir<'_>) -> Result<()> {
|
2023-05-08 12:13:34 +01:00
|
|
|
let definitions = read_typedefs_dir(dir)?;
|
|
|
|
gitbook_dir::generate_from_type_definitions(definitions).await
|
|
|
|
}
|
2023-05-01 11:18:15 +01:00
|
|
|
|
2023-05-14 20:20:52 +01:00
|
|
|
pub async fn generate_typedef_files_from_definitions(
|
|
|
|
dir: &Dir<'_>,
|
|
|
|
) -> Result<HashMap<String, PathBuf>> {
|
2023-05-08 12:13:34 +01:00
|
|
|
let definitions = read_typedefs_dir(dir)?;
|
|
|
|
typedef_files::generate_from_type_definitions(definitions).await
|
2023-05-01 11:18:15 +01:00
|
|
|
}
|
|
|
|
|
2023-05-08 12:13:34 +01:00
|
|
|
fn read_typedefs_dir(dir: &Dir<'_>) -> Result<HashMap<String, DefinitionsTree>> {
|
|
|
|
let mut definitions = HashMap::new();
|
2023-03-24 11:38:27 +00:00
|
|
|
|
|
|
|
for entry in dir.find("*.luau").unwrap() {
|
|
|
|
let entry_file = entry.as_file().unwrap();
|
|
|
|
let entry_name = entry_file.path().file_name().unwrap().to_string_lossy();
|
|
|
|
|
|
|
|
let typedef_name = entry_name.trim_end_matches(".luau");
|
2023-05-08 12:13:34 +01:00
|
|
|
let typedef_contents = entry_file.contents_utf8().unwrap().to_string();
|
2023-03-24 11:38:27 +00:00
|
|
|
|
2023-05-08 12:13:34 +01:00
|
|
|
let typedef_tree = DefinitionsTree::from_type_definitions(&typedef_contents)?;
|
|
|
|
definitions.insert(typedef_name.to_string(), typedef_tree);
|
2023-03-24 11:38:27 +00:00
|
|
|
}
|
|
|
|
|
2023-05-08 12:13:34 +01:00
|
|
|
Ok(definitions)
|
2023-03-24 11:38:27 +00:00
|
|
|
}
|