From 587a1c796d1caed04cdb8f0bc48a6615e80e718c Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Fri, 24 Mar 2023 12:51:37 +0100 Subject: [PATCH] Finish gitbook gen command --- .justfile | 17 ++++++++++++++++- packages/cli/src/cli.rs | 8 ++++---- .../cli/src/gen/{wiki_dir.rs => gitbook_dir.rs} | 16 +++++++++++----- packages/cli/src/gen/mod.rs | 4 ++-- 4 files changed, 33 insertions(+), 12 deletions(-) rename packages/cli/src/gen/{wiki_dir.rs => gitbook_dir.rs} (89%) diff --git a/.justfile b/.justfile index f88b306..574d95e 100644 --- a/.justfile +++ b/.justfile @@ -6,6 +6,21 @@ test: test-cli: cargo test --package lune-cli +# Generate gitbook directory +generate-gitbook: + rm -rf ./gitbook + + mkdir gitbook + mkdir gitbook/docs + + cp -R docs gitbook + cp README.md gitbook/README.md + cp .gitbook.yaml gitbook/.gitbook.yaml + + rm -rf gitbook/docs/typedefs + + cargo run -- --generate-gitbook-dir + # Publish gitbook directory to gitbook branch publish-gitbook: - npx push-dir --dir=docs --branch=gitbook + npx push-dir --dir=gitbook --branch=gitbook diff --git a/packages/cli/src/cli.rs b/packages/cli/src/cli.rs index 6083eab..29d4100 100644 --- a/packages/cli/src/cli.rs +++ b/packages/cli/src/cli.rs @@ -12,9 +12,9 @@ use tokio::{ use crate::{ gen::{ - generate_docs_json_from_definitions, generate_luau_defs_from_definitions, - generate_selene_defs_from_definitions, generate_typedefs_file_from_dir, - generate_wiki_dir_from_definitions, + generate_docs_json_from_definitions, generate_gitbook_dir_from_definitions, + generate_luau_defs_from_definitions, generate_selene_defs_from_definitions, + generate_typedefs_file_from_dir, }, utils::{ files::{discover_script_file_path_including_lune_dirs, strip_shebang}, @@ -143,7 +143,7 @@ impl Cli { .await?; } if self.generate_gitbook_dir { - generate_wiki_dir_from_definitions(&definitions).await?; + generate_gitbook_dir_from_definitions(&definitions).await?; } } if self.script_path.is_none() { diff --git a/packages/cli/src/gen/wiki_dir.rs b/packages/cli/src/gen/gitbook_dir.rs similarity index 89% rename from packages/cli/src/gen/wiki_dir.rs rename to packages/cli/src/gen/gitbook_dir.rs index b3ce260..d8cad39 100644 --- a/packages/cli/src/gen/wiki_dir.rs +++ b/packages/cli/src/gen/gitbook_dir.rs @@ -22,13 +22,19 @@ pub async fn generate_from_type_definitions(contents: &str) -> Result<()> { let tree = DefinitionsTree::from_type_definitions(contents)?; let mut dirs_to_write = Vec::new(); let mut files_to_write = Vec::new(); - // Create the wiki dir at the repo root + // Create the gitbook dir at the repo root let path_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("../../") .canonicalize() .unwrap(); - let path_wiki_dir = path_root.join("wiki"); - dirs_to_write.push(path_wiki_dir.clone()); + let path_gitbook_dir = path_root.join("gitbook"); + let path_gitbook_docs_dir = path_gitbook_dir.join("docs"); + let path_gitbook_pages_dir = path_gitbook_docs_dir.join("pages"); + let path_gitbook_api_dir = path_gitbook_pages_dir.join("api"); + dirs_to_write.push(path_gitbook_dir.clone()); + dirs_to_write.push(path_gitbook_docs_dir.clone()); + dirs_to_write.push(path_gitbook_pages_dir.clone()); + dirs_to_write.push(path_gitbook_api_dir.clone()); // Sort doc items into subcategories based on globals let mut api_reference = HashMap::new(); let mut no_category = Vec::new(); @@ -67,8 +73,8 @@ pub async fn generate_from_type_definitions(contents: &str) -> Result<()> { ); // Generate files for all subcategories for (category_name, category_item) in api_reference { - let path = path_wiki_dir - .join(format!("API Reference - {category_name}")) + let path = path_gitbook_api_dir + .join(category_name.to_ascii_lowercase()) .with_extension("md"); let mut contents = String::new(); write!(contents, "{GENERATED_COMMENT_TAG}\n\n")?; diff --git a/packages/cli/src/gen/mod.rs b/packages/cli/src/gen/mod.rs index 4758374..e3cf9a9 100644 --- a/packages/cli/src/gen/mod.rs +++ b/packages/cli/src/gen/mod.rs @@ -2,16 +2,16 @@ use include_dir::Dir; use regex::Regex; mod docs_file; +mod gitbook_dir; mod luau_defs; mod selene_defs; -mod wiki_dir; pub mod definitions; pub use docs_file::generate_from_type_definitions as generate_docs_json_from_definitions; +pub use gitbook_dir::generate_from_type_definitions as generate_gitbook_dir_from_definitions; pub use luau_defs::generate_from_type_definitions as generate_luau_defs_from_definitions; pub use selene_defs::generate_from_type_definitions as generate_selene_defs_from_definitions; -pub use wiki_dir::generate_from_type_definitions as generate_wiki_dir_from_definitions; pub fn generate_typedefs_file_from_dir(dir: &Dir<'_>) -> String { let mut result = String::new();