@thedatagrid/generate-docs-meta
v1.0.5
Published
CLI tool for generating docs metadata
Readme
@thedatagrid/generate-docs-meta
A CLI tool for generating metadata from documentation files. This tool scans your documentation directory, processes MDX files, and generates both TypeScript types and JSON metadata for your documentation.
Installation
npm install @thedatagrid/generate-docs-metaUsage
Basic Usage
npx generate-content-metadata --content-root ./contentCommand Line Options
--content-root, -c: Root directory containing content files--dts-output-file, -d: Output file for TypeScript type definitions--json-output-file, -j: Output file for JSON metadata--page-extension, -e: File extension for content pages (default: .page.mdx)--image-quality, -q: Image quality for optimization (1-100, default: 85)--verbose, -v: Run with verbose logging--help, -h: Show help
Example
npx generate-content-metadata \
--content-root ./docs \
--dts-output-file ./src/types/routes.d.ts \
--json-output-file ./src/data/index.json \
--page-extension .mdx \
--image-quality 90 \
--verboseConfiguration via package.json
You can also configure the tool by adding a docsRoot object to your package.json:
{
"docsRoot": {
"source": "./content",
"dtsOutputFile": "./src/.gen/routes.d.ts",
"jsonOutputFile": "./src/.gen/index.json",
"pageExtension": ".page.mdx",
"imageQuality": 85
}
}Image Processing
The tool automatically processes image assets referenced in frontmatter fields (like thumbnail):
- Dimension Detection: Automatically extracts image dimensions (width, height, type)
- Quality Optimization: Optimizes images using Sharp with configurable quality settings
- Supported Formats: JPEG, PNG, WebP, AVIF, GIF, SVG
- Fallback: If optimization fails, the original image is copied
Image dimensions are added to the frontmatter as {fieldName}Dimensions (e.g., thumbnailDimensions).
Output
The tool generates two types of output:
- TypeScript type definitions (
.d.tsfile) - JSON metadata containing:
- File paths
- Frontmatter data
- Excerpts
- Reading time
- Content structure
- Image dimensions (for image assets)
Requirements
- Node.js >= 18.0.0
License
MIT
