Creating empty directories in a Yeoman Generator

久未见 提交于 2019-12-08 15:55:07

问题


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:


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/');


来源:https://stackoverflow.com/questions/29830927/creating-empty-directories-in-a-yeoman-generator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!