Skip to content

About

AI powered documentation tool for Typescript

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– TypeScript AI Documentation Generator

Automatically generate comprehensive JSDoc documentation for TypeScript code using local AI models via Ollama

License: MIT TypeScript Node

✨ Features

  • πŸ”’ 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

πŸ“Έ Demo

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;
}

πŸš€ Quick Start

Prerequisites

Installation

# 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

Basic Usage

# 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 codellama

πŸ“– Documentation

Command Line Options

npm 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

Supported Code Constructs

  • βœ… Function declarations
  • βœ… Arrow functions
  • βœ… Class methods
  • βœ… Async functions
  • βœ… Optional parameters
  • βœ… Type annotations
  • βœ… Generic types

Recommended Models

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

πŸ”§ Configuration

Change Default Model

Edit src/index.ts:

const model = args[2] || 'qwen2.5-coder:7b'; // Your preferred model

Adjust AI Temperature

Edit src/ollama.ts:

options: {
  temperature: 0.2,  // Lower = more consistent, Higher = more creative
  top_p: 0.9,
}

Customize Documentation Style

Edit the prompt in src/generator.ts to change:

  • Documentation format
  • Level of detail
  • Included information
  • Example generation

🎯 Examples

Document a Utility File

npm run doc src/utils/helpers.ts

Process Multiple Files

# Create a script to batch process
for file in src/**/*.ts; do
  npm run doc "$file"
done

Integrate with Build Process

Add to package.json:

{
  "scripts": {
    "predocs": "npm run build",
    "docs": "npm run doc src/index.ts docs/index.ts"
  }
}

πŸ› Troubleshooting

Cannot connect to Ollama

# Make sure Ollama is running
ollama serve

# Verify in another terminal
ollama list

Model not found

# Pull the model
ollama pull qwen2.5-coder:7b

# List available models
ollama list

Slow generation

  • Use a smaller model: qwen2.5-coder:1.5b or qwen2.5-coder:3b
  • Ensure Ollama has enough RAM/VRAM
  • Close other resource-intensive applications

Parser not finding functions

# Debug the parser
npm run test-parser examples/sample.ts

This will show the AST structure and what the parser detects.

Poor documentation quality

  1. Try qwen2.5-coder:14b for better results
  2. Adjust temperature in src/ollama.ts
  3. Modify the prompt in src/generator.ts
  4. Ensure your code has proper type annotations

Development Setup

# 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.ts

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

⭐ Star History

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

About

AI powered documentation tool for Typescript

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages