javascript - 咕噜初始化 : How can I copy or create an empty directory?

标签 javascript node.js gruntjs

我想从我的根文件夹中复制一个空目录到新的初始化项目中。我想这样做,为新项目提供一个初始目录结构。

我在文件夹“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/

相关文章:

javascript - 以全屏模式运行网站

javascript - 具有自执行功能的setTimeout

javascript - 如何检查关键字是否存在而不管大小写?

javascript - 我如何告诉 Grunt 不要在构建任务中缩小或连接 js 文件?

javascript - javascript concat 的 Grunt 观察者

javascript - 无法读取未定义的 React JS 的属性 'concat'

javascript - Node 简单对象工厂模块

node.js - 如何在无服务器框架上包含静态文件?

javascript - 使用 Node.js 遍历 XML 文档的最快方法?

javascript - 没有根文件夹的 Grunt Compress