Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulp task that dynamically create folder with name based on file name

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.

like image 944
TWilly Avatar asked Sep 12 '25 21:09

TWilly


1 Answers

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/'));
});
like image 152
Sven Schoenung Avatar answered Sep 15 '25 13:09

Sven Schoenung