hparra / gulp-rename

Rename files easily
MIT License
692 stars 73 forks source link

Renaming multiple files #39

Closed bretthayes closed 9 years ago

bretthayes commented 9 years ago

Is there support for this? For example:

gulp.task('compile:jade', function() {
  return gulp.src(paths.jade)
    .pipe($.jade())
    .pipe($.rename({
      map: {
        'oldFileName.html': 'newFileName.html',
        'otherFile.html': 'otherFile.txt'
      }
    }))
    .pipe(gulp.dest(paths.build));
});
yocontra commented 9 years ago

Use gulp-if

.pipe(gif('oldFileName.html', rename('newFileName.html'))
bretthayes commented 9 years ago

@contra Doesn't work. The output to my build folder still compiles the original file names. Any ideas?

gulp.task('compile:jade', function() {
  return gulp.src(paths.jade)
    .pipe($.jade())
    .pipe($.if('oldFileName.html', $.rename('newFileName.html')))
    .pipe($.if('otherFile.html', $.rename('otherFile.txt')))
    .pipe(gulp.dest(paths.build));
});
yocontra commented 9 years ago

@robrich Shouldn't that work with gulp-if?

shinnn commented 9 years ago

@bretthayes Could you show us the values of paths.jade?

bretthayes commented 9 years ago

@shinnn, @contra

// gulp-if, gulp-rename, and gulp-jade are installed via npm

var gulp = require('gulp'),
    $ = require('gulp-load-plugins')();

var paths = {
  jade: './src/jade/**/*.jade',
  build: './build'
};
shinnn commented 9 years ago
gulp.task('compile:jade', function() {
  return gulp.src(paths.jade)
    .pipe($.jade())
    .pipe($.if('**/oldFileName.html', $.rename({basename: 'newFileName'})))
    .pipe($.if('**/otherFile.html', $.rename({
      basename: 'otherFile',
      extname: '.txt'
    })))
    .pipe(gulp.dest(paths.build));
});
bretthayes commented 9 years ago

@shinnn Perfect! Specifying the asterisks for the source made it work: **/oldfileName.html.

Also using gulp-debug confirmed the path ./src/jade/oldFileName.html being output during the compilation.

Thanks guys!

shinnn commented 9 years ago

No problem :)