-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathscss.js
45 lines (40 loc) · 1.06 KB
/
scss.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
var scss = require("sass")
var TerraformError = require("../../error").TerraformError
var path = require("path")
var fs = require("fs")
exports.compile = function(rootPath, filePath, options, callback){
var srcFullPath = path.resolve(rootPath, filePath)
try{
var fileContents = fs.readFileSync(srcFullPath)
}catch(e){
return callback(null, null)
}
var dirs = [
path.dirname(srcFullPath),
path.dirname(path.resolve(rootPath))
]
scss.render({
file: srcFullPath,
includePaths: dirs,
outputStyle: 'compressed',
sourceMap: true,
sourceMapEmbed: false,
sourceMapContents: true,
outFile: filePath,
omitSourceMapUrl: true
}, function (e, css) {
if (e) {
var error = new TerraformError ({
source: "Sass",
dest: "CSS",
lineno: e.line || 99,
name: "Sass Error",
message: e.message,
filename: e.file || filePath,
stack: fileContents.toString()
})
return callback(error)
}
callback(null, css.css.toString(), css.map.toString())
});
}