4

I have the following gulp task that is currently not working.

gulp.task('emails', function() {
  gulp.src('views/emails/src/**/*.html')
    .pipe(inky())
    .pipe(gulp.dest('views/emails/dist/'+debug()+"/html.ejs"));
});

I would like to iterate over the /views/emails/src/ directory, find all html files, then use inky to convert them to html, and then copy the resulting html file to...

views/emails/dist/'+ folderName +"/html.ejs

where folderName is the name of the .html file that was processed.

I need this in order to get the file structure in the format that the npm email-templates package requires.

TWilly
  • 4,863
  • 3
  • 43
  • 73

1 Answers1

7

That's a job for gulp-rename:

var rename = require('gulp-rename');
var path = require('path');

gulp.task('emails', function() {
  gulp.src('views/emails/src/**/*.html')
    .pipe(inky())
    .pipe(rename(function(file) {
      file.dirname = path.join(file.dirname, file.basename);
      file.basename = 'html';
      file.extname = '.ejs';
    }))
    .pipe(gulp.dest('views/emails/dist/'));
});
Sven Schoenung
  • 30,224
  • 8
  • 65
  • 70