gulpgulp-lessasp.net-core-1.0gulp-renametask-runner-explorer

Changing output directories/files to lowercase in Gulp


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));
});

Solution

  • 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));
    });