README
🚀 Repomix 使用说明
Repomix 是一款功能强大的工具,既可以作为 CLI 命令行工具使用,也能当作 Node.js 库来用。它能对本地和远程代码库进行处理,还提供多种输出格式,为代码处理和报告生成带来了极大的便利。
✨ 主要特性
1. 多种文件处理模式
- 本地模式:扫描当前目录及其子目录,生成指定格式的报告。
- 远程模式:通过 Git 协议克隆远程仓库后进行处理。
2. 支持多种输出格式
- XML
- JSON
- 文本(默认)
3. 压缩功能
支持对生成的文件进行压缩,便于存储和传输。
📦 安装指南
安装工具
npm install repomix
💻 使用示例
快速上手
基本命令
repomix --input <目录> [--output <文件名>] [--format <格式>]
示例
处理当前目录并输出为 result.xml:
repomix . --output result.xml --format xml
📚 详细文档
配置选项
1. 常用参数
--input或-i:指定输入目录或文件路径。--output或-o:指定输出文件名,默认为repomix-output.txt。--format或-f:指定输出格式,支持txt,xml,json。--compress或-c:启用压缩功能,默认为false。
2. 高级选项
--style:指定输出风格(仅限文本格式),支持plain和markdown。--quiet或-q:禁用终端输出,仅生成文件。
核心组件
1. 文件搜索与收集
import { searchFiles, collectFiles } from 'repomix';
async function processFiles(directory) {
const files = await searchFiles(directory);
const collected = await collectFiles(files);
return collected;
}
2. 文件处理流程
import { processFiles } from 'repomix';
async function handleFiles(filePaths, directory) {
const rawFiles = await collectFiles(filePaths, directory);
const processed = await processFiles(rawFiles);
return processed;
}
3. token 计数器
import { TokenCounter } from 'repomix';
const counter = new TokenCounter('gpt-4');
const tokens = counter.countTokens('Hello World!');
示例代码
处理远程仓库
import { runCli, type CliOptions } from 'repomix';
async function processRemoteRepo(url: string) {
const options: CliOptions = {
input: url,
output: 'remote-output.xml',
format: 'xml',
compress: true
};
await runCli(options);
}
注意事项
⚠️ 重要提示
- 依赖管理:确保安装所有必需的包,包括
repomix和其依赖项。- 权限问题:处理远程仓库时,需确保有访问权限。
- 性能优化:对于大规模代码库,建议启用压缩功能以减少存储空间。
项目贡献
贡献指南
- 提交 ISSUE 报告问题或提出需求。
- Fork 代码库并提交 PR 修复 bug 或改进功能。
- 加入社区讨论,参与开发决策。
仓库地址
许可证
本项目遵循 MIT 协议开源:
版权所有 (c) 2023 Repomix 开发团队 本作品在 MIT 协议下发布,允许自由使用、修改和分发。
附录
支持的输出格式
| 属性 | 详情 |
|------|------|
| 输出格式 | txt:文本格式,默认支持;xml:XML 标记语言,便于机器解析;json:JSON 数据交换格式,适合程序处理 |
Scan to contact