hparra / gulp-rename

Rename files easily
MIT License
692 stars 73 forks source link

How to avoid overriding destination file if rename target already exists #61

Closed fedulovivan closed 8 years ago

fedulovivan commented 8 years ago

Hello, is it possible to perform additional check before writing destination file, and omit renaming operation if destination file already exists?

My usecase is creating real config files from samples:

gulp
  .src("config/*.sample")
  .pipe(rename({extname:""}))
  .pipe(gulp.dest("config/"));
heikki commented 8 years ago

https://github.com/hparra/gulp-rename#usage -> rename via function

yocontra commented 8 years ago

@fedulovivan gulp.dest has an overwrite option which you can set to false

fedulovivan commented 8 years ago

@contra Probably this is some kind undocumented dest option.

$ gulp -v
[10:09:06] CLI version 3.9.0
[10:09:06] Local version 3.9.0

In fact these two options below does not work:

.pipe(gulp.dest("config/", {overwrite: false}))
.pipe(gulp.dest("config/", {override: false}))
heikki commented 8 years ago

@fedulovivan It is in 4.0 branch -> https://github.com/gulpjs/gulp/blob/4.0/docs/API.md#optionsoverwrite

fedulovivan commented 8 years ago

@heikki Right, thanks! This new option actually listed in 4.0.0 change log. update: is it turned out gulp v4 is currently alpha

dac514 commented 8 years ago

I would also like this feature but Gulp 4 is still in alpha?

Can someone post an example of how to do this without using the new feature? I looked at rename and it's not what I'm after.

Code:

gulp.task("steps", function stepsTask(cb) {
    var GulpYaddaSteps = require('gulp-yadda-steps');
    gulp.src(__dirname + '/tests/features/**/*.feature')
        .pipe(new GulpYaddaSteps())
        .pipe(gulp.dest(__dirname + '/tests/steps/, {overwrite: false}'));
});

Expected: Existing files are not overwritten Actual: Existing files are overwritten

dewwwald commented 8 years ago

If you would like to see two solutions check this out.

http://stackoverflow.com/questions/38827441/gulp-write-file-if-none-exist/38828128#38828128