Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace original file with busted file #90

Open
cmmcleod opened this issue May 3, 2015 · 3 comments
Open

Replace original file with busted file #90

cmmcleod opened this issue May 3, 2015 · 3 comments

Comments

@cmmcleod
Copy link

cmmcleod commented May 3, 2015

Is there a clean mechanism to 'bust-in-place', i.e. Rename the source files if they are busted. The task I've created to do this is a bit hacky/ugly.

Tips, or suggestions welcome.

gulp.task('revAllAndReplace', function(done) {
  var revAll = new RevAll();
  var stream = gulp.src('dist/**')
    .pipe(revAll.revision())
    .pipe(gulp.dest('dist'))        // Instead something like: .pipe(revAll.replace())
    .pipe(revAll.manifestFile())
    .pipe(gulp.dest('dist'));

  stream.on('end', function() {
    var manifest = require('./dist/rev-manifest.json');
    var arr = [];
    for(var origFileName in manifest) {
      if(origFileName != manifest[origFileName]) { // For all files busted/renamed
        arr.push('./dist/' + origFileName);       // Add the original filename to the list
        console.log(origFileName);
      }
    }
    // Using npm 'del' package in this case to remove original files
    del(arr, done);     // Delete all originals files the were not busted/renamed
  });
  stream.on('error', done);
});
@scott-coates
Copy link

Just wanted to say thanks for putting this here, made it really easy for me to implement!

@outaTiME
Copy link

outaTiME commented Jan 7, 2016

Updates for this feature ?? +1

thks !!!

@airtonix
Copy link

This might look nicer for you :

var gulp = require('gulp'),
    revall =  require('gulp-rev-all'),
    vinyl = require('vinyl-paths'),
    del = require('del'),
    Q = require('bluebird');

gulp.task('clean:static', function() {
  return new Q(function(resolve, reject){ 
    var skinTight = vinyl();

    gulp.src('dist/static/*.*', { read: false})
        .pipe(skinTight)
        .pipe(revall.revision())
        .pipe(gulp.dest('dist/'))
        .on('end', function(){
          del(skinTight.paths)
            .then(resolve)
            .catch(reject);
          });
  });

});
  • uses vinyl-paths to store the incoming paths before being fingerprinted.
  • do your gulp plugin requires outside of the task
  • returns a promise to remain async

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants