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

md-aggregator

v1.0.0

Published

A command-line tool for aggregating Markdown file contents. It can recursively search for Markdown files in directories, process them according to configuration options, and merge all file contents into a single output file.

Downloads

2

Readme

md-aggregator

项目简介

md-aggregator 是一个用于聚合 Markdown 文件内容的命令行工具。它能够递归搜索目录中的 Markdown 文件,根据配置选项进行处理,并将所有文件内容合并为一个输出文件。

功能特性

  • 递归搜索目录中的 Markdown 文件
  • 支持包含和排除特定文件或目录
  • 可配置的文件排序(按名称、修改时间、文件大小)
  • 可自定义的标题级别和模板
  • 支持多种写入模式(覆盖或追加)
  • 可配置的文件分隔符
  • 详细的日志输出

安装

确保您已经安装了 Node.js 和 pnpm,然后运行:

pnpm install -g md-aggregator

或者,您可以直接使用 npx 运行:

npx md-aggregator [options]

使用方法

基本用法

md-aggregator [输入目录] [输出文件]

示例:

# 聚合当前目录中的所有 Markdown 文件,输出到 output.md
md-aggregator . output.md

# 聚合指定目录中的 Markdown 文件
md-aggregator ./docs ./docs/aggregated.md

命令行选项

| 选项 | 描述 | 默认值 | |------|------|--------| | -w, --writeType <type> | 写入类型 (append 或 write) | write | | -s, --separator <separator> | 文件分隔符 | \n\n----\n\n | | -t, --titleLevel <level> | 标题级别 (1-6) | 1 | | -T, --titleTemplate <template> | 标题模板 | # {fileName} | | --insertFileName | 插入文件名作为标题 | false | | -i, --include <files> | 包含文件模式 (正则表达式) | [] | | -e, --exclude <files> | 排除文件模式 (正则表达式) | [] | | -b, --sortBy <sortBy> | 排序依据 (name, modified, size) | name | | -p, --sortPartten <sortPartten> | 排序模式 (asc, desc) | asc | | -l, --useLog | 启用日志输出 | false |

使用示例

1. 基本聚合

# 聚合当前目录中的所有 Markdown 文件
md-aggregator . output.md

2. 插入文件名作为标题

# 为每个文件内容添加文件名作为标题
md-aggregator . output.md --insertFileName --titleLevel 2

3. 包含和排除特定文件

# 只包含以 "doc" 开头的文件
md-aggregator . output.md --include "^doc.*\.md$"

# 排除以 "test" 开头的文件
md-aggregator . output.md --exclude "^test.*\.md$"

4. 文件排序

# 按修改时间排序(最新优先)
md-aggregator . output.md --sortBy modified --sortPartten desc

# 按文件大小排序(最大优先)
md-aggregator . output.md --sortBy size --sortPartten desc

5. 自定义分隔符和标题模板

# 使用自定义分隔符和标题模板
md-aggregator . output.md --separator "\n\n---\n\n" --titleTemplate "## {fileName} (文档)"

API 使用

除了命令行工具,您也可以在代码中使用 md-aggregator:

import aggregate from 'md-aggregator';

const result = aggregate({
  inputDir: './docs',
  outputFile: './docs/output.md',
  insertFileName: true,
  titleLevel: 2,
  sortBy: 'modified',
  sortPartten: 'desc',
  useLog: true
});

if (result.success) {
  console.log(`聚合成功,输出文件: ${result.outputFile}`);
} else {
  console.error(`聚合失败: ${result.errorMsg}`);
}