shonny-ua / gulp-rev-collector

Static asset revision data collector from manifests, with was generated from different streams and replace they's links in html template.
MIT License
150 stars 41 forks source link

How do I delete old version files? #51

Open whdeairen opened 6 years ago

whdeairen commented 6 years ago

image

like this ,我想要唯一的joc.js

whdeairen commented 6 years ago

I want delete old version files

shonny-ua commented 6 years ago

see https://github.com/shonny-ua/gulp-rev-outdated

var gulp            = require('gulp');
var PluginError  = require('plugin-error');
var rimraf          = require('rimraf');
var revOutdated     = require('gulp-rev-outdated');
var path            = require('path');
var through         = require('through2');
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 PluginError('Cleanup old files', err));
            }
            this.push(file);
            cb();
        }.bind(this));
    });
}

gulp.src( [settings.dest + '/joc*.js'], {read: false})
        .pipe( revOutdated() )
        .pipe( cleaner() );