Rename only files not folders
st-schneider opened this issue · 4 comments
st-schneider commented
I have a glob like /themes/**/public/**
where I want to rename the files by eliminating the public
folder.
Currently I have to go
return gulp.src('/themes/**/public/**')
.pipe(rename((filepath: rename.ParsedPath) => {
if (filepath.extname == '') {
filepath.basename = filepath.basename.replace(/public\/?/, "");
}
filepath.dirname = filepath.dirname.replace(/public\/?/, "");
}))
.pipe(gulp.dest('target'));
It is a bit cumbersome to have to rename empty folders as well. If I leave out the if
I end up with and empty public folder in the dest.
Is there a way to only affect files and not folders?
heikki commented
Maybe this:
return gulp.src('/themes/**/public/**', { nodir: true })
...
https://github.com/isaacs/node-glob#options
nodir Do not match directories, only files. (Note: to match only directories, simply put a / at the end of the pattern.)
yocontra commented
We should pass the actual file in as a second arg so we can utilize this https://github.com/gulpjs/vinyl#fileisdirectory or other checks (maybe you want to rename based on contents? who knows)
st-schneider commented
Thank you