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 [email protected] and [email protected].
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 [email protected] and [email protected].
Share Improve this question edited Mar 14, 2013 at 8:24 TLindig asked Mar 13, 2013 at 17:36 TLindigTLindig 50.2k3 gold badges30 silver badges32 bronze badges3 Answers
Reset to default 3Inspired 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: https://stackoverflow./a/7229996/496587
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.
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:
- Store files which matches with our (__empty_file.txt) by iterating over files object returned by init.filesToCopy(props) to an array.
- Create directories using grunt.file.mkdir for each item in the above array and remove this file from files reference which was returned by init.filesToCopy. This has to be called before the call to init.copyAndProcess.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744343061a4569522.html
评论列表(0条)