I want to create a copy with a new extension in the same folder only of the file which was changed. How should src and dest be specified?
var gulp = require('gulp'),
rename = require("gulp-rename"),
watch = require('gulp-watch');
var filePath = "./repo/**/*.xml"
gulp.task('watch', function () {
watch(filePath, gulp.series('rename'));
});
gulp.task('rename', function () {
return gulp.src(???).pipe(rename(function (path) {
path.extname = ".mei";
})).pipe(gulp.dest(???));
});
Try this:
This uses the gulp-changed-in-place plugin to only pass through files that have changed in the same directory (in your case
filePath).It does have a
firstRunoption but I couldn't get it to work properly - maybe that option doesn't play well with gulp v4? To work around that,renameis called once before thewatchis set up, seeNow it will only change the extension of the changed file and add that changed file back into the same directory it started in.