text: 'use strict';
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.delimiter = undefined;
  exports.errorHandler = errorHandler;
  exports.runTests = runTests;
  exports.runJsLint = runJsLint;
  exports.runSCSSLint = runSCSSLint;
  exports.runLinters = runLinters;
  
  var _path = require('path');
  
  var _path2 = _interopRequireDefault(_path);
  
  var _child_process = require('child_process');
  
  var _chalk = require('chalk');
  
  var _chalk2 = _interopRequireDefault(_chalk);
  
  var _jestCli = require('jest-cli');
  
  var _jestCli2 = _interopRequireDefault(_jestCli);
  
  var _yargs = require('yargs');
  
  var _yargs2 = _interopRequireDefault(_yargs);
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  var delimiter = exports.delimiter = _chalk2.default.magenta('[grommet]');
  
  /**
  * NPM dependencies
  **/
  /**
  * Node dependencies
  **/
  function errorHandler(err) {
    console.log(delimiter + ': ' + _chalk2.default.red('failed'));
    var isArray = Array.isArray(err);
    if (isArray) {
      err.forEach(function (e) {
        return console.error(e.message ? e.message : e);
      });
    } else {
      console.error(err.message ? err.message : err);
    }
  }
  
  function runTests(options) {
    return new Promise(function (resolve, reject) {
      var optionKeys = Object.keys(options).length;
      if (options.scsslint || options.jslint) {
        resolve();
      } else {
        process.env.NODE_ENV = 'test';
        console.log(delimiter + ': Running Tests...');
        var packageJSON = require(_path2.default.resolve(process.cwd(), 'package.json'));
        var config = Object.assign({
          rootDir: process.cwd()
        }, packageJSON.jest, (0, _yargs2.default)(process.argv.slice(optionKeys + 2)).argv);
  
        _jestCli2.default.runCLI(config, [process.cwd()], function (result) {
          if (result.numFailedTests || result.numFailedTestSuites) {
            reject('Tests Failed');
          } else {
            resolve();
          }
        });
      }
    });
  }
  
  function runJsLint(options) {
    return new Promise(function (resolve, reject) {
      var optionKeys = Object.keys(options).length;
      if (optionKeys > 0 && !options.jslint) {
        resolve();
      } else {
        console.log(delimiter + ': Running Javascript linting...');
        var eslintChild = (0, _child_process.fork)(_path2.default.resolve(__dirname, 'eslint'), process.argv.slice(optionKeys + 2));
        eslintChild.on('exit', function (code) {
          if (code !== 0) {
            reject('Js Linting failed');
          } else {
            resolve();
          }
        });
        eslintChild.send('**/*.{js,jsx}');
      }
    });
  }
  
  function runSCSSLint(options) {
    return new Promise(function (resolve, reject) {
      var optionKeys = Object.keys(options).length;
      if (optionKeys > 0 && !options.scsslint) {
        resolve();
      } else {
        console.log(delimiter + ': Running SCSS linting...');
        var scsslintChild = (0, _child_process.fork)(_path2.default.resolve(__dirname, 'scsslint'), process.argv.slice(optionKeys + 2));
        scsslintChild.on('exit', function (code) {
          if (code !== 0) {
            reject('SCSS Linting failed');
          } else {
            resolve();
          }
        });
        scsslintChild.send('**/*.scss');
      }
    });
  }
  
  function runLinters(options) {
    return new Promise(function (resolve, reject) {
      if (options.test) {
        resolve();
      } else {
        var errors = [];
        var scssLintCompleted = false;
        var jsLintCompleted = false;
        runJsLint(options).then(function () {
          jsLintCompleted = true;
          if (scssLintCompleted) {
            if (errors.length === 0) {
              resolve();
            } else {
              reject(errors);
            }
          }
        }, function (err) {
          jsLintCompleted = true;
          errors.push(err);
          if (scssLintCompleted) {
            reject(errors);
          }
        });
        runSCSSLint(options).then(function () {
          scssLintCompleted = true;
          if (jsLintCompleted) {
            if (errors.length === 0) {
              resolve();
            } else {
              reject(errors);
            }
          }
        }, function (err) {
          scssLintCompleted = true;
          errors.push(err);
          if (jsLintCompleted) {
            reject(errors);
          }
        });
      }
    });
  }
  
  exports.default = { errorHandler: errorHandler, runJsLint: runJsLint, runLinters: runLinters, runSCSSLint: runSCSSLint, runTests: runTests };