AutoScribe is an AI-powered documentation generator that automatically creates comprehensive JSDoc/TSDoc comments for your JavaScript and TypeScript code using GPT 4.o.
- Generates rich file-level and function-level documentation
- Processes individual files or entire directories recursively
- Supports JavaScript (.js), TypeScript (.ts), JSX (.jsx), and TSX (.tsx) files
- Maintains existing code structure while adding documentation
- Configurable through environment variables or command-line arguments
- Supports "dry-run" mode which outputs in terminal
- Handles various function types including:
- Function declarations
- Arrow functions
- Class methods
- Object methods
- Node.js (version 14 or higher recommended)
- OpenAI API key
- NPM or Yarn package manager
- Clone the repository:
git clone [https://github.com/adamchain/autoscribe.git]
cd [autoscribe]
- Install dependencies:
npm install
- Create a
.env
file in the project root:
OPENAI_API_KEY=your_api_key_here
OPENAI_MODEL=gpt-4o
OUTPUT_FORMAT=jsdoc
SUPPORTED_EXTENSIONS=.js,.jsx,.ts,.tsx
MAX_RETRIES=3
DRY_RUN=false
node autoscribe.js <path> --api-key <your-api-key>
-
--dry-run
: Generate documentation in terminal, without modifying files -
--api-key <key>
: OpenAI API key (not required if key is in env) -
--recursive
: Process directories recursively -
--model <model>
: OpenAI model to use (default: gpt-4o) -
--format <format>
: Documentation format (jsdoc|tsdoc)
Document a single file:
node autoscribe.js ./src/component.js
Document an entire directory recursively:
node autoscribe.js ./src --recursive
Preview documentation without making changes:
node autoscribe.js ./src/component.js --dry-run
The tool can be configured through environment variables or command-line arguments:
Environment Variable | Description | Default |
---|---|---|
OPENAI_API_KEY | Your OpenAI API key | Required |
OPENAI_MODEL | GPT model to use | gpt-4o |
OUTPUT_FORMAT | Documentation format | jsdoc |
SUPPORTED_EXTENSIONS | File extensions to process | .js,.jsx,.ts,.tsx |
MAX_RETRIES | Maximum retry attempts | 3 |
DRY_RUN | Preview mode | false |
The tool generates comprehensive documentation including:
- File purpose
- Main components/functions
- Important notes and dependencies
- Function description
- Parameter types and descriptions
- Return value type and description
- Exception documentation when applicable
- Retries failed API calls up to the configured maximum
- Validates generated documentation format
- Provides detailed error messages for troubleshooting
- Maintains original code if documentation generation fails
Contributions are welcome! Please feel free to submit a Pull Request.
GPL-3.0 license
- OpenAI for the brain
- Babel for AST parsing
For issues, questions, or contributions, please create an issue in the repository.