-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (29 loc) · 997 Bytes
/
index.js
File metadata and controls
35 lines (29 loc) · 997 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
33
34
35
const clean = require('flow-remove-types');
module.exports = function (fly) {
fly.plugin('unflow', {every: false}, function * (files, opts) {
opts = Object.assign({pretty: true, all: true}, opts);
const type = opts.sourceMap || false;
const maps = [];
files.forEach(file => {
const out = clean(file.data.toString(), opts);
file.data = Buffer.from(out.toString());
const mdata = Buffer.from(type ? JSON.stringify(out.generateMap()) : '');
// handle sourcemaps
if (type === 'inline') {
file.data += Buffer.from(`\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mdata.toString('base64')}`);
} else if (type === 'external') {
const mfile = `${file.base}.map`;
file.data += Buffer.from(`\n//# sourceMappingURL=${mfile}`);
// push an external sourcemap to output
maps.push({
dir: file.dir,
base: mfile,
data: mdata
});
}
});
if (maps.length > 0) {
this._.files = this._.files.concat(maps);
}
});
};