forked from joliss/broccoli-sass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (45 loc) · 1.63 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
var path = require('path')
var mkdirp = require('mkdirp')
var includePathSearcher = require('include-path-searcher')
var CachingWriter = require('broccoli-caching-writer')
var sass = require('node-sass')
var _ = require('lodash')
var Promise = require('rsvp').Promise
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
options = options || {}
this.sassOptions = {
imagePath: options.imagePath,
outputStyle: options.outputStyle,
sourceComments: options.sourceComments,
sourceMap: options.sourceMap,
precision: options.precision
}
}
SassCompiler.prototype.updateCache = function(includePaths, destDir) {
var self = this
return new Promise(function(resolve, reject) {
var destFile = path.join(destDir, self.outputFile)
mkdirp.sync(path.dirname(destFile))
var sassOptions = {
file: includePathSearcher.findFileSync(self.inputFile, includePaths),
includePaths: includePaths,
outFile: destFile,
success: function() {
resolve(this)
},
error: function(err) {
reject(err)
}
}
_.merge(sassOptions, self.sassOptions)
sass.renderFile(sassOptions)
})
}