Skip to content

Repository files navigation

Forge Tree

npm versionLicense: MITNode.js Version

A powerful tool to scaffold project structures from ASCII tree diagrams. Supports smart detection of project types, custom templates, and extensive configuration options.

Documentation

Getting Started

Core Concepts

Logging and Analysis

Example Configurations

Advanced Topics

Guides and References

Development

Features

  • 🌳 Parse ASCII tree diagrams into real directory structures
  • 🔍 Smart project type detection (Next.js, Firebase, etc.)
  • 🎨 Support for multiple tree styles and formats
  • 📝 Extensive commenting capabilities
  • 🛠️ Custom initializers and templates
  • 📊 Detailed project statistics
  • 📋 Progress tracking and validation
  • 🔄 Git integration

Requirements

  • Node.js >= 18.0.0

Installation

# Global installation (recommended)
npm install -g forge-tree
# Local installation
npm install forge-tree
# Development setup
git clone https://github.com/Cleman25/forge-tree.git
cd forge-tree
npm ci
npm run build
npm link # Makes the CLI available globally

Quick Start

# Create a new project
forge-tree my-project --tree "my-project/\n src/\n package.json"# Use a tree file
forge-tree --tree-file project.tree
# Enable all features
forge-tree --detectors --dotfiles --git
# Create GitHub repo
forge-tree my-project --github --private

Basic Usage

forge-tree [targetDir] --tree-file path/to/tree.txt
# or
forge-tree [targetDir] --tree "root/\n child/"

Tree File Format

Basic Structure

project/
├─ src/
│ ├─ index.ts
│ └─ types.ts
├─ test/
│ └─ index.test.ts
└─ package.json

Alternative Styles

Simple style:

project/
- src/
- index.ts
- types.ts
- test/
- index.test.ts
- package.json

Custom characters:

project/
+-- src/
| +-- index.ts
| `-- types.ts
+-- test/
| `-- index.test.ts
`-- package.json

Comments

Multiline comments at start/end:

"""
Project description
Multiple lines allowed
"""
project/
├─ src/
│ ├─ index.ts # Main entry
│ └─ types.ts // Type definitions
├─ test/ /* Test directory */
└─ package.json
/*
Additional notes
Can go here
*/

Alternative comment styles:

#
Project description
Using hash style
#
project/
...
/**
* Project description
* Using JSDoc style
*/
project/
...

Smart Detectors

Built-in detectors automatically set up:

Web Applications

  • Next.js apps (web, app, frontend directories)
  • Firebase projects (firebase, functions directories)

Services

  • Backend services (service, api, server directories)
  • Real-time services (realtime, socket directories)

Libraries

  • TypeScript libraries (lib, package, sdk directories)
  • UI components (ui, components, design-system directories)

Infrastructure

  • Database setup (db, database, sql, mongo directories)
  • Docker/K8s (infra, deploy, ops directories)

Configuration

  • TypeScript config (config, tsconfig directories)
  • ESLint/Prettier (eslint, prettier directories)

Custom Initializers

Adding Initializers via CLI

# Add a new initializer
forge-tree --add-init \
--init-id "redis-init" \
--init-name "Redis Setup" \
--init-desc "Initialize Redis with default config" \
--init-cmd "redis-cli" \
--init-args "ping" \
--init-match-dirs "redis,cache" \
--init-match-files "redis.conf" \
--init-env "REDIS_PORT=6379" \
--init-workdir "target"# Add target directories for an initializer
forge-tree --add-init-target \
--init-id "redis-init" \
--target-dirs "services/cache,infra/redis"# List all initializers
forge-tree --list-init
# Remove an initializer
forge-tree --remove-init "redis-init"

Configuration File

You can also define initializers in your config:

{
"customInitializers": [
{
"id": "redis-init",
"name": "Redis Setup",
"description": "Initialize Redis with default config",
"command": "redis-cli",
"args": ["ping"],
"matchDirs": ["redis", "cache"],
"matchFiles": ["redis.conf"],
"env": {
"REDIS_PORT": "6379"
},
"workingDir": "target"
}
],
"initTargets": [
{
"initId": "redis-init",
"targetDirs": ["services/cache", "infra/redis"]
}
]
}

Using Custom Initializers

# Use specific initializers
forge-tree --tree-file project.tree --use-init "redis-init,mongo-init"# Skip specific initializers
forge-tree --tree-file project.tree --skip-init "firebase-init"# Run only custom initializers
forge-tree --tree-file project.tree --only-custom-init

Configuration Options

Command Line Options

Options:
--tree-file Path to ASCII tree file
--tree ASCII tree string (quoted)
--targetDir Where to scaffold (default: ".")
--tabIndentationSize Spaces per depth level (default: 2)
--detectAsciiGuides Skip │ ├ └ guides (default: true)
--dry-run Print actions only
--yes, -y Assume yes for prompts
--pm Preferred package manager (pnpm|yarn|npm)
--detectors Enable smart detectors (default: true)
--dotfiles Generate ignores/formatters (default: true)
--git Initialize git repo
--github Create GitHub repo
--private Create private GitHub repo
--no-push Don't push after creating remote --branch Initial branch name (default: "main") --log Enable logging (default: true) --log-file Log file path --log-level Log level (silent|error|warn|info|debug|verbose) --log-format Log format (text|json) --quiet Suppress console output --show-tree Show input tree structure (default: true) --show-result Show generated structure (default: true) --allowNestedInit Allow initialization in nested directoriesInitializer Management: --add-init Add a new custom initializer --init-id ID for the new initializer --init-name Display name for the initializer --init-desc Description of what the initializer does --init-cmd Command to run --init-args Command arguments (comma-separated) --init-match-dirs Directories to match (comma-separated) --init-match-files Files to check for (comma-separated) --init-env Environment variables (KEY=VALUE,...) --init-workdir Working directory (root|target) --add-init-target Add target directories for an initializer --target-dirs Directories to target (comma-separated) --list-init List all available initializers --remove-init Remove a custom initializer --use-init Use specific initializers (comma-separated) --skip-init Skip specific initializers (comma-separated) --only-custom-init Run only custom initializers

Tree Style Configuration

{
"treeStyle": {
"indent": "",
"vertical": "",
"horizontal": "",
"corner": "",
"branch": ""
}
}

Logging Configuration

{
"logging": {
"enabled": true,
"level": "info",
"file": "forge-tree.log",
"console": true,
"format": "text",
"includeTimestamps": true,
"includeDuration": true,
"includeMetadata": true
}
}

Example Structures

Monorepo Setup

monorepo/
├─ apps/
│ ├─ web/
│ │ ├─ src/
│ │ └─ package.json
│ └─ api/
│ ├─ src/
│ └─ package.json
├─ packages/
│ ├─ ui/
│ │ ├─ src/
│ │ └─ package.json
│ └─ utils/
│ ├─ src/
│ └─ package.json
├─ config/
│ ├─ tsconfig/
│ └─ eslint/
└─ package.json

Next.js Project

web-app/
├─ app/
│ ├─ layout.tsx
│ ├─ page.tsx
│ └─ blog/
│ └─ [slug]/
│ └─ page.tsx
├─ components/
│ └─ Button.tsx
├─ lib/
│ └─ utils.ts
└─ package.json

Backend Service

service/
├─ src/
│ ├─ index.ts
│ ├─ routes/
│ ├─ models/
│ └─ utils/
├─ test/
│ └─ api.test.ts
├─ prisma/
│ └─ schema.prisma
└─ package.json

Statistics and Analysis

The tool provides comprehensive logging and analysis capabilities through its built-in log viewer:

Log Viewer

  • Real-time Monitoring:

    • Live log tailing with automatic updates
    • In-memory and browser cache storage
    • Automatic visualization switching
    • Status indicators and progress tracking
  • Interactive Visualizations:

    • Timeline charts with operation durations
    • Treemap views of operation distribution
    • Gantt diagrams for process flow
    • Network graphs for dependencies
    • Auto-updating during tailing
    • Collapsible sections and entries
  • Data Management:

    • Text and JSON format support
    • Browser localStorage caching
    • No server dependency
    • Automatic data parsing
    • Memory-efficient storage
  • User Interface:

    • Dark/light theme support
    • Collapsible sections
    • Custom scrollbars
    • Path highlighting
    • Duration formatting
    • Pretty-printed JSON
    • Responsive design
  • Analysis Tools:

    • Full-text search
    • Log level filtering
    • Performance metrics
    • Success rate tracking
    • Operation statistics
    • Export options (PDF, CSV, JSON)
  • File System Stats:

    • Directory operations tracking
    • File operation monitoring
    • Initializer success rates
    • Real-time updates
    • Visual progress indicators

Project Statistics

The tool generates detailed statistics about your project structure:

  • Total directories and files
  • Maximum directory depth
  • Empty directories count
  • Average files per directory
  • Largest directory
  • Root level structure
  • Language breakdown
  • File categories (source, config, test, etc.)
  • File extensions

Statistics are saved to forge-tree.stats.json and can be viewed through:

  • Console output with progress bars
  • Interactive web viewer
  • JSON export for further analysis

Viewing Logs and Stats

# View both logs and stats
forge-tree view --log --with-stats
# View only logs
forge-tree view --log forge-tree.log
# View only stats
forge-tree view --stats forge-tree.stats.json
# List recent files
forge-tree view --list
# Browser preferences
forge-tree view --browser chrome --incognito

See the Log Viewer Guide for more details.

Generated Structure Display

After generation, the tool shows:

  • The actual generated structure
  • Comparison with expected structure
  • Missing and additional items
  • Completion percentage
  • Placeholders for large directories (e.g., node_modules/)

Error Handling

The tool validates:

  • Tree structure syntax
  • Comment formatting
  • Node name validity
  • Directory depth consistency
  • Path uniqueness
  • Comment block closure

Command Line Help

CategoryCommandDescriptionExample
Basic Usage
--treeDirect tree string input--tree "root/\n child/"
--tree-fileRead tree from file--tree-file project.tree
--targetDirOutput directory--targetDir ./output
Tree Formatting
--tabIndentationSizeSpaces per level--tabIndentationSize 4
--detectAsciiGuidesParse tree characters--detectAsciiGuides false
--treeStyleCustom tree charactersSee Tree Style Configuration
Project Setup
--pmPackage manager--pm pnpm
--detectorsEnable smart detection--detectors true
--dotfilesGenerate config files--dotfiles true
Git Integration
--gitInitialize repository--git
--githubCreate GitHub repo--github "repo-name"
--privatePrivate repository--private
--branchInitial branch name--branch main
--no-pushSkip initial push--no-push
Logging
--logEnable logging--log true
--log-fileLog file path--log-file "forge.log"
--log-levelLog verbosity--log-level debug
--log-formatLog output format--log-format json
--quietSuppress console--quiet
Log Viewer
view --logView log fileview --log forge-tree.log
view --statsView stats fileview --stats forge-tree.stats.json
view --with-logInclude logsview --stats --with-log
view --with-statsInclude statsview --log --with-stats
view --listList recent filesview --list
view --cleanupClean cacheview --cleanup
view --browserBrowser preferenceview --browser chrome
view --incognitoPrivate modeview --incognito
Display
--show-treeShow input structure--show-tree
--show-resultShow output structure--show-result
Initialization
--allowNestedInitAllow nested inits--allowNestedInit
--add-initAdd custom initializerSee Custom Initializers
--use-initUse specific inits--use-init "redis,mongo"
--skip-initSkip specific inits--skip-init "firebase"
--only-custom-initCustom inits only--only-custom-init
Other
--dry-runPreview actions--dry-run
--yesAuto-confirm prompts--yes
--helpShow help--help

Architecture

graph TD
A[CLI Input] --> B[Parser]
B --> C[Validator]
C --> D[Detector Manager]
D --> E[Generator]
E --> F[Action Executor]
F --> G[Post Processor]
Loading

Development Guide

Adding Features

  1. New Detector

    exportconstMyDetector: Detector={id: "my-detector",match: (node,cfg)=>boolean,prompt: async(node)=>boolean,generate: async(node,cfg)=>GeneratorResult};
  2. New Generator

    exportconstMyGenerator={createActions: (node: TreeNode): PlanAction[]=>{return[{type: "mkdir",path: "..."},{type: "write",path: "...",content: "..."}];}};
  3. New Command

    yargs.command('my-command','Description',{// options},async(argv)=>{// handler});

Testing

  1. Unit Tests

    # Run specific test
    npm test -- src/__tests__/my.test.ts
    # Watch mode
    npm run test:watch
  2. Integration Tests

    # E2E tests
    npm test -- src/__tests__/e2e.test.ts
  3. Coverage

    npm run ci:test

Scripts

# Build the project
npm run build
# Watch mode during development
npm run dev
# Run tests
npm test
npm run test:watch
# Release commands
npm run release:patch # Bump patch version
npm run release:minor # Bump minor version
npm run release:major # Bump major version# CI/CD commands
npm run ci # Full CI pipeline
npm run ci:verify # Run all checks
npm run ci:lint # Run linting
npm run ci:test # Run tests with coverage
npm run ci:build # Production build
npm run ci:clean # Clean build artifacts
npm run ci:audit # Security audit# Local development
npm run local# Install, build, and link locally

Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests to our GitHub repository.

Support

License

MIT © Clement Abel

About

A powerful tool to scaffold project structures from ASCII tree diagrams. Supports smart detection of project types, custom templates, and extensive configuration options.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages