gulpgulp-replace

gulp-replace only replacing text in some files in a folder


I am using gulp replace to replace a string with the version number from my package.json file as follows:

gulp.task('replace', ['uglify','process-html','copy-release'], function () {
    return gulp.src([releaseFolder + '/**/*.html',releaseFolder + '/app.js'])
            .pipe( debug({title:"replace files"}))
           .pipe(replace( "__applicationVersionNumber__", packageJson.version ))
           .pipe(gulp.dest(releaseFolder));
});

This works but of the 6 files in releaseFolder/tempaltes/*.html only 5 of them are replaced:

grunt output showing 5 files in the templates folder processed

folder contents of templates folder showing 6 files

This is replacing the text on the files in place. I.e. they are saved back to the same place when the replace is done. If I set the output location as different they are all replaced but they are already in the location I need them to be in.

Why is the last file missed?

Thanks

My entire gulpFile is here: https://github.com/Roaders/YouTubeCommentator/blob/3808036d7ce1fa84e035bc01cc765c5dd7a1e008/gulpfile.js


Solution

  • Basically all your tasks are incorrectly signalling async completion. For each task you should do one of the following two:

    Since you seem to be using streams in all of your tasks, you can just get rid of the callbacks.

    For example your copy-release task should look like this:

    gulp.task('copy-release', ['clean'], function () {
      return gulp.src([
          './templates/**/*.html',
          './lib/**/*.js',
          './assets/**/*.*',
          './css/**/*.css'
        ], {base: './'})
        .pipe(gulp.dest(releaseFolder));
    });