Automatically generate comprehensive JSDoc documentation for TypeScript code using local AI models via Ollama
- π 100% Local - All processing happens on your machine, your code never leaves
- π― Smart Parsing - Automatically detects functions, methods, parameters, and return types
- π JSDoc Generation - Creates properly formatted documentation with descriptions
- π Powered by Qwen2.5-Coder - Optimized for code understanding and documentation
- β‘ Fast Processing - Local LLM means no API rate limits or costs
- π Type-Aware - Understands TypeScript types, interfaces, and generics
- π¨ Zero Configuration - Works out of the box with sensible defaults
Before:
export function calculateArea(width: number, height: number): number {
return width * height;
}After:
/**
* Calculates the area of a rectangle by multiplying its width and height.
*
* @param {number} width - The width of the rectangle in units
* @param {number} height - The height of the rectangle in units
* @returns {number} The calculated area as width multiplied by height
*/
export function calculateArea(width: number, height: number): number {
return width * height;
}- Node.js (v18 or higher)
- Ollama - Download here
# Clone the repository
git clone https://github.com/yourusername/ts-doc-generator.git
cd ts-doc-generator
# Install dependencies
npm install
# Install and start Ollama
# Download from https://ollama.ai, then:
ollama serve
# Pull Qwen2.5-Coder model (in a new terminal)
ollama pull qwen2.5-coder:7b
# Build the project
npm run build
# Try it out!
npm run doc examples/sample.ts# Generate documentation for a file
npm run doc path/to/your-file.ts
# Specify custom output location
npm run doc src/app.ts src/app.documented.ts
# Use with different Ollama model
npm run doc src/app.ts output.ts codellamanpm run doc <input-file> [output-file] [model]
| Argument | Required | Default | Description |
|---|---|---|---|
input-file |
β Yes | - | Path to TypeScript file to document |
output-file |
β No | <input>.documented.ts |
Where to save documented code |
model |
β No | qwen2.5-coder:7b |
Ollama model to use |
- β Function declarations
- β Arrow functions
- β Class methods
- β Async functions
- β Optional parameters
- β Type annotations
- β Generic types
| Model | Size | Speed | Quality | Best For |
|---|---|---|---|---|
| qwen2.5-coder:7b | 4.7GB | Fast | Excellent | Code documentation (recommended) |
| qwen2.5-coder:14b | 9GB | Medium | Outstanding | Complex codebases |
| codellama | 3.8GB | Fast | Very Good | General code tasks |
| deepseek-coder | 6.7GB | Medium | Excellent | Alternative to Qwen |
Edit src/index.ts:
const model = args[2] || 'qwen2.5-coder:7b'; // Your preferred modelEdit src/ollama.ts:
options: {
temperature: 0.2, // Lower = more consistent, Higher = more creative
top_p: 0.9,
}Edit the prompt in src/generator.ts to change:
- Documentation format
- Level of detail
- Included information
- Example generation
npm run doc src/utils/helpers.ts# Create a script to batch process
for file in src/**/*.ts; do
npm run doc "$file"
doneAdd to package.json:
{
"scripts": {
"predocs": "npm run build",
"docs": "npm run doc src/index.ts docs/index.ts"
}
}# Make sure Ollama is running
ollama serve
# Verify in another terminal
ollama list# Pull the model
ollama pull qwen2.5-coder:7b
# List available models
ollama list- Use a smaller model:
qwen2.5-coder:1.5borqwen2.5-coder:3b - Ensure Ollama has enough RAM/VRAM
- Close other resource-intensive applications
# Debug the parser
npm run test-parser examples/sample.tsThis will show the AST structure and what the parser detects.
- Try
qwen2.5-coder:14bfor better results - Adjust temperature in
src/ollama.ts - Modify the prompt in
src/generator.ts - Ensure your code has proper type annotations
# Clone your fork
git clone https://github.com/yourusername/ts-doc-generator.git
cd ts-doc-generator
# Install dependencies
npm install
# Make changes and test
npm run build
npm run doc examples/sample.ts
# Run the parser debugger
npm run test-parser examples/sample.tsThis project is licensed under the MIT License - see the LICENSE file for details.
If you find this project useful, please consider giving it a star! It helps others discover the project.
Made with β€οΈ by [Pichutan]
Powered by Qwen2.5-Coder and Ollama