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

@themrsami/folder-structure-generator

v1.0.3

Published

A CLI tool to generate folder structures from JSON and create JSON from existing folder structures

Readme

Folder Structure Generator

A powerful Node.js package that allows you to generate folder structures from JSON and create JSON from existing folder structures. Perfect for project templating, scaffolding, and backing up directory structures.

Features

  • Two-way conversion between folders and JSON
  • Create complex folder structures from JSON templates
  • Generate JSON from existing folder structures
  • Both CLI and programmatic interfaces
  • Async/await support
  • Preserves file contents
  • Supports nested directories
  • Easy to use
  • Progress tracking with beautiful progress bars
  • Colorful CLI output
  • Optimized for performance

Installation

npm install @themrsami/folder-structure-generator

Usage

Interactive CLI Usage

Simply run the command without any arguments to start the interactive mode:

npx @themrsami/folder-structure-generator

This will start an interactive session where you can:

  1. Choose between generating JSON or creating folder structure
  2. Select from available directories or JSON files in the current directory
  3. Specify output names
  4. See real-time progress with a beautiful progress bar

Interactive Features:

  • List of available directories and JSON files
  • Easy selection using arrow keys
  • Real-time progress tracking
  • Colorful and user-friendly interface
  • Guided workflow

Traditional CLI Usage

You can still use the traditional command-line arguments if preferred:

  1. Generate JSON from a folder structure:
npx @themrsami/folder-structure-generator generate-json ./my-directory -o structure.json
  1. Create folder structure from JSON:
npx @themrsami/folder-structure-generator create-structure ./structure.json -o generated-folder

Programmatic Usage

const { generateJson, createStructure } = require('@themrsami/folder-structure-generator');

// Example 1: Generate JSON from a directory
async function generateStructureJson() {
    try {
        const structure = await generateJson('./my-project');
        console.log(JSON.stringify(structure, null, 2));
    } catch (error) {
        console.error('Error:', error.message);
    }
}

// Example 2: Create folder structure from JSON
async function createProjectStructure() {
    const structure = {
        'src': {
            type: 'directory',
            children: {
                'components': {
                    type: 'directory',
                    children: {
                        'App.js': {
                            type: 'file',
                            content: 'function App() {\n  return <div>Hello World</div>;\n}'
                        }
                    }
                },
                'index.js': {
                    type: 'file',
                    content: 'console.log("Hello World!");'
                }
            }
        },
        'package.json': {
            type: 'file',
            content: '{\n  "name": "my-project",\n  "version": "1.0.0"\n}'
        }
    };
    
    try {
        await createStructure('./new-project', structure);
        console.log('Project structure created successfully!');
    } catch (error) {
        console.error('Error:', error.message);
    }
}

### Progress Tracking

The package now includes built-in progress tracking for both CLI and programmatic usage:

#### CLI Progress Bars
When using the CLI commands, you'll see a beautiful progress bar showing:
- Current progress percentage
- Number of processed files
- Currently processing file
- Visual progress bar

#### Programmatic Progress Tracking
```javascript
const { generateJson, createStructure, progress } = require('@themrsami/folder-structure-generator');

// Listen for progress events
progress.on('progress', ({ total, current, file }) => {
    console.log(`Processing: ${file} (${current}/${total})`);
});

// Use the functions as normal
await generateJson('./my-directory');

Performance Optimizations

The package now includes several optimizations:

  • Parallel file processing where possible
  • Efficient directory traversal
  • Minimal memory footprint
  • Progress tracking with negligible overhead

JSON Structure Format

The JSON structure follows this format:

{
    "directory-name": {
        "type": "directory",
        "children": {
            "file.txt": {
                "type": "file",
                "content": "File content here"
            },
            "nested-dir": {
                "type": "directory",
                "children": {
                    "another-file.js": {
                        "type": "file",
                        "content": "More content here"
                    }
                }
            }
        }
    }
}

Common Use Cases

  1. Project Templates: Save your project structures as JSON templates and quickly scaffold new projects.
const template = {
    'src': {
        type: 'directory',
        children: {
            'index.js': { type: 'file', content: '// Entry point' },
            'routes': {
                type: 'directory',
                children: {
                    'api.js': { type: 'file', content: '// API routes' }
                }
            }
        }
    }
};
await createStructure('./new-project', template);
  1. Backup Directory Structures: Generate JSON representations of your projects.
const backup = await generateJson('./my-project');
await fs.writeJson('./backup.json', backup);
  1. Project Scaffolding: Create standardized project structures.
const reactTemplate = {
    'src': {
        type: 'directory',
        children: {
            'components': { type: 'directory', children: {} },
            'styles': { type: 'directory', children: {} },
            'utils': { type: 'directory', children: {} },
            'App.js': {
                type: 'file',
                content: 'import React from "react";\n\nexport default function App() {\n  return <div>Hello World</div>;\n}'
            }
        }
    }
};

Error Handling

The package includes built-in error handling for common scenarios:

try {
    await createStructure('./output', structure);
} catch (error) {
    if (error.code === 'EEXIST') {
        console.error('Directory already exists');
    } else if (error.code === 'EACCES') {
        console.error('Permission denied');
    } else {
        console.error('Unexpected error:', error.message);
    }
}

CLI Options

generate-json command

npx @themrsami/folder-structure-generator generate-json [options] <directory>

Options:
  -o, --output <file>  Output JSON file (default: "structure.json")

create-structure command

npx @themrsami/folder-structure-generator create-structure [options] <jsonFile>

Options:
  -o, --output <directory>  Output directory (default: "generated-structure")

Author

License

MIT