Overview
The Addon Verification generator extracts code blocks from thedoc/api/addons.md file to facilitate C++ compilation and JavaScript runtime validations. It organizes code examples by section for testing purposes.
Metadata
Generator identifier
Generator version
Requires metadata generator output as input
Configuration
Output directory path for extracted code files organized by section
Output Format
The generator produces:- Directory structure: One folder per buildable section
- Naming:
{index}_{normalized-section-name}/ - Files: Code files extracted from code blocks (C++, JavaScript, etc.)
- Organization: Files grouped by documentation section
Usage
Dependency Chain
- ast - Parses Markdown to AST
- metadata - Extracts API metadata
- addon-verify - Extracts and organizes code blocks
Implementation Details
The generator:- Visits all code blocks in the AST using
unist-util-visit - Extracts filename from code block comments (e.g.,
// filename.cc) - Groups code blocks by section name
- Filters for buildable sections using
isBuildableSection - Generates normalized folder names
- Creates directory structure
- Writes extracted files to appropriate folders
Filename Extraction
Code blocks must include a filename comment:EXTRACT_CODE_FILENAME_COMMENT regex pattern to extract the filename.
Section Filtering
TheisBuildableSection function determines which sections contain compilable/testable code:
- Checks for presence of build configuration files
- Validates code completeness
- Ensures section is intended for verification
Folder Naming
Folder names are generated using:normalizeSectionName: Converts to lowercase, replaces spaces with hyphensgenerateSectionFolderName: Prepends index for ordering
"Hello World" → 0_hello-world/
File Generation
ThegenerateFileList function:
- Takes code blocks for a section
- Extracts filename and content from each block
- Returns array of file objects ready for writing
This generator is specifically designed for the Node.js addons documentation and expects the filename comment pattern used in
addons.md.src/generators/addon-verify/