-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (26 loc) · 796 Bytes
/
index.js
File metadata and controls
32 lines (26 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var through = require('through2');
var replace = require('./lib/replace');
var gutil = require('gulp-util');
var replacer = function(options) {
var stream = through.obj(function(file, enc, callback) {
if (file.isNull()) {
stream.push(file);
return callback();
}
if (file.isStream()) {
stream.emit('error', new gutil.PluginError('gulp-substituter', 'Streaming not supported'));
return callback();
}
replace(file.contents.toString(), options, function(err, value) {
if (err) {
stream.emit('error', new gutil.PluginError('gulp-substituter', err));
return callback();
}
file.contents = new Buffer(value, enc);
stream.push(file);
callback();
});
});
return stream;
};
module.exports = replacer;