2 * grunt-contrib-compass
5 * Copyright (c) 2016 Sindre Sorhus, contributors
6 * Licensed under the MIT license.
10 var binVersionCheck = require('bin-version-check');
12 module.exports = function (grunt) {
13 var compass = require('./lib/compass').init(grunt);
15 function compile(args, cb) {
16 grunt.log.verbose.writeln('Running command: ' + args.join(' '));
17 var child = grunt.util.spawn({
20 }, function (err, result, code) {
23 'You need to have Ruby and Compass installed ' +
24 'and in your system PATH for this task to work. ' +
25 'More info: https://github.com/gruntjs/grunt-contrib-compass'
29 // `compass compile` exits with 1 and outputs "Nothing to compile"
30 // on stderr when it has nothing to compile.
31 // https://github.com/chriseppstein/compass/issues/993
32 // Don't fail the task in this situation.
33 if (code === 1 && !/Nothing to compile|Compass can't find any Sass files to compile/g.test(result.stderr)) {
40 child.stdout.pipe(process.stdout);
41 child.stderr.pipe(process.stderr);
45 grunt.registerMultiTask('compass', 'Compile Sass to CSS using Compass', function () {
46 var options = this.options();
47 var cb = this.async();
49 // display compilation time
54 // create a function to retroactively add a banner to the top of the
55 // generated files, if specified
56 var bannerCallback = compass.buildBannerCallback(grunt, options);
57 // create a temporary config file if there are 'raw' options or
58 // settings not supported as CLI arguments
59 var configContext = compass.buildConfigContext(options);
60 // get the array of arguments for the compass command
61 var args = compass.buildArgsArray(options);
63 configContext(function (err, path) {
69 // add `--config` path arguments before `--` option-argument separator if one exists,
70 // otherwise add to the end
71 var doubleDashIdx = args.indexOf('--');
72 args.splice(doubleDashIdx === -1 ? args.length : doubleDashIdx, 0, '--config', path);
75 binVersionCheck(args[0], '>=0.12.2', function (err) {
80 compile(args, function () {