Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating empty directories in a Yeoman Generator

How does one create an empty directory via a yeoman generator?

I've looked at mem-fs-editor, but as far as I can tell, directories are only created when a child file is created. I've tried creating a file in a sub directory and then deleting the file, but this doesn't work (I assume because mem-fs is prebuilt completely in memory, when it comes to write to disk, empty directories are not written).

like image 973
tolmark Avatar asked Apr 23 '15 17:04

tolmark


1 Answers

mem-fs-editor (the file library used by Yeoman) do not support empty folders. This is very similar to how git work, the internal only keep track of files.

One option is to add .gitkeep or other empty files in those directory. That's my recommended solution as this will fix the issues you'll have anyway using git.

Another option is to use mkdirp:

var mkdirp = require('mkdirp');

// In your generator
mkdirp.sync('/some/path/to/dir/');
like image 108
Simon Boudrias Avatar answered Sep 28 '22 05:09

Simon Boudrias