forked from joliss/broccoli-sass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (30 loc) · 1.26 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
var path = require('path')
var fs = require('fs')
var mkdirp = require('mkdirp')
var CachingWriter = require('broccoli-caching-writer')
var sass = require('node-sass')
module.exports = SassCompiler
SassCompiler.prototype = Object.create(CachingWriter.prototype)
SassCompiler.prototype.constructor = SassCompiler
function SassCompiler (inputTrees, inputFile, outputFile, options) {
if (!(this instanceof SassCompiler)) return new SassCompiler(inputTrees, inputFile, outputFile, options)
if (!Array.isArray(inputTrees)) throw new Error('Expected array for first argument - did you mean [tree] instead of tree?')
CachingWriter.call(this, inputTrees, options)
this.inputFile = inputFile
this.outputFile = outputFile
this.options = options || {}
}
SassCompiler.prototype.updateCache = function(includePaths, destDir) {
var destFile = path.join(destDir, this.outputFile)
mkdirp.sync(path.dirname(destFile))
var sassOptions = {
file: path.join(includePaths[0], this.inputFile),
includePaths: includePaths,
imagePath: this.options.imagePath,
outputStyle: this.options.outputStyle,
precision: this.options.precision,
sourceComments: this.options.sourceComments,
}
result = sass.renderSync(sassOptions)
fs.writeFileSync(destFile, result.css)
}