🚀 Professional Project Migration Assistant - Git status check, smart cleanup, and migration preparation tools
npm install dir-cli一个安全高效的项目清理与迁移准备工具。
- 智能清理:支持 Node.js、Python、Java、Rust、Go
- Git 准备度检查:未提交、未推送、冲突、远程仓库
- 状态报告:支持 HTML / Markdown / JSON 输出
- 安全机制:Dry-run 预览、白名单、路径校验、符号链接防护
- 国际化:内置中英文,多语言可选
- Node.js >= 16.0.0
- 操作系统:macOS、Linux 或 Windows(含 WSL)
``bash`
npm install -g dir-cli
`bash检查项目状态与迁移准备度
dir-cli check
🧰 命令说明
$3
扫描并分析当前目录下各项目的 Git 状态与迁移准备度。选项:
-
--depth :最大扫描深度(默认:无限制)
- --format :table | json | plain(默认:table)
- --include-hidden:包含隐藏目录
- --exclude :逗号分隔的排除模式
- --output :将 JSON 输出保存到文件
- --no-progress:禁用进度条示例:
-
dir-cli check
- dir-cli check --depth 3
- dir-cli check --format json --output status.json
- dir-cli check --exclude "temp,cache"$3
智能清理依赖与构建产物。用法:
dir-cli clean [type] [options]类型:
-
node:node_modules、dist、.next、.nuxt
- python:__pycache__、.pytest_cache、dist、build、venv、.venv
- java:target、build、.gradle、out、logs、dist
- rust:target
- go:bin、dist、build、coverage.out(注意:默认不清理 vendor/)
- all:清理以上所有类型选项:
-
--dry-run:预览将要清理的内容,不实际删除
- --interactive:交互式选择要清理的项目
- --yes:跳过确认提示
- --no-progress:禁用进度条
- --include-hidden:扫描时包含隐藏目录
- --exclude :逗号分隔的排除模式
- --format :table | json | plain(默认:table)示例:
-
dir-cli clean
- dir-cli clean node --dry-run
- dir-cli clean python --yes
- dir-cli clean all --interactive$3
基于实时扫描结果生成迁移/状态报告。用法:
dir-cli report [type] [options]类型:
-
status:项目状态报告
- migration:迁移准备度报告(当前与 status 数据一致,展示角度不同)选项:
-
--format :html | json | markdown(默认:html)
- --output :输出文件路径示例:
-
dir-cli report status --format html --output status.html
- dir-cli report migration --format markdown --output migration.md
- dir-cli report status --format json --output status.json$3
管理配置。用法:
dir-cli config [action] [key] [value]动作:
-
list:打印全部配置
- get :读取配置
- set :设置配置(支持点号路径,如 scan.maxDepth)
- reset:重置为默认示例:
-
dir-cli config list
- dir-cli config get scan.maxDepth
- dir-cli config set scan.maxDepth 5
- dir-cli config set clean.defaultSelectAll false
- dir-cli config reset$3
语言设置。用法:
-
dir-cli locale --current
- dir-cli locale --list
- dir-cli locale (如 en、zh-CN)🔧 支持的项目类型
| 类型 | 识别方式 | 清理目标 | 说明 |
|------|----------|----------|------|
| Node.js |
package.json | node_modules、dist、.next、.nuxt | 支持 npm/yarn/pnpm/bun |
| Python | requirements.txt、setup.py、pyproject.toml、Pipfile | __pycache__、.pytest_cache、dist、build、venv、.venv | |
| Java | pom.xml、build.gradle(.kts) | target、build、.gradle、out、logs、dist | Maven/Gradle |
| Rust | Cargo.toml | target | Cargo 构建产物 |
| Go | go.mod | bin、dist、build、coverage.out | 默认不清理 vendor/ |🛡️ 安全机制
- 白名单:仅删除白名单内路径(如
node_modules、target、.gradle、bin 等)
- 路径校验:防止越界删除,仅在项目根内操作
- 符号链接:跳过符号链接
- Dry-run:先预览再执行,避免误删
- 故障隔离:个别项目失败不影响其他项目
- 安全日志:控制台输出,可扩展到文件⚙️ 配置(摘录)
`json
{
"scan": {
"maxDepth": "unlimited",
"excludeDirs": [".git", ".cache", ".tmp", "temp", ".DS_Store", "Thumbs.db"],
"includeHidden": false,
"concurrent": 10,
"ignoreSymlinks": true
},
"git": {
"checkUncommitted": true,
"checkUnpushed": true,
"checkRemote": true,
"checkConflicts": true,
"defaultBranch": "main",
"ignoreFiles": [".DS_Store", "Thumbs.db", "*.log"]
},
"clean": {
"defaultSelectAll": true,
"showPreview": true,
"logOperations": true,
"logPath": "~/.dir-cli/logs",
"enabledCleaners": ["node", "python", "java", "rust", "go"]
},
"output": {
"format": "table",
"showProgress": true,
"colorful": true,
"verbose": false,
"locale": "auto"
}
}
`通过
dir-cli config 管理配置。🔍 使用示例
- 迁移准备
-
dir-cli check --format json --output migration-status.json
- dir-cli clean all --dry-run
- dir-cli clean all --yes
- dir-cli report migration --format html --output migration-report.html- 磁盘清理
-
dir-cli clean node --dry-run
- dir-cli clean python --interactive- CI 集成
-
dir-cli check --format json > status.json
- dir-cli report status --format markdown --output status.md🌍 国际化
内置:
en、zh-CN、zh-TW、ja、ko、es、fr、de、ru。
使用 dir-cli locale 管理语言。❗ 故障排查
- Windows/WSL:建议在项目所在的同一文件系统中运行
- 权限:确保对清理目标具有写权限
- 建议:先用
--dry-run` 预览再执行MIT