-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
36 lines (32 loc) · 937 Bytes
/
index.js
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
33
34
35
36
var eventStream = require('event-stream');
module.exports = gulpChange;
function gulpChange(run) {
return eventStream.map(function(file, done) {
if (file.isNull()) {
return done(null, file);
}
if (file.isStream()) {
return done(new PluginError('gulp-change', 'Streaming not supported.'));
}
var content = file.contents.toString();
var ctx = {
file: file,
fname: file.history[file.history.length - 1].substr(file.base.length),
originalContent: content
};
function next(err, content) {
if (err) {
return done(err);
}
if (content) {
file.contents = new Buffer(content);
}
done(null, file);
}
if (run.length > 1) {
run.call(ctx, content, next);
} else {
next(null, run.call(ctx, content))
}
});
}