Initial commit
[yaffs-website] / node_modules / grunt-contrib-sass / tasks / lib / check.js
1 'use strict';
2 var path = require('path');
3 var dargs = require('dargs');
4 var async = require('async');
5 var chalk = require('chalk');
6 var spawn = require('cross-spawn');
7 var grunt = require('grunt');
8
9 module.exports = function (files, options, cb) {
10   var failCount = 0;
11
12   var filesToCheck = files.filter(function (src) {
13     return path.basename(src)[0] !== '_' && grunt.file.exists(src);
14   });
15
16   async.eachLimit(filesToCheck, options.concurrencyCount, function (src, next) {
17     var bin;
18     var args;
19
20     var passedArgs = dargs(options, {
21       includes: ['loadPath'],
22       ignoreFalse: true
23     });
24
25     if (options.bundleExec) {
26       bin = 'bundle';
27       args = ['exec', 'sass', '--check', src];
28     } else {
29       bin = 'sass';
30       args = ['--check', src];
31     }
32
33     args = args.concat(passedArgs);
34
35     grunt.verbose.writeln('Command: ' + bin + ' ' + args.join(' '));
36
37     grunt.verbose.writeln('Checking file ' + chalk.cyan(src) + ' syntax.');
38     spawn(bin, args, {stdio: 'inherit'})
39       .on('error', grunt.warn)
40       .on('close', function (code) {
41         if (code > 0) {
42           failCount++;
43           grunt.log.error('Checking file ' + chalk.cyan(src) + ' - ' + chalk.red('failed') + '.');
44         } else {
45           grunt.verbose.ok('Checking file ' + chalk.cyan(src) + ' - ' + chalk.green('passed') + '.');
46         }
47
48         next();
49       });
50   }, function () {
51     if (failCount > 0) {
52       grunt.warn('Sass check failed for ' + failCount + ' files.');
53     } else {
54       grunt.log.ok('All ' + chalk.cyan(filesToCheck.length) + ' files passed.');
55     }
56
57     cb();
58   });
59 };