A powerful CLI for directory visualization, generation, and analysis, designed for developers and testers.
For complete documentation with all options and detailed examples, see DOCUMENTATION.md
# Install globally
npm install -g treecraft
# Or use directly from the repo
git clone https://github.com/TheAlphamerc/treecraft.git
cd treecraft
npm install
npm run build
Visualize directory structure in various formats.
-m, --mode <mode>
: Visualization mode [default: tree]tree
: Traditional ASCII tree structuregraph
: Hierarchical graph with weighted brancheslist
: Flat list of all pathsinteractive
: Browse directories and files interactively
-d, --depth <n>
: Limit depth (e.g., 2)-e, --exclude <patterns>
: Exclude patterns (comma-separated, e.g., "node_modules,dist")-f, --filter <patterns>
: Filter patterns (comma-separated, e.g., ".ts,.js")-c, --color
: Enable colored output-x, --export <format>
: Export as text, json, or yaml--with-metadata
: Include size and modification time-o, --output-file <file>
: Write output to file
Examples:
# Default tree view with colors
treecraft viz . -c
# Graph visualization with metadata
treecraft viz ./src -m graph --with-metadata
# Interactive directory browser
treecraft viz . -m interactive
# Export filtered JSON
treecraft viz ./src -f "*.ts" -x json -o src.json
# Limit depth and exclude directories
treecraft viz . -d 1 -e "dist,node_modules"
Generate directory structure from a specification file.
-o, --output <path>
: Output directory (required)-s, --skip-all
: Skip existing files/directories-w, --overwrite-all
: Overwrite existing files/directories
Supported Input Formats:
- JSON: Nested object structure
- YAML: Nested object structure
- Text: ASCII tree format
Examples:
# Generate from JSON specification
treecraft gen spec.json -o ./project
# Generate with conflict resolution
treecraft gen spec.yaml -o ./project -s # Skip existing files
# Generate with overwrite
treecraft gen spec.txt -o ./project -w # Overwrite existing files
Example Specification (JSON):
{
"src": {
"index.ts": "console.log('Hello World');",
"utils": {
"helpers.ts": "export function add(a, b) { return a + b; }"
}
},
"package.json": "{\"name\": \"example\", \"version\": \"1.0.0\"}"
}
Analyze and display directory statistics.
-s, --size-dist
: Show size distribution (<1KB, 1KB-1MB, >1MB)-x, --export <format>
: Export as text, json, or yaml-f, --filter <patterns>
: Filter patterns (comma-separated)-e, --exclude <patterns>
: Exclude patterns (comma-separated)-d, --depth <n>
: Limit depth for statistics-t, --file-types
: Show file type breakdown-r, --sort <key>
: Sort distribution by size or count [default: count]
Examples:
# Basic statistics
treecraft stats .
# Comprehensive statistics for JavaScript files
treecraft stats . -s -t -f "*.js"
# Export statistics as JSON
treecraft stats . -x json -o stats.json
# Sort size distribution by size
treecraft stats . -s -r size
Search for files by name.
-t, --ext <extension>
: Filter by file extension (e.g., ".ts", ".js")-d, --depth <n>
: Limit search depth-f, --filter <patterns>
: Include only specific patterns-e, --exclude <patterns>
: Exclude patterns-x, --export <format>
: Export results as text, json, or yaml
Examples:
# Basic search
treecraft search . utils
# Search only TypeScript files
treecraft search . utils -t ".ts"
# Export search results
treecraft search . config -x yaml > results.yaml
The default visualization mode, displaying a traditional ASCII tree structure.
├── src
│ ├── components
│ │ └── Button.tsx
│ └── index.ts
└── package.json
A hierarchical graph with weighted branches. Larger directories are shown first.
Root
├── src
│ ├── components
│ │ └── Button.tsx
│ └── index.ts
└── package.json
With metadata:
Root
├── src [D, 4096B]
│ ├── components [D, 4096B]
│ │ └── Button.tsx [F, 256B]
│ └── index.ts [F, 128B]
└── package.json [F, 512B]
A flat list of all paths in the directory structure.
src
src/components
src/components/Button.tsx
src/index.ts
package.json
An interactive browser that allows navigation through the directory structure using arrow keys and Enter.
- JSON: Nested object structure
- YAML: Nested object structure
- Text: ASCII tree format
- Text: Human-readable formatted output
- JSON: Machine-readable JSON format
- YAML: Human-readable YAML format
TreeCraft provides detailed error messages for various scenarios:
- Invalid paths or non-existent directories
- Permission issues
- Format validation errors
- Input/output conflicts
For complete documentation of all features, options, and advanced usage examples, refer to DOCUMENTATION.md.
- Clone:
git clone https://github.com/TheAlphamerc/treecraft.git
- Install:
npm install
- Build:
npm run build
- Test:
npm test
The project uses Jest for testing. Run tests with:
npm test # Run all tests
npm test -- [pattern] # Run specific tests