0

I'm using Gulp to automatically copy/bundle/compile my files, I basically copy the entire folder structure from the base folder (MyProject/Scripts) to wwwroot/js.

In the process of copying/processing I want to rename the output path/filenames to lowercase. I found the ChangeCase-module and the Rename-module but I can't get it to work in my setup below.

gulp.task("compile:less", function () {
    return gulp.src(paths.lessSrc)
        .pipe(less())
        //how can I get to currentdirectory so I can use it for the rename? maybe there is another way
        //.pipe(rename({ dirname: changeCase.lowerCase(??currentdir??) }))
        .pipe(gulp.dest(paths.cssTarget));
});

and

gulp.task("compile:js", function () {
    return gulp.src(paths.jsOrigin)
        //simple copy of folders and files but how to rename all to lowercase?
        .pipe(gulp.dest(paths.jsTarget));
});
user2713516
  • 2,983
  • 5
  • 23
  • 49

1 Answers1

2

You can pass a callback function to gulp-rename:

gulp.task("compile:js", function () {
  return gulp.src(paths.jsOrigin)
    .pipe(rename(function(path) {
       path.dirname = changeCase.lowerCase(path.dirname);
       path.basename = changeCase.lowerCase(path.basename);
       path.extname = changeCase.lowerCase(path.extname);
     })) 
    .pipe(gulp.dest(paths.jsTarget));
});
Sven Schoenung
  • 30,224
  • 8
  • 65
  • 70
  • Instead of `path.dirname = changeCase.lowerCase(path.dirname); path.basename = changeCase.lowerCase(path.basename); path.extname = changeCase.lowerCase(path.extname);` I think it should be: `path.dirname = path.dirname.toLowerCase(); path.basename = path.basename.toLowerCase(); path.extname = path.extname.toLowerCase();` – berniecc Mar 09 '20 at 09:27