-
Notifications
You must be signed in to change notification settings - Fork 96
/
index.js
41 lines (33 loc) · 1.31 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
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 (inputNodes, inputFile, outputFile, options) {
if (options == null) options = {}
if (!(this instanceof SassCompiler)) return new SassCompiler(inputNodes, inputFile, outputFile, options)
if (!Array.isArray(inputNodes)) throw new Error('Expected array for first argument - did you mean [node] instead of node?')
CachingWriter.call(this, inputNodes, {
annotation: options.annotation
})
this.inputFile = inputFile
this.outputFile = outputFile
this.options = options
}
SassCompiler.prototype.build = function() {
var destFile = path.join(this.outputPath, this.outputFile)
mkdirp.sync(path.dirname(destFile))
var sassOptions = {
file: path.join(this.inputPaths[0], this.inputFile),
includePaths: this.inputPaths,
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)
}