I want copy an empty directory from my root folder into the new initialized project. I want do this, to provide an initial directory structure for new projects.
I have such empty directories in the folder 'my-template/root/' but that will not be copied by:
// Files to copy (and process).
var files = init.filesToCopy(props);
// Actually copy (and process) files.
init.copyAndProcess(files, props);
I tried this:
// to copy also the empty directories
init.copy('myDir1/');
init.copy('myDir2/');
But than grunt-init crashes with:
Error: Unable to read "grunt-init-example/root/myDir1/" file (Error code: EISDIR).
What have I to do, to get an empty directory to the destination folder?
I use grunt@0.4.0 and grunt-init@0.2.0.
Try taking a look this this article
The part relevant to creating a directory is:
var root = path.normalize(__dirname+"/relative/path/you/want");
grunt.file.mkdir(root);
however, reading the whole this would probably be good.
Inspired by the answer of Nick Mitchinson, I use this workaround:
// 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') );
Update:
Alternative solution is to add .gitkeep files to the empty directories. Than the directories are no more empty and will be listed with filesToCopy().
For more details about .gitkeep look here: http://stackoverflow.com/a/7229996/496587
I create an empty __empty_file.txt file inside the empty folders which I want to get copied. Inside my template.js file I do the following: