@hrefcl/apidoc - v4.0.5
    Preparing search index...

    Class default

    Documentation output writer and asset bundler

    The Writer class is responsible for:

    • Generating HTML documentation files from parsed API data
    • Bundling JavaScript and CSS assets using esbuild
    • Managing output directory structure and file copying
    • Handling template processing and content generation
    • Cache busting for static assets
    const writer = new Writer(apiData, appContext);
    await writer.write();
    console.log('Documentation generated successfully');
    const writer = new Writer(apiData, appContext, 'v=1.2.0');
    await writer.write();

    4.0.0

    Index

    Constructors

    • Creates a new Writer instance for generating documentation output

      Parameters

      • api: any

        Parsed API data and project information from the core parser

      • app: any

        Application context containing shared instances and configuration

      • cacheBustingQueryParam: string = ...

        Cache-busting query parameter for static assets. Defaults to current timestamp to ensure fresh assets on each build.

      Returns default

      const writer = new Writer(
      { data: '[]', project: '{}' },
      { log: logger, options: { dest: './docs' } }
      );
      const writer = new Writer(apiData, appContext, 'v=2.1.0');
      

    Properties

    api: any
    log: any
    opt: any
    cacheBustingQueryParam: string
    fs: __module
    path: PlatformPath
    authProcessor: any

    Methods

    • Initialize authentication system if login configuration is present

      Returns void

    • Write output files based on configuration.

      If dry run mode is enabled, no files are created, and the method simply logs the operation and resolves the promise. Otherwise, it creates the necessary files either as a single file or multiple output files based on the specified options.

      Returns Promise<any>

      Promise that resolves when file writing is complete.

      Writer

    • Attempt to locate the specified asset file path and retrieve its resolved path. If the file cannot be resolved, an error is logged.

      Parameters

      • assetPath: any

        Relative file path of the asset to find.

      Returns string

      Return the resolved file path

      Writer

    • Generate Markdown documentation files

      Returns Promise<void>

      Writer

    • Generate OpenAPI 3.0 specification file (swagger.json)

      Returns void

      Writer

    • Create output files in the destination directory

      Performs the following tasks:

      • Creates the destination directory where the output files will be generated.
      • Copies a template index.html file into the destination directory.
      • Creates an assets folder within the destination directory.
      • Optionally saves a parsed API file as api-data.json into the assets folder if the writeJson option is enabled.
      • Generates OpenAPI specification if requested
      • Executes a bundler operation for the assets folder.

      Returns Promise<any>

      Resolves as the bundling operation assets folder.

      Writer

    • Run the bundler to create a bundled JS file using esbuild.

      Parameters

      • outputPath: any

        Path where the bundler will output

      Returns Promise<unknown>

      Resolves with the output path upon successful bundling, or rejects with an error if the bundling process fails.

      Writer

    • Read image files from a directory, then convert them to Base64 strings and map them to tokens.

      • The tokens are used as keys to represent the Base64-encoded strings of the images.
      • Images are sourced from the "img" subdirectory of the specified template path.
      • Only valid files within the directory are processed. And the MIME type is determined based on the file extension.

      Returns {}

      A mapping of token keys to Base64-encoded image strings, where each key is in the format "IMAGE_LINK_TOKEN_".

      Writer

    • Process custom markdown settings from apidoc.json

      Parameters

      • projectInfo: any

        Project configuration from apidoc.json

      Returns Record<string, any>

      Object containing processed markdown content for each group

    • Generate and return the content of the index.html file for the API documentation.

      Replaces predefined tokens with dynamic values such as the project title, description, and cache-busting query parameters.

      Returns string

      Processed HTML content for the index page of the API documentation.

      Writer

    • Create a self-contained single HTML file by bundling CSS and JS into the file

      • modify the main index HTML content to embed CSS, JS directly
      • remove external links to assets
      • save the final file to the destination directory

      Returns Promise<void>

      A promise that resolves once the single HTML file is successfully created.

      Writer

    • Write a JSON file with the provided data.

      Parameters

      • dest: any

        Destination file path where the file will be written.

      • data: any

        File data

      Returns void

      Writer

    • Write a JS file with the provided data.

      Parameters

      • dest: any

        Destination file path where the file will be written.

      • data: any

        File data

      Returns void

      Writer

    • Copy all highlight.js themes for dynamic theme loading

      Parameters

      • assetsPath: any

        Path to the assets directory

      Returns void

      Writer

    • Create a directory

      Parameters

      • dir: any

        Path of the directory to create

      Returns void

      Writer