UNPKG

1.93 kBJavaScriptView Raw
1const path = require('path')
2const sass = require('sass')
3const extend = require('extend-shallow')
4
5exports.name = 'scss'
6exports.outputFormat = 'css'
7
8exports.render = function (str, options) {
9 const input = extend({}, options, {data: str})
10 // TODO: Replace with sass.compileString()
11 const out = sass.renderSync(input)
12 return {
13 body: out.css.toString(),
14 dependencies: out.stats.includedFiles.map(filename => {
15 return path.resolve(filename)
16 })
17 }
18}
19
20exports.renderAsync = function (str, options) {
21 const input = extend({}, options, {data: str})
22 return new Promise((resolve, reject) => {
23 // TODO: Replace with sass.compileStringAsync()
24 sass.render(input, (err, out) => {
25 if (err) {
26 return reject(err)
27 }
28
29 return resolve({
30 body: out.css.toString(),
31 dependencies: out.stats.includedFiles.map(filename => {
32 return path.resolve(filename)
33 })
34 })
35 })
36 })
37}
38
39exports.renderFile = function (filename, options) {
40 const input = extend({}, options, {
41 file: path.resolve(filename)
42 })
43 // TODO: Replace with sass.compile()
44 const out = sass.renderSync(input)
45 return {
46 body: out.css.toString(),
47 dependencies: out.stats.includedFiles.map(filename => {
48 return path.resolve(filename)
49 }).filter(name => {
50 return name !== filename
51 })
52 }
53}
54
55exports.renderFileAsync = function (filename, options) {
56 const input = extend({}, options, {file: path.resolve(filename)})
57 return new Promise((resolve, reject) => {
58 // TODO: Replace with sass.compileAsync()
59 sass.render(input, (err, out) => {
60 if (err) {
61 return reject(err)
62 }
63
64 return resolve({
65 body: out.css.toString(),
66 dependencies: out.stats.includedFiles.map(filename => {
67 return path.resolve(filename)
68 }).filter(name => {
69 return name !== filename
70 })
71 })
72 })
73 })
74}