Initial commit
[yaffs-website] / node_modules / grunt-contrib-compass / tasks / compass.js
1 /*
2  * grunt-contrib-compass
3  * http://gruntjs.com/
4  *
5  * Copyright (c) 2016 Sindre Sorhus, contributors
6  * Licensed under the MIT license.
7  */
8
9 'use strict';
10 var binVersionCheck = require('bin-version-check');
11
12 module.exports = function (grunt) {
13   var compass = require('./lib/compass').init(grunt);
14
15   function compile(args, cb) {
16     grunt.log.verbose.writeln('Running command: ' + args.join(' '));
17     var child = grunt.util.spawn({
18       cmd: args.shift(),
19       args: args
20     }, function (err, result, code) {
21       if (code === 127) {
22         grunt.warn(
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'
26         );
27       }
28
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)) {
34         grunt.warn('↑');
35       }
36
37       cb();
38     });
39     if (child) {
40       child.stdout.pipe(process.stdout);
41       child.stderr.pipe(process.stderr);
42     }
43   }
44
45   grunt.registerMultiTask('compass', 'Compile Sass to CSS using Compass', function () {
46     var options = this.options();
47     var cb = this.async();
48
49     // display compilation time
50     if (!options.clean) {
51       options.time = true;
52     }
53
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);
62
63     configContext(function (err, path) {
64       if (err) {
65         grunt.warn(err);
66       }
67
68       if (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);
73       }
74
75       binVersionCheck(args[0], '>=0.12.2', function (err) {
76         if (err) {
77           grunt.warn(err);
78         }
79
80         compile(args, function () {
81           bannerCallback();
82           cb();
83         });
84       });
85     });
86   });
87 };