Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document practices around keeping empty directories in source control #836

Open
strugee opened this issue May 6, 2017 · 5 comments
Open

Comments

@strugee
Copy link
Contributor

strugee commented May 6, 2017

Currently the Right Way™ to modify the filesystem in a generator is to use mem-fs-editor, and the Right Way™ to create a directory with mem-fs-editor is to directly use mkdirp. That works fine; however, the empty directory doesn't display in the list of files created (or conflicted, or whatever) at the end of the generator run. It'd be nice if I could tell Yeoman about these directories so it would display them in the list of created files.

@SBoudrias
Copy link
Member

Empty directories are a bit problematic because they won't be commited to git. We've taken a similar approach with Yeoman internal file system to only track files.

My suggestion would be to add a file to keep the directories in source control - with git, we usually see empty .gitkeep files inside directories on popular boilerplate projects.

I don't think we're planning to change this core behavior of Yeoman in the near future.

strugee referenced this issue in straticjs/generator-stratic May 7, 2017
According to yeoman/yeoman#1668 the Right Way™ to do this is to create
an empty .gitkeep file, particularly because git doesn't track empty
directories.
strugee referenced this issue in straticjs/generator-stratic May 7, 2017
According to yeoman/yeoman#1668 the Right Way™ to do this is to create
an empty .gitkeep file, particularly because git doesn't track empty
directories.
@strugee
Copy link
Contributor Author

strugee commented May 7, 2017

Gotcha. That makes a lot of sense.

It'd be nice if this was documented somewhere.

@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Jan 21, 2025
@JoshuaKGoldberg JoshuaKGoldberg changed the title Notify Yeoman I've created an empty directory Document practices around keeping empty directories in source control Jan 21, 2025
@JoshuaKGoldberg JoshuaKGoldberg removed their assignment Jan 21, 2025
@JoshuaKGoldberg JoshuaKGoldberg transferred this issue from yeoman/yeoman Jan 21, 2025
@JoshuaKGoldberg
Copy link
Contributor

🤔 I'm not convinced this needs a full mention in docs. Creating empty directories is pretty rare. Most tools these days handle them well.

The first use cases that come to mind for me are directories like dist or lib, for compiled outputs. But common tools like Babel, ESBuild, TypeScript, Webpack, etc. generally create those directories as needed.

Sorry for pinging so many years later @strugee, just checking - is there a particular reason why you'd want empty directories?

@strugee
Copy link
Contributor Author

strugee commented Jan 25, 2025

@JoshuaKGoldberg it's been many, many years since I touched Yeoman code, but at the time I was writing a Yeoman generator for my static site generator project. It was probably to create the standard location for images:

https://github.com/straticjs/generator-stratic/blob/758142354b83c07cf5a0a65a8aeb2a2700ee9b02/app/index.js#L102

Looking back another way to solve this would be for Yeoman to just automatically create a .gitkeep file if the generator calls mkdirp.

@JoshuaKGoldberg
Copy link
Contributor

👍 Makes sense, thanks! Having a blank directory like images/ -or, in my personal experience with Astro, assets/- is reasonable IMO.

As to where to put this, I'm not sure 🤔. I don't think it needs to be a high-level point in the main docs - it's not something you need to understand to learn the foundations of generators. Maybe an FAQ in https://yeoman.io/learning/faq?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants