Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-rev-outdated

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-rev-outdated

Old static asset revision files filter

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
237
decreased by-24.28%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Dependencies devDependencies NPM version

gulp-rev-outdated

NPM

Old static asset revision files filter.

Install

$ npm install --save-dev gulp-rev-outdated

Usage

We can use gulp-rev to cache-bust several assets. Every modification of source files caused a new revisioned asset creation. In case of using separate http://static.exsample.com/ domain for distributing static assets we have some problem with a lot of accumulated revisioned asset files. If we have several different frontends (e.q. [www-1.exsample.com, www-2.exsample.cpm, ... www-12.exsample com]) worked with different software releases, We can't remove all revisioned asset files on static.exsample.com. We need to save number of recent revisioned assets. gulp-rev-outdated filter revisioned assets and exclude parametrised quantity of recent files for removing.

Takes one parameter [ keepQuantity ] - number of saved recent files. Default value == 2.

var gulp         = require('gulp');
var gutil           = require('gulp-util');
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 gutil.PluginError('Cleanup old files', err));
            }
            this.push(file);
            cb();
        }.bind(this));
    });
}

gulp.task('clean', function() {
    gulp.src( ['dist/js/vendors*.js'], {read: false})
        .pipe( revOutdated(1) ) // leave 1 latest asset file
        .pipe( cleaner() );

    gulp.src( ['dist/js/bundle*.js'], {read: false})
        .pipe( revOutdated(3) ) // leave 3 recent assets
        .pipe( cleaner() );

    gulp.src( ['dist/css/*.css'], {read: false})
        .pipe( revOutdated() ) // leave 2 recent assets (default value)
        .pipe( cleaner() );

    return;
});

It's also possible to pass in all your asset files at once:

[...]

gulp.task('clean', function() {
    gulp.src( ['dist/**/*.*'], {read: false})
        .pipe( revOutdated(1) ) // leave 1 latest asset file for every file name prefix.
        .pipe( cleaner() );

    return;
});

gulp.src option read false prevents gulp to read the contents of the file and makes this task a lot faster. If you need the file and it's contents after cleaning in the same stream, do not set the read option to false.

Works with gulp-rev-outdated

  • gulp-rev

License

MIT © Oleksandr Ovcharenko

Keywords

FAQs

Package last updated on 02 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc