-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports compass and defaults to sass. Fixes #1
- Loading branch information
1 parent
3225202
commit 9283555
Showing
2 changed files
with
92 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,76 @@ | ||
module.exports.lib = 'grunt-contrib-sass'; | ||
// Special case when the extension doesn't match the target | ||
// Note: grunt-contrib-sass expects the target to be named sass | ||
module.exports.targetName = 'sass'; | ||
module.exports.target = { | ||
dist: { | ||
files: [{ | ||
expand: true, | ||
src: ['**/*.{scss, sass}', '!node_modules/**/*.{scss, sass}'], | ||
ext: '.css' | ||
}] | ||
} | ||
}; | ||
var q = require('q'), | ||
deferred = q.defer(), | ||
exec = require('child_process').exec, | ||
utils = require('../helpers/Utils'); | ||
|
||
var | ||
compassSettings = { | ||
lib: 'grunt-contrib-compass', | ||
targetName: 'compass', | ||
target: { | ||
dist: { | ||
options: { | ||
sassDir: '.', | ||
cssDir: '.' | ||
} | ||
} | ||
} | ||
}, | ||
|
||
sassSettings = { | ||
lib: 'grunt-contrib-sass', | ||
targetName: 'sass', | ||
target: { | ||
dist: { | ||
files: [{ | ||
expand: true, | ||
src: ['**/*.{scss, sass}', '!node_modules/**/*.{scss, sass}'], | ||
ext: '.css' | ||
}] | ||
} | ||
} | ||
}; | ||
|
||
// Resolves with whether or not the Compass gem is installed | ||
function isCompassInstalled() { | ||
var deferred = q.defer(), | ||
cmd = 'compass'; | ||
|
||
exec(cmd, function (err) { | ||
deferred.resolve(! err); | ||
}); | ||
|
||
return deferred.promise; | ||
} | ||
|
||
// Whether or not the directory structure was auto-generated | ||
// from compass create. | ||
// Note: auto-generation is determined by the existence of | ||
// the sass and stylesheets directories | ||
function wasCompassCreate() { | ||
return q.all([utils.exists('sass'), utils.exists('stylesheets')]) | ||
.then(function (results) { | ||
return results[0] && results[1]; | ||
}); | ||
} | ||
|
||
|
||
// Check if compass is installed | ||
isCompassInstalled() | ||
.then(function (isInstalled) { | ||
if (isInstalled) { | ||
wasCompassCreate().then(function (wasGenenerated) { | ||
// Use the sass/ and stylesheets/ folders | ||
if (wasGenenerated) { | ||
compassSettings.target.dist.options.sassDir = 'sass'; | ||
compassSettings.target.dist.options.cssDir = 'stylesheets'; | ||
} | ||
|
||
deferred.resolve(compassSettings); | ||
}); | ||
} else { | ||
deferred.resolve(sassSettings); | ||
} | ||
}); | ||
|
||
module.exports = deferred.promise; |