"use strict";

var _regeneratorRuntime = require("babel-runtime/regenerator")["default"];

var _interopRequireDefault = require("babel-runtime/helpers/interop-require-default")["default"];

exports.__esModule = true;

var _path = require("path");

var _path2 = _interopRequireDefault(_path);

var _fs = require("fs");

var _fs2 = _interopRequireDefault(_fs);

exports["default"] = function callee$0$0() {
  var cwd, parts, loc, babelrc, packagejson, pkg;
  return _regeneratorRuntime.async(function callee$0$0$(context$1$0) {
    while (1) switch (context$1$0.prev = context$1$0.next) {
      case 0:
        cwd = process.cwd();
        parts = cwd.split(_path2["default"].sep);

      case 2:
        loc = parts.join(_path2["default"].sep);

        if (loc) {
          context$1$0.next = 5;
          break;
        }

        return context$1$0.abrupt("break", 15);

      case 5:
        babelrc = _path2["default"].join(loc, ".babelrc");

        if (!_fs2["default"].existsSync(babelrc)) {
          context$1$0.next = 8;
          break;
        }

        return context$1$0.abrupt("return", [true, "Found config at " + babelrc]);

      case 8:
        packagejson = _path2["default"].join(loc, "package.json");

        if (!_fs2["default"].existsSync(packagejson)) {
          context$1$0.next = 13;
          break;
        }

        pkg = require(packagejson);

        if (!pkg.babel) {
          context$1$0.next = 13;
          break;
        }

        return context$1$0.abrupt("return", [true, "Found config at " + packagejson]);

      case 13:

        parts.pop();

      case 14:
        if (parts.length) {
          context$1$0.next = 2;
          break;
        }

      case 15:
        return context$1$0.abrupt("return", [false, "Found no .babelrc config"]);

      case 16:
      case "end":
        return context$1$0.stop();
    }
  }, null, this);
};

module.exports = exports["default"];