Repomix 是一款功能强大的工具,既可以作为 CLI 命令行工具使用,也能当作 Node.js 库来用。它能对本地和远程代码库进行处理,还提供多种输出格式,为代码处理和报告生成带来了极大的便利。
支持对生成的文件进行压缩,便于存储和传输。
npm install repomix
repomix --input <目录> [--output <文件名>] [--format <格式>]
处理当前目录并输出为 result.xml:
repomix . --output result.xml --format xml
--input 或 -i:指定输入目录或文件路径。--output 或 -o:指定输出文件名,默认为 repomix-output.txt。--format 或 -f:指定输出格式,支持 txt, xml, json。--compress 或 -c:启用压缩功能,默认为 false。--style:指定输出风格(仅限文本格式),支持 plain 和 markdown。--quiet 或 -q:禁用终端输出,仅生成文件。import { searchFiles, collectFiles } from 'repomix';
async function processFiles(directory) {
const files = await searchFiles(directory);
const collected = await collectFiles(files);
return collected;
}
import { processFiles } from 'repomix';
async function handleFiles(filePaths, directory) {
const rawFiles = await collectFiles(filePaths, directory);
const processed = await processFiles(rawFiles);
return processed;
}
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和其依赖项。- 权限问题:处理远程仓库时,需确保有访问权限。
- 性能优化:对于大规模代码库,建议启用压缩功能以减少存储空间。
本项目遵循 MIT 协议开源:
版权所有 (c) 2023 Repomix 开发团队 本作品在 MIT 协议下发布,允许自由使用、修改和分发。
| 属性 | 详情 |
|---|---|
| 输出格式 | txt:文本格式,默认支持;xml:XML 标记语言,便于机器解析;json:JSON 数据交换格式,适合程序处理 |