lune/packages/cli/src/gen/mod.rs

39 lines
1.2 KiB
Rust
Raw Normal View History

use std::collections::HashMap;
use anyhow::Result;
2023-03-24 11:38:27 +00:00
use include_dir::Dir;
use self::definitions::DefinitionsTree;
2023-03-24 11:51:37 +00:00
mod gitbook_dir;
mod typedef_files;
pub mod definitions;
2023-02-21 20:06:11 +00:00
pub async fn generate_gitbook_dir_from_definitions(dir: &Dir<'_>) -> Result<()> {
let definitions = read_typedefs_dir(dir)?;
gitbook_dir::generate_from_type_definitions(definitions).await
}
pub async fn generate_typedef_files_from_definitions(dir: &Dir<'_>) -> Result<()> {
let definitions = read_typedefs_dir(dir)?;
typedef_files::generate_from_type_definitions(definitions).await
}
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");
let typedef_contents = entry_file.contents_utf8().unwrap().to_string();
2023-03-24 11:38:27 +00: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
}
Ok(definitions)
2023-03-24 11:38:27 +00:00
}