-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
43 lines (37 loc) · 970 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
37
38
39
40
41
42
43
"use strict";
var through = require("through2");
var decomment = require("decomment");
var PluginError = require("plugin-error");
function main(options, func) {
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new PluginError("gulp-strip-comments", "Streaming not supported."));
}
try {
file.contents = Buffer.from(func(file.contents.toString(), options));
this.push(file);
} catch (error) {
this.emit(
"error",
new PluginError("gulp-strip-comments", error, {
fileName: file.path,
}),
);
}
return cb();
});
}
function gulpDecomment(options) {
return main(options, decomment);
}
gulpDecomment.text = function (options) {
return main(options, decomment.text);
};
gulpDecomment.html = function (options) {
return main(options, decomment.html);
};
module.exports = gulpDecomment;