So just to give you some context, I\'m trying to create a generator that will create some files (based on user input of course) as well as update some existing files in
Yeoman also provides a more elegant way of fs operations using mem-fs-editor.
You can use this.fs.copy
, passing a process function as an option to do any modifications to the content:
this.fs.copy(path, newPath, {
process: function(content) {
/* Any modification goes here. Note that contents is a Buffer object */
var regEx = new RegExp('old string', 'g');
var newContent = content.toString().replace(regEx, 'new string');
return newContent;
}
});
This way you can also take advantage of mem-fs-editor
features.