Skip to the content.

Configuration

The SimpleDocsExtractor uses a comprehensive configuration system to control how documentation is extracted, processed, and generated. This document covers all available configuration options.

Table of Contents

Main Configuration Object

The main configuration is defined by the SimpleDocExtractorConfig interface:

interface SimpleDocExtractorConfig {
  baseDir: string;
  generators?: {
    index?: IndexGeneratorConfig;
    documentation?: DocumentationGeneratorConfig;
  };
  targets: Target[];
  formatters?: TFormatter[];
}

Required Properties

Optional Properties

Target Configuration

Each target defines a set of files to process and where to output the generated documentation:

type Target = {
  globOptions: GlobOptions & { cwd: string; extensions: string | string[] };
  outDir: string;
  createIndexFile: boolean;
  generators?: {
    index?: IndexGeneratorConfig;
    documentation?: DocumentationGeneratorConfig;
  };
  extraction?: DocumentContentExtractorConfig;
};

Target Properties

Index Generator Configuration

Controls how index files are generated:

type IndexGeneratorConfig = {
  template: string;
  outDir?: string;
  searchAndReplace?: string;
  baseDir?: string;
  markdownLink?: boolean;
  filesHeading?: string;
  directoryHeading?: string;
  excerpt?: ExcerptExtractorConfig;
  lineCallback?: (fileNameEntry: string, lineNumber: number, excerpt?: string) => string;
  fileNameCallback?: (filePath: string) => string;
  flatten?: boolean;
  recursive?: boolean;
};

Index Generator Properties

Flatten Feature

The flatten option controls how nested directory structures are displayed in index files:

Documentation Generator Configuration

Controls how individual documentation files are generated:

type DocumentationGeneratorConfig = {
  template?: string;
  outDir?: string;
};

Documentation Generator Properties

Excerpt Configuration

Controls how excerpts are generated for index files:

type ExcerptExtractorConfig = {
  firstSentenceOnly?: boolean;
  addEllipsis?: boolean;
  length?: number;
};

Excerpt Properties

Extractor Plugins

Extractor plugins define how documentation content is extracted from source files. The system supports multiple extractor types:

Tag Extractor Plugin

Extracts content between HTML-like tags:

new TagExtractorPlugin({
  tag: "docs",
  searchAndReplace: "%content%",
  attributeFormat: "### **{value}**", // Optional
  defaultText: "No documentation available" // Optional
})

Properties:

Example usage in source code:

/**
 * <docs>
 * This is documentation content that will be extracted.
 * </docs>
 */

Regex Extractor Plugin

Extracts content using regular expressions:

new RegexExtractorPlugin({
  pattern: /\/\*\*([\s\S]*?)\*\//g,
  searchAndReplace: "%content%",
  defaultText: "No documentation available" // Optional
})

Properties:

Callback Extractor Plugin

Uses a custom callback function to extract content:

new CallbackExtractor({
  callback: (content: string) => {
    // Custom extraction logic
    return extractedContent;
  },
  searchAndReplace: "%content%",
  defaultText: "No documentation available" // Optional
})

Properties:

Formatters

Formatters process the extracted content before it’s written to files. Available formatters include:

RemoveMultiLineCommentAsterisks

Removes leading asterisks and whitespace from multi-line comments:

import { RemoveMultiLineCommentAsterisks } from "@/simple-docs-scraper/formatters/RemoveMultiLineCommentAsterisks.js";

// Usage in config
formatters: [RemoveMultiLineCommentAsterisks]

AddDoubleLinesFormatter

Adds extra blank lines between content lines (except inside code blocks):

import { AddDoubleLinesFormatter } from "@/simple-docs-scraper/formatters/AddDoubleLinesFormatter.js";

// Usage in config
formatters: [AddDoubleLinesFormatter]

Example Configuration

Here’s a complete example configuration from the publish-docs.ts script:

export const DEFAULT_CONFIG: SimpleDocExtractorConfig = {
  baseDir: process.cwd(),
  generators: {
    index: {
      template: path.join(process.cwd(), "src/templates/index.template.md"),
      markdownLink: true,
      filesHeading: "\n## Files\n",
      directoryHeading: "\n## Folders\n",
      flatten: false, // Set to true to flatten nested directory structure
      recursive: true,
      excerpt: {
        length: 75,
        addEllipsis: false,
        firstSentenceOnly: true,
      },
    },
    documentation: {
      template: path.join(process.cwd(), "src/templates/documentation.template.md"),
    },
  },
  targets: [
    {
      globOptions: {
        cwd: path.join(process.cwd(), "src"),
        extensions: "**/*.{js,ts}",
        ignore: ["**/tests/**", "**/scripts/**"],
      },
      outDir: path.join(process.cwd(), "docs"),
      createIndexFile: true,
      extraction: [
        new TagExtractorPlugin({
          tag: "docs",
          searchAndReplace: "%content%",
        }),
        new TagExtractorPlugin({
          tag: "method",
          searchAndReplace: "%methods%",
          attributeFormat: "### **{value}**",
        }),
      ],
    },
  ],
  formatters: [RemoveMultiLineCommentAsterisks, AddDoubleLinesFormatter],
};

This configuration: