Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Gitnaseem745/mkstruct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

πŸ—οΈ mkstruct

Instantly generate multi-level folder & file structures from flat text or ASCII tree format.
Stop wasting time creating nested directories manually. Scaffold entire projects in seconds! πŸš€


✨ Features

  • βœ… Two Input Formats: Flat file lists or tree-like ASCII structures
  • πŸ“ Automatic Detection: Intelligently detects format type
  • πŸš€ Zero Config: Works with npx β€” no global install required
  • πŸ›‘οΈ Safe by Default: Dry-run mode to preview before creating
  • πŸ’ͺ Force Mode: Overwrite existing files when needed
  • 🎯 Smart Path Handling: Correctly handles nested directories
  • πŸ’‘ Perfect For: Scaffolding boilerplates, UI libraries, and project templates
  • πŸ”’ Security: Prevents writing outside current directory

πŸ“¦ Installation

Option 1: Use with npx (Recommended)

No installation needed! Run directly:

npx mkstruct structure.txt

Option 2: Global Install

Install once, use anywhere:

npm install -g mkstruct

Option 3: Local Project Install

Add to your project's dev dependencies:

npm install --save-dev mkstruct

πŸš€ Quick Start

1️⃣ Flat Format

Create a file structure.txt with paths separated by slashes:

src/index.js
src/components/Header.jsx
src/components/Footer.jsx
src/styles/main.css
public/images/logo.png
README.md

Generate the structure:

mkstruct structure.txt

Result:

βœ… Created file: src/index.js
πŸ“ Created folder: src/components
βœ… Created file: src/components/Header.jsx
βœ… Created file: src/components/Footer.jsx
πŸ“ Created folder: src/styles
βœ… Created file: src/styles/main.css
...

2️⃣ Tree Format

Create a file tree.txt with ASCII tree structure:

β”œβ”€β”€ src
β”‚ β”œβ”€β”€ index.js
β”‚ β”œβ”€β”€ components
β”‚ β”‚ β”œβ”€β”€ Header.jsx
β”‚ β”‚ └── Footer.jsx
β”‚ └── styles
β”‚ └── main.css
β”œβ”€β”€ public
β”‚ └── images
β”‚ └── logo.png
└── README.md

Generate the structure:

mkstruct tree.txt

Note: mkstruct automatically detects which format you're using!


πŸ“š Usage & Options

Basic Syntax

mkstruct [file] [options]

Options

Option Alias Description
--dry-run -d Preview actions without creating files
--force -f Overwrite existing files
--stdin -s Read structure from stdin instead of file
--verbose -v Enable verbose logging
--help -h Show help information

πŸ’‘ Examples

Preview Before Creating (Dry Run)

mkstruct structure.txt --dry-run

Output:

[DRY] create file: src/index.js
[DRY] mkdir: src/components
[DRY] create file: src/components/Header.jsx
...

Read from stdin

cat structure.txt | mkstruct --stdin

Or create on-the-fly:

echo -e "src/index.js\nsrc/App.js\nREADME.md" | mkstruct --stdin

Force Overwrite Existing Files

mkstruct structure.txt --force

⚠️ Warning: This will overwrite existing files without prompting!


Verbose Output

mkstruct structure.txt --verbose

🎯 Real-World Use Cases

1. Scaffold a React Project

react-structure.txt:

src/App.jsx
src/main.jsx
src/components/Navbar.jsx
src/components/Hero.jsx
src/components/Footer.jsx
src/pages/Home.jsx
src/pages/About.jsx
src/hooks/useAuth.js
src/utils/api.js
src/styles/globals.css
public/favicon.ico
npx mkstruct react-structure.txt

2. Create Express.js Backend

backend-tree.txt:

β”œβ”€β”€ server.js
β”œβ”€β”€ config
β”‚ β”œβ”€β”€ database.js
β”‚ └── environment.js
β”œβ”€β”€ routes
β”‚ β”œβ”€β”€ api.js
β”‚ β”œβ”€β”€ auth.js
β”‚ └── users.js
β”œβ”€β”€ controllers
β”‚ β”œβ”€β”€ authController.js
β”‚ └── userController.js
β”œβ”€β”€ models
β”‚ └── User.js
β”œβ”€β”€ middleware
β”‚ β”œβ”€β”€ auth.js
β”‚ └── errorHandler.js
└── utils
 β”œβ”€β”€ logger.js
 └── validators.js
npx mkstruct backend-tree.txt

3. Documentation Structure

docs/getting-started.md
docs/api/authentication.md
docs/api/endpoints.md
docs/guides/deployment.md
docs/guides/testing.md
docs/examples/basic.md
docs/examples/advanced.md

4. Test Directory Setup

tests/unit/utils.test.js
tests/unit/components.test.js
tests/integration/api.test.js
tests/e2e/user-flow.test.js
tests/fixtures/data.json
tests/__mocks__/axios.js

πŸ”§ Advanced Usage

Combine with Other Tools

# Generate from GitHub gist
curl -s https://gist.githubusercontent.com/user/id/raw | mkstruct --stdin
# Generate and initialize git
mkstruct structure.txt && git init
# Generate, install dependencies, and start
mkstruct structure.txt && npm init -y && npm install express

Create Custom Scripts

Add to package.json:

{
 "scripts": {
 "scaffold": "mkstruct templates/project-structure.txt",
 "scaffold:preview": "mkstruct templates/project-structure.txt --dry-run"
 }
}

Then run:

npm run scaffold

πŸ“– Format Specifications

Flat Format Rules

  1. Use forward slashes (/) for paths, even on Windows
  2. Files must have an extension (e.g., .js, .css, .md)
  3. Folders are automatically created for nested paths
  4. One path per line
  5. Empty lines are ignored

Example:

src/index.js ← File (has extension)
src/utils/ ← Folder (no extension, optional trailing /)
config/env.json ← Nested file

Tree Format Rules

  1. Use standard tree characters: β”œβ”€β”€, └──, β”‚
  2. Each level is indented by 4 spaces or 1 tab
  3. Files are detected by having an extension
  4. The format is automatically detected

Tree Characters:

  • β”œβ”€β”€ - Branch item
  • └── - Last branch item
  • β”‚ - Vertical line for nesting

Example:

project/
β”œβ”€β”€ src
β”‚ β”œβ”€β”€ index.js
β”‚ └── utils
β”‚ └── helper.js
└── README.md

⚠️ Important Notes

Security

  • mkstruct prevents writing outside the current working directory
  • Paths starting with .. or absolute paths are rejected
  • Always review the structure file before running with --force

Existing Files

  • By default, mkstruct skips existing files (shows warning)
  • Use --force to overwrite existing files
  • Use --dry-run to preview before creating

Cross-Platform Compatibility

  • Use forward slashes (/) in structure files on all platforms
  • mkstruct automatically converts to Windows backslashes when needed
  • Tree format works identically on Windows, Mac, and Linux

πŸ› Troubleshooting

Problem: "No input file provided"

Solution: Provide a filename or use --stdin:

mkstruct mystructure.txt
# OR
echo "src/index.js" | mkstruct --stdin

Problem: Files created in wrong location

Solution: Make sure you're in the correct directory:

pwd # Check current directory
cd /path/to/project
mkstruct structure.txt

Problem: Tree format not detected

Solution: Ensure proper tree characters (β”œβ”€β”€, └──, β”‚) are used. Copy from examples or use a tree generator.


Problem: "Refusing to write outside CWD"

Solution: Don't use absolute paths or .. in your structure file. All paths should be relative to current directory.


🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. Report Bugs: Open an issue with details
  2. Suggest Features: Share your ideas in issues
  3. Submit PRs: Fork, create a branch, and submit a pull request
  4. Improve Docs: Help make documentation clearer

Development Setup

# Clone the repository
git clone https://github.com/Gitnaseem745/mkstruct.git
cd mkstruct
# Install dependencies
npm install
# Run locally
node bin/index.js examples/structure.txt --dry-run

πŸ“„ License

MIT Β© Naseem Ansari

See LICENSE file for details.


🌟 Show Your Support

If mkstruct helped you save time, please give it a ⭐️ on GitHub!


πŸ“ž Contact & Links


Made with ❀️ by developers, for developers

About

CLI tool for instantly generating multi-level folder & file structures from flat text or ASCII tree format.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /