-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathindex.js
41 lines (33 loc) · 1.12 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
'use strict';
const p = require('path');
const sass = require('node-sass');
module.exports = function (task, utils) {
const render = utils.promisify(sass.render);
// requires that `source()` is specifying MAIN files directly!
task.plugin('sass', {}, function * (file, opts) {
// ensure `opts.file` & not `opts.data`
opts = Object.assign({}, opts, { file:p.format(file), data:null });
// option checks for `sourceMap`
if (opts.sourceMap && typeof opts.sourceMap === 'boolean' && !opts.outFile) {
return this.emit('plugin_error', {
plugin: '@taskr/sass',
message: 'You must specify an `outFile` if using a `boolean` value for `sourceMap`.'
});
}
// update extn to 'css'
file.base = file.base.replace(/(s[a|c]ss)/i, 'css');
const data = yield render(opts);
// update the file's data
file.data = data.css;
// if has `map` & needed opts
if (data.map) {
const o = p.parse(opts.outFile || opts.sourceMap);
// create new `file` entry
this._.files.push({
dir: o.dir,
base: o.base,
data: data.map
});
}
});
};