hparra / gulp-rename

Rename files easily
MIT License
692 stars 73 forks source link

Remove a part of the file name on rename #26

Closed madastro closed 9 years ago

madastro commented 10 years ago

I have several files with the following format:

SN012_template1.css
SN123_template2.css
SN321_template3.css
...
SN302_template100.css

is it possible to remove the SN*_ part of those files and leave the template#.css as is? This is the current gulp.task that I'll be adding the rename pipe to:

gulp.task('build', function() {
    return gulp.src(css)
        .pipe(minify({
            keepSpecialComments: 1,
            keepBreaks: true
        }))
        .pipe(gulp.dest(dest))
});
psi-4ward commented 9 years ago

untested:

gulp.task('build', function() {
  return gulp.src(css)
    .pipe(minify({
      keepSpecialComments: 1,
      keepBreaks: true
    }))
    .pipe(rename(function(opt) {
      opt.basename = opt.basename.replace(/^SN[0-9]+_/, '');
      return opt;
    }))
    .pipe(gulp.dest(dest))
});
shinnn commented 9 years ago

@psi-4ward is right.