-
-
Notifications
You must be signed in to change notification settings - Fork 209
/
sass.js
43 lines (35 loc) · 1.12 KB
/
sass.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
/* eslint-disable prefer-object-spread, promise/prefer-await-to-then */
'use strict';
const util = require('util');
const path = require('path');
module.exports = grunt => {
grunt.registerMultiTask('sass', 'Compile Sass to CSS', function () {
const done = this.async();
const options = this.options({
precision: 10
});
if (!options.implementation) {
grunt.fatal('The implementation option must be passed to the Sass task');
}
grunt.verbose.writeln(`\n${options.implementation.info}\n`);
(async () => {
await Promise.all(this.files.map(async item => {
const [src] = item.src;
if (!src || path.basename(src)[0] === '_') {
return;
}
const result = await util.promisify(options.implementation.render)(Object.assign({}, options, {
file: src,
outFile: item.dest
}));
grunt.file.write(item.dest, result.css);
if (options.sourceMap) {
const filePath = options.sourceMap === true ? `${item.dest}.map` : options.sourceMap;
grunt.file.write(filePath, result.map);
}
}));
})().catch(error => {
grunt.fatal(error.formatted || error);
}).then(done);
});
};