New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

tree-cli-tool

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-cli-tool

A powerful command-line tool to display directory tree structure with various configuration options and output formats

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Tree CLI Tool

CI npm version codecov License: MIT

一个功能强大的命令行工具,用于显示目录树状结构,支持多种配置选项和输出格式。

安装

npm install -g tree-cli-tool

基本用法

# 显示当前目录的树状结构
tree-cli

# 显示指定目录的树状结构
tree-cli /path/to/directory

# 限制遍历深度
tree-cli -d 3

# 显示文件大小
tree-cli -s

# 输出为 JSON 格式
tree-cli -f json

# 排除特定文件/目录
tree-cli -e "node_modules" "*.log" ".git"

命令选项

基本选项

  • [path] - 目标目录路径(默认:当前目录)
  • -d, --max-depth <number> - 最大遍历深度,-1 表示无限制(默认:-1)
  • -f, --format <type> - 输出格式:text|json|markdown(默认:text)

过滤选项

  • -e, --exclude <patterns...> - 排除模式(支持 glob 风格)
  • --include-types <types...> - 只包含指定文件类型(扩展名)
  • --exclude-types <types...> - 排除指定文件类型(扩展名)
  • -i, --ignore-pattern <regex> - 正则表达式忽略模式

显示选项

  • -a, --show-hidden - 显示隐藏文件和目录
  • -s, --show-size - 显示文件大小
  • --show-date - 显示修改时间
  • -D, --dirs-only - 只显示目录
  • --no-color - 禁用彩色输出

输出选项

  • -o, --output <file> - 输出到文件而不是标准输出

预设命令

quick 命令

快速查看目录结构,自动排除常见的构建目录:

tree-cli quick [path] [-d depth]

自动排除:node_modules, .git, dist, build, .next, .nuxt

dev 命令

开发者友好的视图,排除更多构建和缓存目录:

tree-cli dev [path] [-d depth]

自动排除:node_modules, .git, dist, build, .next, .nuxt, coverage, .nyc_output, .cache, tmp, temp, *.log, .DS_Store, Thumbs.db

使用示例

1. 基本目录树

tree-cli

2. 限制深度并显示文件大小

tree-cli -d 2 -s

3. 只显示 JavaScript 和 TypeScript 文件

tree-cli --include-types js ts jsx tsx

4. 排除特定目录和文件类型

tree-cli -e "node_modules" "dist" --exclude-types log tmp

5. 输出为 JSON 格式

tree-cli -f json -o tree.json

6. 使用正则表达式排除文件

tree-cli -i "test.*\\.js$"

7. 开发者模式查看项目结构

tree-cli dev -d 3

输出格式

Text 格式(默认)

project/
├── src/
│   ├── components/
│   │   └── Button.tsx
│   └── index.ts
├── package.json
└── README.md

2 directories, 3 files

JSON 格式

{
  "tree": {
    "name": "project",
    "path": "/path/to/project",
    "isDirectory": true,
    "children": [...]
  },
  "stats": {
    "totalFiles": 3,
    "totalDirectories": 2,
    "totalSize": 1024
  }
}

Markdown 格式

# Directory Tree: project

- **project**/
  - **src**/
    - **components**/
      - Button.tsx
    - index.ts
  - package.json
  - README.md

## Statistics

- **Directories**: 2
- **Files**: 3

作为 Node.js 模块使用

import { generateTree } from 'tree-cli-tool';

const result = await generateTree({
  path: './my-project',
  maxDepth: 3,
  format: 'json',
  exclude: ['node_modules', '.git'],
  showSize: true,
});

console.log(result.formatted);
console.log('Stats:', result.stats);

开发

本地开发

# 克隆仓库
git clone https://github.com/oyal/tree-cli-tool.git
cd tree-cli-tool

# 安装依赖
npm install

# 开发模式运行
npm run dev

# 构建项目
npm run build

# 运行测试
npm test

# 代码格式化
npm run format

# 检查代码格式
npm run format:check

代码质量保证

项目配置了以下代码质量工具:

  • Prettier: 代码格式化
  • GitHub Actions: 自动化 CI/CD 流程

代码质量检查 在以下时机自动运行:

  • GitHub Actions CI 流程中
  • 发布前自动检查(prepublishOnly)

发布流程

本项目使用 GitHub Actions 自动化发布流程:

  • 自动发布 (推荐):

    • 进入 GitHub Actions 页面
    • 选择 "Publish" 工作流
    • 选择版本类型 (patch/minor/major)
    • 点击运行
  • 手动发布

    npm version patch  # 或 minor, major
    git push origin main --tags
    

贡献指南

  • Fork 本仓库
  • 创建功能分支 (git checkout -b feature/amazing-feature)
  • 提交更改 (git commit -m 'Add some amazing feature')
  • 推送到分支 (git push origin feature/amazing-feature)
  • 创建 Pull Request

许可证

MIT

Keywords

tree

FAQs

Package last updated on 10 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts