npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@haiyanwang/mindmap-cli

v0.3.0

Published

CLI tool for manipulating .xmind mind map files and Mermaid diagrams

Readme

mindmap-cli

English | 中文

一个用于在终端中操作 .xmind 思维导图文件和 Mermaid 图表的 CLI 工具。

安装

npm install -g @haiyanwang/mindmap-cli

或者免安装直接使用:

npx @haiyanwang/mindmap-cli <command>

Mermaid 导出 PNG

如需将 Mermaid 图表导出为 PNG,请全局安装 Mermaid CLI:

npm install -g @mermaid-js/mermaid-cli

使用方法

命令行工具可通过 mindmap-cli 或短别名 mm 调用。

在终端中预览思维导图

mm view <file.xmind> [-d depth] [-s sheet]
  • -d, --depth <n> - 最大显示深度
  • -s, --sheet <名称|索引> - 选择指定的工作表

将 xmind 转换为 Markdown

mm to-md <file.xmind> [-o output.md] [-s sheet]

默认输出到同目录下的 <文件名>.md

将 Markdown 转换为 xmind

mm from-md <file.md> [-o output.xmind]

根据标题层级(######)和列表项构建思维导图树。

导出为 PNG 或 PDF

mm export <file.xmind> -f <png|pdf> [-o dir] [-s sheet] [--all]
  • -f, --format <png|pdf> - 输出格式(必填)
  • -o, --output <dir> - 输出目录
  • -s, --sheet <名称|索引> - 选择指定的工作表
  • --all - 导出所有工作表

批量查找替换

mm replace <file.xmind> --find <text> --replace <text> [-o output] [--regex] [--fields title,note,labels]
  • --find <text> - 要查找的文本
  • --replace <text> - 替换文本
  • --regex - 将 --find 作为正则表达式处理
  • --fields <fields> - 逗号分隔的搜索字段列表(默认:title,note,labels

Mermaid 图表转换

mm mermaid <file> [-o output] [-f format] [-s sheet]

支持三种转换模式:

Mermaid 思维导图 → xmind:

mm mermaid diagram.mmd -o output.xmind
# 或直接运行(自动检测 mindmap 类型):
mm mermaid diagram.mmd

Mermaid 图表 → PNG(UML、流程图、时序图等):

mm mermaid diagram.mmd -f png -o output.png

xmind → Mermaid 思维导图:

mm mermaid file.xmind -o output.mmd
# 或指定工作表:
mm mermaid file.xmind -s "Sheet Name" -o output.mmd

支持的 Mermaid 图表类型

所有 Mermaid 图表类型均可导出为 PNG:

  • 思维导图 (Mindmap) - 也可双向转换为 xmind
  • 流程图 (Flowchart) - graph TD; A-->B
  • 时序图 (Sequence) - sequenceDiagram; A->>B: msg
  • 类图 (Class) - classDiagram; class Animal
  • 状态图 (State) - stateDiagram-v2; [*] --> Active
  • ER 图 - erDiagram; CUSTOMER ||--o{ ORDER : places
  • 甘特图 (Gantt) - gantt; section S; task: d, 2024-01-01, 7d
  • 饼图 (Pie) - pie title Pets; "Dogs" : 386
  • 以及更多...

Mermaid 思维导图语法

思维导图格式使用缩进来定义层级结构:

mindmap
  ((根节点))
    分支 A
      叶子 A1
      叶子 A2
    分支 B
      叶子 B1

节点形状:

  • ((文本)) - 圆形
  • [文本] - 矩形
  • (文本) - 圆角矩形
  • [[文本]] - 六边形
  • (((文本))) - 爆炸形

使用示例

# 在终端中预览思维导图
mm view project.xmind

# 限制显示深度
mm view project.xmind -d 2

# 转换为 Markdown
mm to-md project.xmind -o notes.md

# 从 Markdown 创建思维导图
mm from-md notes.md

# 将所有工作表导出为 PNG
mm export project.xmind -f png --all

# 批量替换文本
mm replace project.xmind --find "旧文本" --replace "新文本"

# 将 Mermaid 思维导图转换为 xmind
mm mermaid diagram.mmd

# 将 UML 图导出为 PNG
mm mermaid architecture.mmd -f png -o architecture.png

# 将 xmind 导出为 Mermaid 思维导图
mm mermaid project.xmind -o project.mmd

技术栈

  • TypeScript (ES2022, ESM)
  • commander - CLI 框架
  • jszip - .xmind ZIP 归档处理
  • markmap-lib - Markdown 解析为思维导图
  • sharp - SVG 转 PNG 光栅化
  • pdf-lib - PDF 生成
  • xmind-generator - .xmind 文件创建
  • @mermaid-js/mermaid-cli - Mermaid 图表渲染
  • picocolors - 终端彩色输出
  • ora - 终端加载动画

项目结构

src/
├── index.ts                  CLI 入口
├── commands/                 命令处理器
│   ├── view.ts               终端预览
│   ├── to-md.ts              xmind → Markdown
│   ├── from-md.ts            Markdown → xmind
│   ├── export.ts             PNG/PDF 导出
│   ├── replace.ts            批量查找替换
│   └── mermaid.ts            Mermaid 转换
├── core/                     核心数据处理
│   ├── model.ts              数据模型(MindNode/MindSheet/MindWorkbook)
│   ├── xmind-reader.ts       .xmind 文件读取
│   ├── xmind-writer.ts       .xmind 文件写入
│   ├── markdown.ts           Markdown → MindWorkbook
│   └── tree-utils.ts         树遍历工具
├── renderers/                输出渲染器
│   ├── terminal-tree.ts      终端彩色树形图
│   ├── markdown-renderer.ts  MindNode → Markdown
│   ├── svg-mindmap.ts        MindNode → SVG
│   └── mermaid-renderer.ts   MindNode → Mermaid 语法
├── exporters/                文件导出器
│   ├── png-exporter.ts       SVG → PNG
│   └── pdf-exporter.ts       SVG → PNG → PDF
└── utils/                    工具函数
    ├── errors.ts             自定义错误类
    └── file.ts               文件路径工具

许可证

Apache-2.0