Moonwave Documentation Ecosystem

repository·master·Indexed 42 days ago

https://github.com/evaera/moonwave

A documentation ecosystem for Lua that automates the conversion of source code comments into structured JSON and visually rendered websites via Docusaurus. It includes a Rust-based extractor, a Docusaurus plugin, and a CLI for scaffolding and automation.

Tokens
18.2K
Snippets
77
Records
99
Agent score
53%

What's inside Moonwave

  1. What is Moonwave

    master

    Moonwave is a command line tool designed to generate documentation from comments within Lua source code. It consists of three primary components:

    • Moonwave Extractor: A Rust-based program that parses Lua files and extracts documentation into JSON format.
    • Docusaurus Plugin: A React-based plugin for Docusaurus that visually renders the extracted JSON documentation.
    • Moonwave CLI: A unified interface that abstracts the extractor and the Docusaurus plugin, allowing users to manage the entire documentation workflow without interacting with the underlying components directly.
  2. Overview of the Moonwave CLI

    master
    The Moonwave CLI is a scaffolding and automation tool designed to simplify the setup of a Moonwave-powered documentation site. It automates the generation of a Docusaurus project and handles the extraction of doc comments, allowing developers to get started without needing deep prior knowledge of the underlying technologies.
  3. Define a Moonwave class using @class

    master

    In Moonwave, all documented entities (types, properties, or functions) must belong to a "class". A class is conceptually any Lua table containing fields or functions (e.g., a service, an OOP class, or a plain table). Each class generates its own dedicated API page.

    You can define a class using either multi-line comments with an equals sign or single-line triple-dash comments. Both methods are equivalent.

    --[=[
    	@class MyFirstClass
    
    	This is my first class.
    ]=]
    local MyFirstClass = {}
    MyFirstClass.__index = MyFirstClass

    OR

    --- @class MyFirstClass
    ---
    --- This is my first class.
    local MyFirstClass = {}
    MyFirstClass.__index = MyFirstClass
  4. Define classes with @class and @within

    master

    Use @class <name> to denote a class. It is recommended to have one per .lua file.

    For any doc comment that is not an @class (such as properties, functions, or types), you must include the @within <class name> tag to specify which class the item belongs to. Failing to include @within for non-class doc comments will result in an error.

    --- @class MyClass
    --- A sample class.
    local MyClass = {}
    MyClass.__index = MyClass
    
    --- @prop name string
    --- @within MyClass
    --- A string referring to the name
  5. Create Nested API Sections

    master

    Moonwave supports hierarchical organization for API documentation through nested sections. You can nest sections within [[classOrder.items]] to create a multi-level sidebar.

    Nested sections inherit the ability to use classes, tag, and collapsed settings. You can control the collapsed state at any level of the hierarchy.

    [[classOrder]]
    section = "Parent Section"
    
    [[classOrder.items]]
    section = "Child Section 1"
    classes = ["Class1", "Class2"]
    
    [[classOrder.items]]
    section = "Child Section 2"
    tag = "childTag"
    
    [[classOrder.items.items]]
    section = "Grandchild Section"
    classes = ["Class4", "Class5"]
  6. Key features of Moonwave

    master

    Moonwave provides several features for Lua documentation workflows:

    • Low Configuration: Generate a documentation website with minimal setup by using specific doc comments in your Lua code.
    • Validation: Includes an extensive validation system to catch errors or inconsistencies in your documentation.
    • JSON Output: Extracts documentation into JSON, making it compatible with various external tools.
    • Readable Comment Format: Uses a simple doc comment format designed to be easily readable within the source code.
  7. Using generics and type variables

    master

    Generics are defined using angled brackets <>. While Moonwave generally follows the Luau Typechecking Guide, documentation types can be more flexible for clarity.

    • Standard Generics: Use <T> to define a type variable: <T>(arg: T) -> (T, T).
    • Type Variable Convention: Use single capital letters like T or U to indicate that two types must be the same. For example, (arg: T) -> T indicates that the return type is exactly the same as the input type, whereas (arg: any) -> any would allow the return type to differ from the input.
    • Documentation Flexibility: Since docs are for reading, you can omit the declaration of <T> if it makes the type clearer, such as (arg: T) -> (T, T).
    <T>(arg: T) -> (T, T)
    () -> Promise<T>
    (arg: T) -> T
  8. Run the Moonwave website in local development mode

    master

    Start a local development server using yarn start. This command will automatically open a browser window and supports live reloading, meaning most changes to the site will be reflected immediately without a server restart.

    $ yarn start
  9. Publish your website with Moonwave

    master

    You can build and publish your documentation website using the Moonwave CLI.

    If you are using Git and GitHub Pages, you can build and publish in a single step:

    moonwave build --publish

    Otherwise, run moonwave build to generate the site locally. The output will be placed in a build directory in your project root. You can customize the output location using the --out-dir [path] flag.

    Note: Add the build folder to your .gitignore to prevent committing build artifacts.

    moonwave build --publish
    # or
    moonwave build --out-dir ./custom-build-path