Dirfy
Instantly scaffold directory & file structures from any ASCII/Unicode “tree” diagram 🚀
📋 Problem Statement
Modern AI code generators (ChatGPT, Copilot, etc.) excel at producing code snippets—but often describe project layouts as ASCII or Unicode “tree” diagrams. Manually translating those diagrams into a real folder/file structure is:
- Time-consuming & error-prone when projects are large or deeply nested
- Tedious to type out dozens or hundreds of
mkdir -p/touchcommands - Prone to typos and forgotten directories
Dirfy automates the entire process: feed it any tree diagram (text or file), and it creates the exact structure—no matter how big—in seconds.
✨ Features
- Parse ASCII & Unicode tree diagrams
- Dry-run mode (
-d,--dry-run) to preview changes without writing - Verbose logging (
-v,--verbose) for full action reports - Custom indent support (
-i N,--indent=N) for non-standard tree outputs - Path prefixing (
-p DIR/,--prefix=DIR/) to scaffold under any base folder - Live progress bar and clear success/failure summary
- Zero external dependencies (pure Ruby ≥ 2.7)
🚀 Installation
# via RubyGems
gem install dirfy
# or from source
git clone https://github.com/ahmedmelhady7/dirfy.git
cd dirfy
bundle install
rake install
💡 Usage
From a file
dirfy path/to/tree.txt
Via pipe
cat tree.txt | dirfy
Common Options
| Flag | Description |
|---|---|
-d, --dry-run |
Preview actions without creating files/directories |
-v, --verbose |
Show each create/skip/fail action |
-i N, --indent=N |
Set spaces per tree level (default: 4) |
-p DIR/, --prefix= |
Prepend DIR/ to every generated path |
-h, --help |
Display help and exit |
🛠️ Examples
Given a file myapp_tree.txt:
my_app/
├── lib/
│ └── my_app.rb
├── spec/
│ └── my_app_spec.rb
└── README.md
Run:
dirfy -d -v myapp_tree.txt
Output (dry-run):
🔍 Detected 4 items to create.
DRY-RUN Dir: my_app/
DRY-RUN Dir: my_app/lib/
DRY-RUN File: my_app/lib/my_app.rb
DRY-RUN Dir: my_app/spec/
DRY-RUN File: my_app/spec/my_app_spec.rb
DRY-RUN File: my_app/README.md
Remove -d to actually scaffold.
🤝 Contributing
We ❤️ pull-requests, issues, code-reviews, and — most importantly — your ideas to make dirfy even better.
- Read our CONTRIBUTING.md for setup instructions, code style, and the PR process.
- Fork the repo, branch off
main, and open a PR. - Run tests locally:
bundle install
bundle exec rake
- Ensure your code follows our style (via
rake lint) and has adequate test coverage. - Celebrate 🎉 — once your PR is merged, add yourself to
AUTHORS.md!
Happy scaffolding! 🚀
� Release Process
This section documents the release process for maintainers.
Prerequisites
- Push access to the repository
- RubyGems account with push access to the
dirfygem - 2FA enabled on RubyGems account
Release Steps
Run tests and ensure clean state
bundle exec rake git status # should be cleanUpdate version
# Edit lib/dirfy/version.rb vim lib/dirfy/version.rbCommit version bump
git add lib/dirfy/version.rb Gemfile.lock git commit -m "chore: bump version to vX.Y.Z"Create and push tag
git tag vX.Y.Z git push origin main git push origin vX.Y.ZBuild and publish gem
rake build gem push pkg/dirfy-X.Y.Z.gem # Follow 2FA authentication flowCreate GitHub release
gh release create vX.Y.Z pkg/dirfy-X.Y.Z.gem \ --title "vX.Y.Z" \ --notes "Release notes here"
Automated Release (Helper Script)
Use the provided release script for semi-automated releases:
./scripts/release.sh patch # for patch version (0.0.X)
./scripts/release.sh minor # for minor version (0.X.0)
./scripts/release.sh major # for major version (X.0.0)
Troubleshooting
- 2FA Authentication: RubyGems requires 2FA. Use WebAuthn or
--otpflag - Workflow scope: GitHub token needs
workflowscope to modify Actions - Permission denied: Ensure you have push access to both repo and RubyGems
�📝 License
MIT © Ahmed Elhady
Built with ❤️ to make AI-generated project scaffolding a breeze.
Release steps
This project supports both local and GitHub Actions-based releases. The workflow /.github/workflows/release.yml will publish a built gem when a vX.Y.Z tag is pushed, but the runner needs a valid RUBYGEMS_API_KEY secret and the repository maintainer must ensure the CI token can run workflow jobs that modify releases.
Local release (recommended when you need to provide 2FA interactively):
- Bump the version in
lib/dirfy/version.rb(e.g.0.3.0). - Build the gem locally:
bundle install
bundle exec rake build
- Create a git tag and push it (this will trigger CI if configured):
git add -A
git commit -m "Release vX.Y.Z"
git tag vX.Y.Z
git push origin main --follow-tags
- Publish the gem to RubyGems interactively (you may need to complete 2FA):
gem push pkg/dirfy-X.Y.Z.gem
CI-based release (recommended for automated releases):
- Ensure the repository has the secret
RUBYGEMS_API_KEYconfigured in GitHub Settings → Secrets. - Ensure the repository's token has appropriate permissions to run workflow jobs that create or update releases (the token needs
workflowscope to update workflows). - Push a tag
vX.Y.Zto the repo. Therelease.ymlworkflow will build and push the gem.
Notes and troubleshooting
- If you see an error like
Invalid credentials (401)duringgem pushin CI, double-check thatRUBYGEMS_API_KEYis correctly set and that the CI runner writes it to~/.gem/credentialsbefore pushing. - If GitHub rejects pushes that modify workflow files, ensure the token used has
workflowscope or make the workflow change via the GitHub web UI. - For local gem publishing, if 2FA is enabled you will be prompted to authenticate in your browser or provide an OTP.