/*
 * grunt-react
 * https://github.com/ericclemmons/grunt-react
 *
 * Copyright (c) 2013 Eric Clemmons, contributors
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

  var path = require('path');
  var transform = require('react-tools').transform;

  grunt.registerMultiTask('react', 'Compile Facebook React JSX templates into JavaScript', function() {
    var done = this.async();

    var options = this.options();
    grunt.verbose.writeflags(options, 'Options');

    if (this.files.length < 1) {
      grunt.verbose.warn('Destination not written because no source files were provided.');
    }

    grunt.util.async.forEachSeries(this.files, function(f, nextFileObj) {
      var destFile = f.dest;

      var files = f.src.filter(function(filepath) {
        if (!grunt.file.exists(filepath)) {
          grunt.log.warn('Source file "' + filepath + '" not found.');
          return false;
        } else {
          return true;
        }
      });

      if (files.length === 0) {
        if (f.src.length < 1) {
          grunt.log.warn('Destination not written because no source files were found.');
        }

        // No src files, go to next target. Warn would have been issued above.
        return nextFileObj();
      }

      var compiled = [];
      grunt.util.async.concatSeries(files, function(file, next) {
        grunt.log.writeln('[react] Compiling ' + file.cyan + ' --> ' + destFile.cyan);

        try {
          compiled.push(transform(grunt.file.read(file)));
          next();
        } catch (e) {
          var error = grunt.log.wordlist(['[react] ' + e], { color: 'red' });
          grunt.log.error(error);
          nextFileObj(error);
        }
      }, function () {
        grunt.file.write(destFile, compiled.join(grunt.util.normalizelf(grunt.util.linefeed)));
        grunt.log.writeln('[react] File ' + destFile.cyan + ' created.');
        nextFileObj();
      });

    }, done);
  });
};

@@ -1580,137 +1580,25 @@
     
-var error = grunt.log.wordlist(%5B'%5Breact%5D ' + e%5D, %7B color: 'red' %7D);%0A          grunt.log.error(error);%0A          nextFileObj(error
+grunt.fail.warn(e
 );%0A 

Throw a proper error when something goes wrong.