-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
42 lines (37 loc) · 1009 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
var through = require('through2'),
flowRemoveTypes = require('flow-remove-types'),
gutil = require('gulp-util'),
PluginError = gutil.PluginError;
module.exports = function gulpFlowRemoveTypes(options) {
if(!options) {
options = {}
}
return through.obj(function (file, enc, cb) {
var result;
if (file.isNull()) {
return cb(null, file);
}
if (file.isBuffer()) {
try {
const result = flowRemoveTypes(file.contents.toString('utf8'), options);
file.contents = new Buffer(result.toString());
this.push(file);
//sourceMap option support
if(options.sourceMap) {
this.push(new gutil.File({
cwd: file.cwd,
base: file.base,
path: file.path + '.map',
contents: new Buffer(JSON.stringify(result.generateMap()))
}))
}
cb();
}
catch (err) {
throw new PluginError('gulp-flow-remove-types', err);
}
} else if (file.isStream()) {
throw new PluginError('gulp-flow-remove-types', 'Streams are not supported!');
}
});
};