-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
74 lines (67 loc) · 1.89 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const path = require('path')
const sass = require('sass')
const extend = require('extend-shallow')
exports.name = 'scss'
exports.outputFormat = 'css'
exports.render = function (str, options) {
const input = extend({}, options, {data: str})
// TODO: Replace with sass.compileString()
const out = sass.renderSync(input)
return {
body: out.css.toString(),
dependencies: out.stats.includedFiles.map(filename => {
return path.resolve(filename)
})
}
}
exports.renderAsync = function (str, options) {
const input = extend({}, options, {data: str})
return new Promise((resolve, reject) => {
// TODO: Replace with sass.compileStringAsync()
sass.render(input, (err, out) => {
if (err) {
return reject(err)
}
return resolve({
body: out.css.toString(),
dependencies: out.stats.includedFiles.map(filename => {
return path.resolve(filename)
})
})
})
})
}
exports.renderFile = function (filename, options) {
const input = extend({}, options, {
file: path.resolve(filename)
})
// TODO: Replace with sass.compile()
const out = sass.renderSync(input)
return {
body: out.css.toString(),
dependencies: out.stats.includedFiles.map(filename => {
return path.resolve(filename)
}).filter(name => {
return name !== filename
})
}
}
exports.renderFileAsync = function (filename, options) {
const input = extend({}, options, {file: path.resolve(filename)})
return new Promise((resolve, reject) => {
// TODO: Replace with sass.compileAsync()
sass.render(input, (err, out) => {
if (err) {
return reject(err)
}
return resolve({
body: out.css.toString(),
dependencies: out.stats.includedFiles.map(filename => {
return path.resolve(filename)
}).filter(name => {
return name !== filename
})
})
})
})
}