我想从我的根文件夹中复制一个空目录到新的初始化项目中。我想这样做,为新项目提供一个初始目录结构。
我在文件夹“my-template/root/”中有这样的空目录,但不会被复制:
// Files to copy (and process).
var files = init.filesToCopy(props);
// Actually copy (and process) files.
init.copyAndProcess(files, props);
我试过这个:
// to copy also the empty directories
init.copy('myDir1/');
init.copy('myDir2/');
但是 grunt-init 会崩溃:
Error: Unable to read "grunt-init-example/root/myDir1/" file (Error code: EISDIR).
我该怎么做,才能将空目录获取到目标文件夹?
我使用 grunt@0.4.0 和 grunt-init@0.2.0。
最佳答案
受到 Nick Mitchinson 回答的启发,我使用了这个解决方法:
// module dependencies
var join = require("path").join;
// empty directories will not be copied, so we need to create them manual
grunt.file.mkdir( join(init.destpath(), 'myDir1') );
grunt.file.mkdir( join(init.destpath(), 'myDir2') );
更新:
另一种解决方案是将 .gitkeep
文件添加到空目录中。目录不再为空,并且将使用 filesToCopy() 列出。
有关 .gitkeep
的更多详细信息,请查看此处:https://stackoverflow.com/a/7229996/496587
关于javascript - 咕噜初始化 : How can I copy or create an empty directory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15392465/