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:
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

View file

@ -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() {

View file

@ -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")?;

View file

@ -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();