Autofold

Create directory and file structures from any input format. Transform ASCII trees, JSON objects, or path arrays into real filesystem structures.

Terminal
$bunx autofold@latest -f tree "project..."
✨ Creating directory structure...
✅ Structure created successfully!

Multiple Input Formats

Autofold supports various input formats to match your workflow

ASCII Tree Strings

Convert beautiful ASCII tree diagrams directly into folder structures

JSON Objects

Use nested or flat JSON objects to define your directory structure

Path Arrays

Simple arrays of paths or path segments for quick structure creation

Quick Start

Get up and running in seconds

Installation

bash
bun add autofold@latest

CLI Usage

bash
bunx autofold@latest -f tree "./project
├── src
│   ├── index.ts
│   └── utils
│       └── helper.ts
└── package.json"

Library Usage

typescript
import { transformTreeString, createStructure } from 'autofold';

const treeString = `project
├── src
│   ├── index.ts
│   └── utils
│       └── helper.ts
└── package.json`;

const nodes = transformTreeString(treeString);
await createStructure(nodes[0], './output');

Examples

See Autofold in action with different input formats

Input: Tree String

bash
autofold -f tree "./project
├── src
│   ├── index.ts
│   └── utils
│       └── helper.ts
└── package.json"

Input: JSON Object

bash
autofold -f nested '{
  "project": {
    "src": {
      "index.ts": null,
      "utils": {
        "helper.ts": null
      }
    },
    "package.json": null
  }
}'

Input: Path Array

bash
autofold -f paths '[
  "project/src/index.ts",
  "project/src/utils/helper.ts",
  "project/package.json"
]'

Output: Directory Structure

project/
├──src/
├──index.ts
└──utils/
└──helper.ts
└──package.json

All formats produce the same result

  • • Directories are created recursively
  • • Files are created as empty files
  • • Structure matches your input exactly
  • • Works with any depth of nesting

API Reference

Complete library functions and types

Core Functions

transformTreeString()

Parse ASCII tree strings

transformNestedTree()

Parse nested JSON objects

createDirectoryTree()

Parse path arrays

createStructure()

Generate filesystem structure

TypeScript Types

typescript
type FolderNode = {
  type: 'folder' | 'file';
  name: string;
  children?: FolderNode[];
};

type NestedTree = {
  [key: string]: null | string | NestedTree;
};