diff --git a/README.md b/README.md index 62640e7..284c7dc 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,9 @@ var outputTree = compileSass(inputTrees, inputFile, outputFile, options); * **`outputFile`**: Relative path of the output CSS file. -* **`options`**: A hash of options for libsass. Supported options are - `imagePath`, `outputStyle`, `precision`, `sourceComments`, and `sourceMap`. +* **`options`**: A hash of options for libsass. Supported options are: + `imagePath`, `indentedSyntax`, `omitSourceMapUrl`, `outputStyle`, `precision`, + `sourceComments`, `sourceMap`, `sourceMapEmbed`, and `sourceMapContents`. ### Example diff --git a/index.js b/index.js index dacc45c..1e71c16 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,10 @@ 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 +var rsvp = require('rsvp') +var Promise = rsvp.Promise +var fs = require('fs') +var writeFile = rsvp.denodeify(fs.writeFile) module.exports = SassCompiler SassCompiler.prototype = Object.create(CachingWriter.prototype) @@ -20,33 +23,43 @@ function SassCompiler (inputTrees, inputFile, outputFile, options) { options = options || {} this.sassOptions = { imagePath: options.imagePath, + indentedSyntax: options.indentedSyntax, + omitSourceMapUrl: options.omitSourceMapUrl, outputStyle: options.outputStyle, + precision: options.precision, sourceComments: options.sourceComments, sourceMap: options.sourceMap, - precision: options.precision + sourceMapEmbed: options.sourceMapEmbed, + sourceMapContents: options.sourceMapContents } } SassCompiler.prototype.updateCache = function(includePaths, destDir) { - var self = this - return new Promise(function(resolve, reject) { - var destFile = path.join(destDir, self.outputFile) + var destFile = path.join(destDir, this.outputFile) + var sourceMapFile = this.sassOptions.sourceMap + if (typeof sourceMapFile !== 'string') { + sourceMapFile = destFile + '.map' + } mkdirp.sync(path.dirname(destFile)) var sassOptions = { - file: includePathSearcher.findFileSync(self.inputFile, includePaths), + file: includePathSearcher.findFileSync(this.inputFile, includePaths), includePaths: includePaths, outFile: destFile, - success: function() { - resolve(this) - }, + success: function(result) { + var promises = [writeFile(destFile, result.css)] + if (this.sassOptions.sourceMap) { + promises.push(writeFile(sourceMapFile, result.map)) + } + resolve(Promise.all(promises)) + }.bind(this), error: function(err) { reject(err) } } - _.merge(sassOptions, self.sassOptions) - sass.renderFile(sassOptions) - }) + _.merge(sassOptions, this.sassOptions) + sass.render(sassOptions) + }.bind(this)) } diff --git a/package.json b/package.json index 642e3be..ea7d561 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "broccoli-sass", "description": "Libsass-based Sass compiler for Broccoli", - "version": "0.3.3", + "version": "0.4.0", "author": "Jo Liss ", "main": "index.js", "license": "MIT", @@ -21,7 +21,7 @@ "include-path-searcher": "^0.1.0", "lodash": "~2.4.1", "mkdirp": "^0.3.5", - "node-sass": "^1.1.4", + "node-sass": "^2.0.1", "rsvp": "^3.0.6" } }