gulp-rev-outdated icon indicating copy to clipboard operation
gulp-rev-outdated copied to clipboard

Old revisions not being removed

Open 0dp opened this issue 6 years ago • 0 comments

Hi @shonny-ua,

I can't seem to get this plugin to work as intended. Old revisions are not being removed. Here are my two tasks. One to create revisions and one to clean them up.

function cleaner() {
    return through.obj(function(file, enc, cb){
        rimraf( path.resolve( (file.cwd || process.cwd()), file.path), function (err) {
            if (err) {
                this.emit('error', new gutil.PluginError('Cleanup old files', err));
            }
            this.push(file);
            cb();
        }.bind(this));
    });
}

gulp.task( 'rev', function() {
  // by default, gulp would pick `assets/css` as the base,
  // so we need to set it explicitly:
  gulp.src([paths.css + '/child-theme.min.css', paths.js + '/child-theme.min.js'], {base: './'})
    .pipe(rev())
    .pipe(gulp.dest('./'))  // write rev'd assets to build dir
    .pipe(rev.manifest({
        merge: true // merge with the existing manifest if one exists
    }))
    .pipe(gulp.dest('./'));  // write manifest to build dir
});

gulp.task( 'rev-clean', function() {
  gulp.src([paths.css + '/*.css'], {read: false})
    .pipe( revOutdated(2) ) // leave 2 recent assets (default value)
    .pipe( cleaner() );

    return;
});

0dp avatar May 09 '18 12:05 0dp