-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
48 lines (42 loc) · 1.31 KB
/
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
44
45
46
47
48
var coffeescript = require('coffeescript');
var createFilter = require('rollup-pluginutils').createFilter;
var objectAssign = require('object-assign');
var extname = require('path').extname;
function compileOptions(id, options, literateExtensions) {
if (literateExtensions.indexOf(extname(id) === -1)) {
return options;
} else {
return objectAssign({}, options, { literate: true });
}
}
function sourceMap(output) {
if (output.v3SourceMap) {
return JSON.parse(output.v3SourceMap);
}
}
module.exports = function coffee(options) {
options = objectAssign({
sourceMap: true,
bare: true,
extensions: ['.coffee', '.litcoffee'],
literateExtensions: ['.litcoffee', '.md']
}, options || {});
var filter = createFilter(options.include, options.exclude);
var extensions = options.extensions;
var literateExtensions = options.literateExtensions;
delete options.extensions;
delete options.literateExtensions;
delete options.include;
delete options.exclude;
return {
transform: function(code, id) {
if (!filter(id)) return null;
if (extensions.indexOf(extname(id)) === -1) return null;
var output = coffeescript.compile(code, compileOptions(id, options, literateExtensions));
return {
code: output.js,
map: sourceMap(output)
};
}
};
};