Creating empty directories in a Yeoman Generator

2019-06-15 18:54发布

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).

1条回答
霸刀☆藐视天下
2楼-- · 2019-06-15 19:47

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/');
查看更多
登录 后发表回答