meta-bonsai generates a pruned ASCII tree that highlights only developer-marked files and directories, keeping ancestor paths to preserve structure.
- Generate a pruned ASCII tree that focuses on marked files and directories
- Preserve ancestor paths so the output stays navigable and keeps context
- Keep trees readable for sharing in docs, reviews, and discussions
- Respect
.gitignoreand extra ignore patterns to match real project workflows - Provide both a CLI and a library API for scripting and integration
This package is intended to be used via npx meta-bonsai or as a library dependency in Node.js projects.
- Run in the current directory:
npx meta-bonsai - Run with a target path:
npx meta-bonsai ./src - Ignore paths (repeatable or comma-separated):
--ignore dist --ignore node_modules,coverage
If no marked nodes are found, the CLI prints a friendly message and exits normally.
When marked nodes exist, it prints a pruned ASCII tree:
project
├── src // core
│ └── main.ts // entry
└── README.md // docs
- Directory: create
__meta.jsonunder the directory and setdescorname - File: start the file with
/** @meta Description */
Only .ts, .tsx, .js, .jsx, and .vue files are scanned for file-level marks.
Place it in the directory. Valid JSON; desc takes precedence over name:
{ "desc": "core business" }Or use name only:
{ "name": "src" }When both exist, desc is used: { "name": "src", "desc": "core business" } → displays "core business".
Must be at the very beginning of the file (no characters, including newlines, before /**). Only .ts, .tsx, .js, .jsx, and .vue are scanned:
/** @meta page entry */
/** @meta entry */
If there is a newline or any content before the comment, it will not match.
Exports are available from the package root:
scanAndPruneTree: scan a directory and return a pruned treerenderTree: render a pruned tree as ASCIIcreateIgnoreMatcher: build an ignore matcher from.gitignoreplus CLI patternsparseMetaComment: parse@metafrom a file prefixparseMetaJson: parse__meta.jsonMetaNode,IgnoreMatcher: exported types
import { scanAndPruneTree, renderTree, createIgnoreMatcher } from "meta-bonsai";
// Basic usage: scan a directory and print
const tree = await scanAndPruneTree("./src");
if (tree) {
console.log(renderTree(tree));
}
// With custom ignore rules (.gitignore + extra patterns)
const ignoreMatcher = await createIgnoreMatcher(".", ["dist", "coverage"]);
const tree2 = await scanAndPruneTree(".", { ignoreMatcher });
if (tree2) {
console.log(renderTree(tree2));
}- Run tests:
npm test - Build:
npm run build - Typecheck:
npm run typecheck
MIT