Finish gitbook gen command

This commit is contained in:
Filip Tibell 2023-03-24 12:51:37 +01:00
parent 4b014b7b61
commit 587a1c796d
No known key found for this signature in database
4 changed files with 33 additions and 12 deletions

View file

@ -6,6 +6,21 @@ test:
test-cli: test-cli:
cargo test --package lune-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 directory to gitbook branch
publish-gitbook: publish-gitbook:
npx push-dir --dir=docs --branch=gitbook npx push-dir --dir=gitbook --branch=gitbook

View file

@ -12,9 +12,9 @@ use tokio::{
use crate::{ use crate::{
gen::{ gen::{
generate_docs_json_from_definitions, generate_luau_defs_from_definitions, generate_docs_json_from_definitions, generate_gitbook_dir_from_definitions,
generate_selene_defs_from_definitions, generate_typedefs_file_from_dir, generate_luau_defs_from_definitions, generate_selene_defs_from_definitions,
generate_wiki_dir_from_definitions, generate_typedefs_file_from_dir,
}, },
utils::{ utils::{
files::{discover_script_file_path_including_lune_dirs, strip_shebang}, files::{discover_script_file_path_including_lune_dirs, strip_shebang},
@ -143,7 +143,7 @@ impl Cli {
.await?; .await?;
} }
if self.generate_gitbook_dir { 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() { if self.script_path.is_none() {

View file

@ -22,13 +22,19 @@ pub async fn generate_from_type_definitions(contents: &str) -> Result<()> {
let tree = DefinitionsTree::from_type_definitions(contents)?; let tree = DefinitionsTree::from_type_definitions(contents)?;
let mut dirs_to_write = Vec::new(); let mut dirs_to_write = Vec::new();
let mut files_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")) let path_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../") .join("../../")
.canonicalize() .canonicalize()
.unwrap(); .unwrap();
let path_wiki_dir = path_root.join("wiki"); let path_gitbook_dir = path_root.join("gitbook");
dirs_to_write.push(path_wiki_dir.clone()); 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 // Sort doc items into subcategories based on globals
let mut api_reference = HashMap::new(); let mut api_reference = HashMap::new();
let mut no_category = Vec::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 // Generate files for all subcategories
for (category_name, category_item) in api_reference { for (category_name, category_item) in api_reference {
let path = path_wiki_dir let path = path_gitbook_api_dir
.join(format!("API Reference - {category_name}")) .join(category_name.to_ascii_lowercase())
.with_extension("md"); .with_extension("md");
let mut contents = String::new(); let mut contents = String::new();
write!(contents, "{GENERATED_COMMENT_TAG}\n\n")?; write!(contents, "{GENERATED_COMMENT_TAG}\n\n")?;

View file

@ -2,16 +2,16 @@ use include_dir::Dir;
use regex::Regex; use regex::Regex;
mod docs_file; mod docs_file;
mod gitbook_dir;
mod luau_defs; mod luau_defs;
mod selene_defs; mod selene_defs;
mod wiki_dir;
pub mod definitions; pub mod definitions;
pub use docs_file::generate_from_type_definitions as generate_docs_json_from_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 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 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 { pub fn generate_typedefs_file_from_dir(dir: &Dir<'_>) -> String {
let mut result = String::new(); let mut result = String::new();