Creating empty directories in a Yeoman Generator
Asked Answered
W

1

12

How does one create an empty directory via a yeoman generator?

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

Writ answered 23/4, 2015 at 17:54 Comment(1)
I got around this limitation by, as you've said, adding folders with a dummy text files in it and copying over with the following code: this.fs.copy( this.templatePath('forCopy'), this.destinationRoot());Asterism
U
23

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.

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.

Another option is to use mkdirp:

var mkdirp = require('mkdirp');

// In your generator
mkdirp.sync('/some/path/to/dir/');
Uncork answered 23/4, 2015 at 22:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.