Is it possible to pass the name of the parent directory to gulp-rename or any other renaming plugin? I'm trying to programmatically concatenate all the files in the 'src' folders and rename them with the name of their parent directory. Code below is what I have so far.
gulp.task('js-test', function() {
return gulp.src('dev/scripts/**/src/*.min.js')
.pipe(concat('interim-name.js'))
.pipe(rename('How do I give it the name of the parent directory of src'))
.pipe(gulp.dest('dev/scripts'))
});
The end result would look like this:
- Dev
- Scripts
- Bootstrap
- Src
- alert.js (file)
- alert.js.map (file)
- alert.min.js (file)
- tooltip.js (file)
- tooltip.js.map (file)
- tooltip.min.js (file)
- alert.js (file)
- bootstrap.js
- bootstrap.min.js
- Src
- Fontawesome
- Src
- file-1.js
- file-1.js.map (file)
- file-1.min.js (file)
- file-2.js
- file-2.js.map (file)
- file-2.min.js (file)
- file-3.js
- file-3.js.map (file)
- file-3.min.js (file)
- file-1.js
- fontawesome.js
- fontawesome.min.js
- Src
- Bootstrap
- Scripts
gulp-rename has the option of using a function, for example from the documentation:
So I would log out path.dirname and then work on a string manipulation of that: