Skip to the content.

Configuration Example

This document provides a simple example of how to configure the SimpleDocsExtractor.

Table of Contents

Basic Configuration

Here’s a minimal configuration that processes TypeScript and JavaScript files:

import { TagExtractorPlugin } from "@/simple-docs-scraper/extractors/TagExtractorPlugin.js";
import { RecommendedFormatters } from "@/simple-docs-scraper/formatters/RecommendedFormatters.js";
import { SimpleDocExtractorConfig } from "@/simple-docs-scraper/types/config.js";
import path from "path";

const config: SimpleDocExtractorConfig = {
  baseDir: process.cwd(),
  targets: [
    {
      globOptions: {
        cwd: path.join(process.cwd(), "src"),
        extensions: "**/*.{js,ts}",
        ignore: ["**/tests/**", "**/scripts/**"],
      },
      outDir: path.join(process.cwd(), "docs"),
      createIndexFile: true,
      flatten: false, // Set to true to flatten nested directory structure
      extraction: [
        new TagExtractorPlugin({
          tag: "docs",
          searchAndReplace: "%content%",
        }),
      ],
    },
  ],
  formatters: RecommendedFormatters.recommended(),
};

Configuration Breakdown

Required Properties

Target Configuration

Each target specifies:

Extractor Plugins

The most common extractor is TagExtractorPlugin, which extracts content between HTML-like tags:

// In your source code:
/**
 * <docs>
 * This documentation will be extracted.
 * </docs>
 */

// In your config:
new TagExtractorPlugin({
  tag: "docs",
  searchAndReplace: "%content%",
})

Formatters

Formatters clean up the extracted content. Common ones include:

Use the RecommendedFormatters class to get the recommended formatters.

Flatten Feature

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

Example with flatten enabled:

{
  outDir: path.join(process.cwd(), "docs"),
  createIndexFile: true,
  flatten: true, // Flattens the directory structure
  extraction: [
    new TagExtractorPlugin({
      tag: "docs",
      searchAndReplace: "%content%",
    }),
  ],
}

This will create a single index file showing all nested files with proper indentation levels.

Usage

import { SimpleDocExtractor } from "@/simple-docs-scraper/index.js";

const extractor = new SimpleDocExtractor(config);
const result = await extractor.start();

For more advanced configuration options, see advanced-config.md.