-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
31 lines (24 loc) · 1.05 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
var path = require( 'path' );
var sander = require( 'sander' );
var _sass = require( 'node-sass' );
module.exports = function sass ( inputdir, outputdir, options, callback ) {
if ( !options.src || !options.dest ) {
throw new Error( 'gobble-sass requires `options.src` and `options.dest` to be set' );
}
options.file = path.join( inputdir, options.src );
if ( options.sourceMap !== false ) {
// by default, generate sourcemaps and include comments
options.outFile = path.join( outputdir, options.dest );
options.sourceMap = path.join( outputdir, options.dest + '.map' );
options.sourceMapRoot = path.dirname( options.outFile );
options.sourceMapContents = options.sourceMapContents !== false;
}
_sass.render( options, function ( err, result ) {
if ( err ) return callback( err );
var promises = [ sander.writeFile( outputdir, options.dest, result.css ) ];
if ( result.map ) {
promises.push( sander.writeFile( outputdir, options.dest + '.map', result.map ) );
}
Promise.all( promises ).then( function () { callback(); }, callback );
});
};