0.1.3 • Published 5 months ago

gather-ts v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

gather-ts

A powerful code analysis and packaging tool designed for creating AI-friendly code representations. Gather-ts analyzes your codebase, resolves dependencies, and generates a comprehensive single-file representation optimized for AI analysis.

npm version License: MIT

Features

  • 📊 Comprehensive code analysis with dependency resolution
  • 🔍 Intelligent file filtering and ignore patterns
  • 📝 Token-aware processing with multiple model support
  • 🚀 High performance with batch processing and caching
  • ⚡️ Support for TypeScript and JavaScript projects
  • 🛠️ Configurable output formats
  • 📈 Detailed metrics and analytics

Installation

Install globally:

npm install -g gather-ts

Or as a project dependency:

npm install --save-dev gather-ts

Quick Start

  1. Navigate to your project directory:
cd your-project
  1. Generate a default configuration:
gather-ts --init
  1. Run the analysis:
gather-ts src/index.ts --output analysis.txt

Usage

Basic Command Structure

gather-ts <files...> --output <output> [options]

Arguments

  • files: Entry files to analyze (comma or space separated)
  • --output, -o: Output file path
  • --root, -r: Project root directory (default: current directory)
  • --depth, -d: Maximum depth for dependency analysis
  • --debug: Enable debug logging
  • --batch-size: Batch size for processing files
  • --metrics: Include performance metrics in output
  • --config, -c: Path to custom config file
  • --encoding: File encoding (default: utf8)
  • --ignore: Additional patterns to ignore
  • --require: Required files to include
  • --init: Initialize configuration in current directory

Examples

Analyze a single file:

gather-ts src/app/page.tsx --output output.txt

Analyze multiple files with metrics:

gather-ts src/app/page.tsx,src/components/Button.tsx --output output.txt --metrics

Custom configuration and depth:

gather-ts src/index.ts --output analysis.txt --config custom-config.json --depth 3

Configuration

Gather-ts can be configured using a gather-ts.config.json file in your project root. Generate a default configuration using:

gather-ts --init

Configuration Options

{
  "maxDepth": 5,
  "topFilesCount": 5,
  "showTokenCount": true,
  "tokenizer": {
    "model": "gpt-4",
    "showWarning": true
  },
  "outputFormat": {
    "includeSummaryInFile": true,
    "includeGenerationTime": true,
    "includeUsageGuidelines": true
  },
  "debug": false,
  "cacheTokenCounts": true
}

Configuration Fields

FieldTypeDescriptionDefault
maxDepthnumberMaximum depth for dependency analysis5
topFilesCountnumberNumber of top files to show in summary5
showTokenCountbooleanShow token counts in outputtrue
tokenizer.modelstringModel to use for tokenization"gpt-4"
tokenizer.showWarningbooleanShow warnings for token limitstrue

File Ignoring

Gather-ts uses both .gitignore and .gather-ts-ignore files for determining which files to process. Create a .gather-ts-ignore file in your project root to specify additional ignore patterns:

# Ignore test files
**/*.test.ts
**/*.spec.ts

# Ignore documentation
docs/
*.md

# Ignore specific directories
temp/
build/

API Usage

You can also use gather-ts programmatically in your Node.js applications:

import { configureContainer } from 'gather-ts';

async function analyzeCode() {
  const container = await configureContainer(process.cwd(), {
    debug: true,
    maxCacheAge: 7 * 24 * 60 * 60 * 1000, // 7 days
    fileExtensions: ['ts', 'tsx', 'js', 'jsx']
  });

  const compiler = container.resolve(ServiceTokens.COMPILER);
  
  const result = await compiler.compile({
    entryFiles: ['src/index.ts'],
    outputFile: 'analysis.txt',
    includeMetrics: true
  });

  console.log(`Analysis complete! Output: ${result.outputPath}`);
}

Error Handling

Gather-ts provides detailed error messages and validation. Common error scenarios:

  • Invalid configuration
  • File access issues
  • Dependency resolution failures
  • Token counting errors

Errors include context and suggestions for resolution.

Performance Tips

  1. Use appropriate depth limits for large projects
  2. Enable token count caching for faster processing
  3. Use batch processing for large file sets
  4. Ignore unnecessary files using .gather-ts-ignore

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

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

Support

Changelog

See CHANGELOG.md for a list of changes and version history.

Authors

  • Andrew Robb - Initial work

Acknowledgments

  • Thanks to all contributors
  • Built with TypeScript and Node.js
  • Inspired by the need for better AI code analysis tools