-
Notifications
You must be signed in to change notification settings - Fork 72
/
index.js
32 lines (26 loc) · 876 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
'use strict';
const extname = require('path').extname;
const compile = require('coffee-script').compile;
module.exports = function (task) {
task.plugin('coffee', { every:true }, function * (file, opts) {
opts = opts || {};
// modify extension
const ext = extname(file.base);
file.base = file.base.replace(new RegExp(ext, 'i'), '.js');
// compile output
const out = compile(file.data.toString(), opts);
if (opts.sourceMap && out.sourceMap) {
const map = `${file.base}.map`;
// add sourceMapping to file contents
out.js += `//# sourceMappingURL=${map}`;
// add sourcemap to `files` array
this._.files.push({
base: map,
dir: file.dir,
data: new Buffer(out.v3SourceMap) // <-- already stringified
});
}
// update file's data
file.data = new Buffer(out.js || out);
});
}