@leolee9086/longfile-detector
v1.0.0
Published
A high-performance CLI tool to detect and list text files with the most lines in a directory
Maintainers
Readme
Longfile Detector
一个高性能的命令行工具,用于检测并列示指定目录下行数最多的文本文件。
特性
- 🚀 高性能: 使用 fast-glob 和优化的文件处理算法
- 🔍 智能检测: 基于 mimedb 的 MIME 类型检测,准确识别文本文件
- 🎯 灵活过滤: 支持 Glob 模式和扩展名过滤
- 📊 详细信息: 显示文件行数、大小、类型和修改时间
- 🛡️ 安全可靠: 完善的错误处理和边界情况处理
- 📦 易于使用: 支持 npx 直接运行
安装
全局安装
npm install -g longfile-detector使用 npx (推荐)
npx longfile-detector [选项]本地安装
npm install longfile-detector使用方法
基本用法
# 扫描当前目录,显示前10个最大的文本文件
npx longfile-detector
# 扫描指定目录
npx longfile-detector -d /path/to/directory
# 显示更多文件
npx longfile-detector -n 20
# 使用自定义 Glob 模式
npx longfile-detector -g "**/*.{js,ts,jsx,tsx}"
# 按扩展名过滤
npx longfile-detector -e "js,ts,jsx,tsx"
# 显示详细信息
npx longfile-detector -v命令行选项
| 选项 | 简写 | 描述 | 默认值 |
|------|------|------|--------|
| --directory | -d | 要扫描的目录路径 | . (当前目录) |
| --number | -n | 显示文件数量 | 10 |
| --glob | -g | Glob 模式过滤文件 | **/*.{js,ts,jsx,tsx,html,css,scss,less,json,md,txt,yml,yaml} |
| --extensions | -e | 文件扩展名过滤,逗号分隔 | - |
| --verbose | -v | 显示详细信息 | false |
| --help | -h | 显示帮助信息 | - |
| --version | -V | 显示版本号 | - |
示例输出
正在扫描目录: ./src
使用 Glob 模式: **/*.{js,ts,jsx,tsx,html,css,scss,less,json,md,txt,yml,yaml}
检测结果 (按行数排序):
────────────────────────────────────────────────────────────────────────────────
1. 1,234 行 ( 45.67 KB) - src/components/large-component.js
2. 987 行 ( 32.15 KB) - src/utils/data-processor.ts
3. 654 行 ( 21.89 KB) - src/pages/dashboard.jsx
4. 432 行 ( 15.23 KB) - src/styles/main.scss
5. 321 行 ( 11.45 KB) - src/config/settings.json
────────────────────────────────────────────────────────────────────────────────
扫描完成,共处理 5 个文件,耗时 23.45 ms支持的文件类型
工具会自动检测以下类型的文本文件:
编程语言
- JavaScript (.js, .jsx)
- TypeScript (.ts, .tsx)
- Python (.py)
- Java (.java)
- C/C++ (.c, .cpp, .h, .hpp)
- C# (.cs)
- PHP (.php)
- Ruby (.rb)
- Go (.go)
- Rust (.rs)
- Swift (.swift)
- Kotlin (.kt)
- Scala (.scala)
- R (.r)
- Perl (.pl)
- Lua (.lua)
Web 技术
- HTML (.html, .htm)
- CSS (.css, .scss, .sass, .less)
- JSON (.json)
- XML (.xml)
- YAML (.yml, .yaml)
文档
- Markdown (.md)
- 纯文本 (.txt)
- 配置文件 (.ini, .conf)
其他
- Shell 脚本 (.sh, .bash)
- SQL (.sql)
- 日志文件 (.log)
- Dockerfile
- Makefile
- Git 配置文件 (.gitignore, .gitattributes)
性能优化
- 并行处理: 使用 Promise.all 并行处理多个文件
- 高效行数计算: 直接操作 Buffer,避免字符串分割
- 智能过滤: 基于 MIME 类型的准确文件类型检测
- 内存优化: 流式处理大文件,避免内存溢出
- 缓存优化: 使用 fast-glob 的高效文件系统遍历
错误处理
工具具有完善的错误处理机制:
- 自动跳过无法读取的文件
- 忽略二进制文件和非文本文件
- 处理权限问题
- 提供详细的错误信息(使用 -v 选项)
开发
本地开发
# 克隆仓库
git clone <repository-url>
cd longfile-detector
# 安装依赖
npm install
# 运行测试
npm test
# 代码检查
npm run lint
# 本地运行
node bin/longfile-detector.js测试
# 运行所有测试
npm test
# 运行特定测试
node --test test/detector.test.js许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
更新日志
v1.0.0
- 初始版本发布
- 支持基本的文件检测功能
- 添加 Glob 模式过滤
- 实现高性能行数计算
- 添加详细的测试用例
