fileweaver
Version:
A CLI tool to weave files together based on regex patterns
211 lines (162 loc) โข 6.53 kB
Markdown
# ๐ FileWeaver
<div align="center">




A powerful CLI tool for weaving files together with advanced pattern matching capabilities, featuring visual progress and tree view of processed files. Optimized for sharing code with Large Language Models (LLMs).
[Installation](#installation) โข
[Usage](#usage) โข
[Examples](#examples) โข
[Contributing](#contributing)
</div>
## โจ Features
- ๐ **Regex Pattern Matching**: Filter files using regular expressions
- ๐ซ **Exclusion Patterns**: Ignore files that match specific patterns
- ๐ **Directory Support**: Process files from any directory
- ๐ **File Headers**: Option to include original filenames in the output
- ๐ฏ **Flexible Output**: Specify custom output location and filename
- ๐ณ **Tree View**: Visual representation of processed files with optional inclusion in output
- ๐ **Progress Bar**: Real-time processing visualization
- ๐จ **Colored Output**: Enhanced readability with color-coded messages
- ๐ **Custom Prompts**: Add custom prompts to the output file
- ๐๏ธ **Directory Tree**: Include directory structure in the output file
- ๐ **Token Estimation**: Get approximate token counts for LLM context management
- ๐ **Size Limiting**: Control output size to fit LLM context windows
- ๐งน **Comment Removal**: Strip comments to reduce size and focus on core code
- ๐ **Markdown Format**: Generate output in Markdown with proper code formatting
- ๐ **Project Summary**: Auto-generate project overviews from README and package.json
- โญ **File Prioritization**: Ensure important files appear first in the output
- ๐ **Language Detection**: Automatically identify and tag programming languages
## ๐ Installation
```bash
npm install -g fileweaver
```
## ๐ง Usage
```bash
fileweaver [options]
```
### Options
| Option | Description | Default |
|--------|-------------|---------|
| `-r, --regex <pattern>` | Regex pattern to match files | - |
| `-ir, --ignoreregex <pattern>` | Regex pattern to ignore files | - |
| `-d, --directory <path>` | Directory path | Current directory |
| `-h, --headers` | Add file headers to content | false |
| `-o, --output <file>` | Output file name | output.txt |
| `-t, --tree` | Include directory tree in output file | false |
| `-p, --prompt <text>` | Add custom prompt to output file | - |
| `-m, --markdown` | Format output as markdown with code blocks | false |
| `-tok, --tokens` | Show token estimation for LLMs | false |
| `-nc, --no-comments` | Strip comments from code files | false |
| `-s, --summary` | Include auto-generated project summary | false |
| `-i, --important <files>` | Comma-separated file patterns to prioritize | - |
| `-m, --max-size <size>` | Maximum output size in KB | Infinity |
| `--version` | Show version number | - |
| `--help` | Show help | - |
## ๐ Examples
### Basic File Concatenation with Tree
```bash
fileweaver -d . -r "\.js$" -t true -o combined.js
```
This will include a tree view in the output file:
```
==================================================
Directory Tree:
==================================================
โโโ src
โ โโโ index.js
โ โโโ utils
โ โโโ helper.js
โ โโโ validator.js
โโโ index.js
```
### Add Custom Prompt
```bash
fileweaver -r "\.md$" -p "Process these markdown files for documentation" -o docs.md
```
Output will include:
```
==================================================
Prompt:
==================================================
Process these markdown files for documentation
```
### LLM-Optimized Format with Token Estimation
```bash
fileweaver -r "\.(js|jsx)$" -markdown -tokens -o for-llm.md
```
This will:
- Format all JavaScript files with Markdown code blocks
- Add language tags to each code block
- Include token count estimation for LLM context management
### Generate Project Summary with Key Files First
```bash
fileweaver -s -i "index.js,main.jsx,README.md" -markdown -o project-overview.md
```
This will:
- Generate a project summary from README and package.json
- Prioritize the specified important files
- Format everything as Markdown
### Size-Limited Export for LLM Context
```bash
fileweaver -r "src/" -max-size 100 -tokens -nc -o llm-input.txt
```
This will:
- Process all files in the src directory
- Limit output to 100KB to fit LLM context windows
- Remove comments to save space
- Show token estimation
- Save to llm-input.txt
### Combine Multiple LLM-Optimized Features
```bash
fileweaver -d ./src -r "\.(js|ts)$" -markdown -tokens -nc -s -i "index.js,App.tsx" -max-size 150 -o llm-ready.md
```
This will:
- Process all JS and TS files
- Format with Markdown
- Remove comments
- Include project summary
- Prioritize important files
- Limit size to 150KB
- Estimate tokens
- Save as llm-ready.md
## ๐ Advanced Usage
### Complete LLM Project Analysis
Generate a comprehensive project overview optimized for code review by LLMs:
```bash
fileweaver -d ./project -s -markdown -tokens -i "index.js,package.json,src/App.js" -t true -p "Please review this React project codebase and suggest improvements" -o llm-review.md
```
This will:
- Process all files in the project
- Generate a project summary
- Format with Markdown code blocks
- Prioritize key files at the beginning
- Include directory tree
- Add token estimations
- Add the specified prompt for the LLM
### Code Exploration with Size Constraints
```bash
fileweaver -r "\.jsx?$" -ir "test|mock" -markdown -nc -max-size 50 -o explore.md
```
This will:
- Process all JavaScript files (excluding test and mock files)
- Format with Markdown
- Remove comments
- Limit output to 50KB
- Save to explore.md
## ๐ค Contributing
Contributions are welcome! Feel free to:
1. Fork the repository
2. Create your feature branch: `git checkout -b feature/amazing-feature`
3. Commit your changes: `git commit -m 'Add amazing feature'`
4. Push to the branch: `git push origin feature/amazing-feature`
5. Open a Pull Request
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.
## ๐ Support
For support and questions, please [open an issue](https://github.com/c2developers/fileweaver/issues) on GitHub.
---
<div align="center">
Made with โค๏ธ by C2Developers
</div>