Skip to the content.

Simple Docs Extractor

Below you will find the table of contents and links to all generated documentation files.


Folders


About

A lightweight TypeScript library for extracting documentation from source files and organizing them into a structured output directory.

Having trouble getting started? Send me an email or create an issue.

Why this approach?

I built this library so I could write documentation directly in my source code, and have it automatically pulled out and organized for me.

This way, I can focus on coding while the library takes care of collecting and structuring the docs.

With GitHub Actions, the documentation is published to GitHub Pages automatically, so everything stays up to date with no extra effort.

Documentation

View the documentation on GitHub Pages.

Features

Proof is in the pudding

Examples

Basic Configuration with Minimal Configuration

const service = SimpleDocExtractor
  .create(process.cwd())
  .target((target) => {
    target.cwd(path.join(process.cwd(), 'src'))
    target.outDir(path.join(process.cwd(), "docs"))
    target.patterns("**/*")
    target.createIndexFiles()
  })
  .addRecommendedFormatters()
  .buildService();

await service.start();

Simple Doc Configuration Example

This is the same example as used in our publish-docs.ts script.

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

export const DEFAULT_CONFIG = SimpleDocExtractor
  .create(process.cwd())
    // Define our global templates (This can also be done on a target level)
    .indexTemplate((template) => {
      template.useFile(path.join(process.cwd(), "src/templates/index.template.md"));
      template.useMarkdownLinks();
    })
    .documentationTemplate((template) => {
      template.useFile(path.join(process.cwd(), "src/templates/documentation.template.md"));
    })
  // Define our target(s) to extract documentation from
  .target((target) => {
    target.cwd(path.join(process.cwd(), 'src')) // The directory to search for files to extract documentation from
    target.outDir(path.join(process.cwd(), "docs")) // The directory to output the generated documentation to
    target.patterns("**/*.{js,ts}") // The patterns to match files to extract documentation from
    target.ignores(["**/tests/**", "**/scripts/**"]) // The patterns to ignore when searching for files to extract documentation from
    target.createIndexFiles() // Whether to create an index.md file for this target
    target.plugins([ // The plugins to use when extracting documentation
      new TagExtractorPlugin({
        tag: "docs",
        searchAndReplace: "%content%",
      }),
      new TagExtractorPlugin({
        tag: "method",
        searchAndReplace: "%methods%",
        attributeFormat: "### **{value}**",
      })
    ])
    // Define the template to use for the root index file
    target.rootIndexTemplate((template) => {
      template.useFile(path.join(process.cwd(), "src/templates/root-index.template.md")); // The template to use for the root index file
      template.useMarkdownLinks(); // Whether to use markdown links in the root index file
      template.plugins( // The plugins to use when generating the root index file
        new CopyContentsPlugin({
          fileToCopy: path.join(process.cwd(), "README.md"),
          searchAndReplace: "%readme%",
        }),
      )
    })
  })
  .addRecommendedFormatters() // Add the recommended formatters to the configuration
  .buildConfig(); // Build the configuration

new SimpleDocExtractor(config).start()
    .then(result => {
        console.log('Success count: ', result.successCount);
        console.log('Total count: ', result.totalCount);
        console.log('Missing documentation files: ', result.missingDocumentationFiles);
        console.log('Logs:');
        result.logs.forEach(log => {
            console.log(log);
        });
    });

This file is auto generated. Do not edit manually.