-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (26 loc) · 924 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
var through = require('through2');
var PluginError = require('gulp-util').PluginError;
// Constants
var PLUGIN_NAME = 'mibew-gulp-greh';
var RE = /(\/\*\![\s\S]*?\*\/\n)([\s\S]*?)\1/g;
module.exports = function() {
return through.obj(function(file, encoding, callback) {
if (file.isNull()) {
return callback(null, file);
}
if (file.isStream()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported!'));
} else if (file.isBuffer()) {
src = file.contents.toString();
var oldString = '';
var newString = src;
while (oldString !== newString) {
oldString = newString;
newString = oldString.replace(RE, '$1$2'+"\n");
}
file.contents = new Buffer(newString);
}
this.push(file);
return callback(null, file);
});
};