Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
Set skipBinary: true by default, add tests, update all dependencies. Closes #81, closes #91
  • Loading branch information
lazd committed May 16, 2018
1 parent 534ccc9 commit 14df43b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ Type: `Object`

##### options.skipBinary
Type: `boolean`
Default: `false`
Default: `true`

Skip binary files
Skip binary files. This option is true by default. If you want to replace content in binary files, you must explicitly set it to false


[MDN documentation for RegExp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ var rs = require('replacestream');
var istextorbinary = require('istextorbinary');

module.exports = function(search, _replacement, options) {
if (!options) {
options = {};
}

if (options.skipBinary === undefined) {
options.skipBinary = true;
}

return new Transform({
objectMode: true,
transform: function(file, enc, callback) {
if (file.isNull()) {
return callback(null, file);
}

var replacement = _replacement;
if (typeof _replacement === 'function') {
// Pass the vinyl file object as this.file
replacement = _replacement.bind({ file: file });
}

function doReplace() {
if (file.isStream()) {
file.contents = file.contents.pipe(rs(search, replacement));
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "gulp-replace",
"version": "0.6.1",
"version": "1.0.0",
"description": "A string replace plugin for gulp",
"dependencies": {
"istextorbinary": "1.0.2",
"istextorbinary": "2.2.1",
"readable-stream": "^2.0.1",
"replacestream": "^4.0.0"
},
"devDependencies": {
"concat-stream": "^1.5.2",
"mocha": "^2.1.0",
"should": "^7.0.1",
"vinyl": "^0.5.0"
"mocha": "^5.1.1",
"should": "^13.2.1",
"vinyl": "^2.1.0"
},
"scripts": {
"test": "mocha"
Expand Down
17 changes: 17 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,23 @@ describe('gulp-replace', function() {
stream.end();
});

it('should be true by default', function(done) {
stream = replacePlugin('world', 'person');

var file = new File({
path: 'test/fixtures/binary.png',
contents: fs.readFileSync('test/fixtures/binary.png')
});

stream.on('data', function(newFile) {
newFile.contents.should.eql(fs.readFileSync('test/expected/binary.png'));
done();
});

stream.write(file);
stream.end();
});

});
});
});
Expand Down

0 comments on commit 14df43b

Please sign in to comment.