Skip to content

Commit

Permalink
Merge pull request #56 from Josiah/clone-original-file
Browse files Browse the repository at this point in the history
Clone the original file prior to renaming
  • Loading branch information
contra committed Oct 6, 2015
2 parents ba5ab6d + 5001e08 commit 17d44ec
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ function gulpRename(obj) {
};
}

stream._transform = function (file, unused, callback) {
stream._transform = function (originalFile, unused, callback) {


var file = originalFile.clone({contents: false});
var parsedPath = parsePath(file.relative);
var path;

Expand Down
47 changes: 47 additions & 0 deletions test/rename.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/* global helper, helperError */

require('./spec-helper');
var rename = require('../');
var gulp = require('gulp');
var Path = require('path');

describe('gulp-rename', function () {
context('with string parameter', function () {
Expand Down Expand Up @@ -172,6 +175,50 @@ describe('gulp-rename', function () {
});
});

context('in parallel streams', function () {
it('only changes the file in the current stream', function (done) {
var files = gulp.src('test/fixtures/hello.txt');

var pipe1 = files.pipe(rename({suffix: '-1'}));
var pipe2 = files.pipe(rename({suffix: '-2'}));
var end1 = false;
var end2 = false;
var file1;
var file2;

pipe1
.on('data', function (file) {
file1 = file;
})
.on('end', function () {
end1 = true;

if (end2) {
return check();
}
});

pipe2
.on('data', function (file) {
file2 = file;
})
.on('end', function () {
end2 = true;

if (end1) {
return check();
}
});

function check() {
file1.path.should.equal(Path.resolve('test/fixtures/hello-1.txt'));
file2.path.should.equal(Path.resolve('test/fixtures/hello-2.txt'));

return done();
}
});
});

context('throws unsupported parameter type', function () {
var srcPattern;
beforeEach(function () {
Expand Down

0 comments on commit 17d44ec

Please sign in to comment.