Ali Khakpouri
Ali Khakpouri

Reputation: 873

Gulp - Renaming a file extension

Scenario: I have two config files. Using gulp-rename, I like to rename them from .config to config.disabled.

var rename = require("gulp-rename");
gulp.task("zzz_Remove-Useless-Files", function () {
    var files = [config.websiteRoot + "/App_config/ConnectionStrings.config", config.websiteRoot + "/App_config/RewriteRules.config"];
    return gulp.src(files).pipe(
        foreach(function (stream, file) {
            return gulp.src(file.path)
                .pipe(debug({ title: "Disabling " }))
                .pipe(rename(function (path) {
                    path.extname = ".config.disabled"
                }))
                .pipe(gulp.dest(file.base))
                .pipe(debug({ title: "Stream is now " }));
        })
    );
});

Running this task DOES rename the file to .config.disabled; however, it does it by copying the original file. Like this

config files

What am I doing wrong?

Upvotes: 1

Views: 3057

Answers (1)

Ali Khakpouri
Ali Khakpouri

Reputation: 873

gulp-rename doesn't remove the src files. In order to do that, this is what I had to:

    var vinylPaths = require('vinyl-paths');
    var del = require("del");
    gulp.task("zzz_Remove-Useless-Files", function () {
        var files = [config.websiteRoot + "/App_config/ConnectionStrings.config", config.websiteRoot + "/App_config/RewriteRules.config"];
        return gulp.src(files).pipe(
            foreach(function (stream, file) {
                return gulp.src(file.path)
                    .pipe(debug({ title: "Disabling " }))
                    .pipe(rename(function (path) {
                        path.extname = ".config.disabled"
                    }))
                    .pipe(gulp.dest(file.base))
                    .pipe(debug({ title: "Stream is now " }))
                    .pipe(vinylPaths(del));
            })
        );
    });

Upvotes: 3

Related Questions