tools/storybook-llms-extractor/README.md
A CLI tool that extracts documentation from Storybook builds and converts it to LLM-friendly formats, following the llmstxt.org specification.
This tool processes Storybook production builds to generate comprehensive documentation in plain text format that's optimized for Large Language Models (LLMs). It extracts component documentation, props, examples, and MDX content to create structured documentation files.
npm install @fluentui/storybook-llms-extractor
# or
yarn add @fluentui/storybook-llms-extractor
Extract documentation from a Storybook build:
storybook-llms-extractor --distPath "storybook-static" --summaryBaseUrl "https://storybook.example.com"
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
--distPath | string | Yes | - | Relative path to the Storybook distribution folder |
--summaryBaseUrl | string | No | / | Base URL for the Storybook docs |
--summaryTitle | string | No | Summary | Title for the summary file |
--summaryDescription | string | No | "" | Description for the summary file |
--refs | array | No | [] | Array of composed Storybook refs |
You can use a configuration file (e.g., llms.config.js) for complex setups:
module.exports = {
distPath: 'storybook-static',
summaryBaseUrl: 'https://react.fluentui.dev',
summaryTitle: 'Fluent UI React v9',
summaryDescription: 'Fluent UI React components documentation',
refs: [
{
title: 'Charts v9',
url: 'https://charts.fluentui.dev',
},
],
};
Then run:
storybook-llms-extractor --config llms.config.js
The tool generates the following files in your Storybook dist directory:
storybook-static/
├── llms.txt # Main summary file (llmstxt.org format)
└── llms/
├── component-button.txt # Individual component docs
├── component-accordion.txt
└── concepts-introduction.txt # MDX page docs
llms.txt)The main summary file follows the llmstxt.org specification:
# Fluent UI React v9
> **Note:** This is a summary overview using the LLMs.txt format...
- [Components/Button](https://example.com/llms/components-button.txt): A button component
- [Components/Accordion](https://example.com/llms/components-accordion.txt): An accordion component
Each component gets its own detailed documentation file:
# Components/Button
A button triggers an action or event.
## Props
| Name | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| `appearance` | `"primary" | "secondary"` | No | `"secondary"` | Button appearance |
## Examples
### Primary Button
```tsx
<Button appearance="primary">Click me</Button>
## How It Works
1. **Static File Routing**: Uses Playwright to serve Storybook files without needing a web server
2. **Story Extraction**: Accesses Storybook's internal story store to get all component metadata
3. **Content Processing**: Converts HTML documentation to clean Markdown format
4. **Documentation Generation**: Creates structured text files optimized for LLM consumption
## Integration Examples
### GitHub Actions
```yaml
- name: Build Storybook
run: npm run build-storybook
- name: Generate LLM Docs
run: npx storybook-llms-extractor --distPath storybook-static --summaryBaseUrl ${{ env.DEPLOY_URL }}
If you have multiple Storybook instances, you can reference them:
storybook-llms-extractor \
--distPath "storybook-static" \
--summaryBaseUrl "https://main.storybook.dev" \
--refs '{"title":"Charts","url":"https://charts.storybook.dev"}' \
--refs '{"title":"Icons","url":"https://icons.storybook.dev"}'
nx build storybook-llms-extractor
nx test storybook-llms-extractor
# Link the package locally
npm link
# Use in another project
cd /path/to/your/storybook
npm link @fluentui/storybook-llms-extractor
storybook-llms-extractor --distPath storybook-static
"Unable to find Storybook story store"
distPathHTML content not converting properly
Missing component props
This tool is part of the Fluent UI project. Please see the main repository for contribution guidelines.
MIT - see the main Fluent UI repository for details.