在 Yeoman Generator 中创建空目录 [英] Creating empty directories in a Yeoman Generator

查看:34
本文介绍了在 Yeoman Generator 中创建空目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过自耕农生成器创建一个空目录?

我看过mem-fs-editor,但就我而言可以看出,只有在创建子文件时才会创建目录.我试过在子目录中创建一个文件,然后删除该文件,但这不起作用(我假设因为 mem-fs 是完全在内存中预建的,在写入磁盘时,不会写入空目录).

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

推荐答案

mem-fs-editor(Yeoman 使用的文件库)不支持空文件夹.这与 git 的工作方式非常相似,内部只跟踪文件.

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.

一种选择是在这些目录中添加 .gitkeep 或其他空文件.这是我推荐的解决方案,因为这将解决您无论如何使用 git 都会遇到的问题.

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.

另一种选择是使用 mkdirp:

var mkdirp = require('mkdirp');

// In your generator
mkdirp.sync('/some/path/to/dir/');

这篇关于在 Yeoman Generator 中创建空目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆