'use strict';

var _fs = require('fs');

var _fs2 = _interopRequireDefault(_fs);

var _ini = require('ini');

var _ini2 = _interopRequireDefault(_ini);

var _chalk = require('chalk');

var _chalk2 = _interopRequireDefault(_chalk);

var _open = require('open');

var _open2 = _interopRequireDefault(_open);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

require('babel-polyfill');

function openRepo() {
  try {
    var config = _ini2.default.parse(_fs2.default.readFileSync('.git/config', 'utf-8'));
    var url = config['remote "origin"'].url;
    var isSSHRemoteUrl = url.indexOf('git@') > -1;
    var finalUrl = void 0;

    if (isSSHRemoteUrl) {
      finalUrl = 'http://' + url.replace('git@', '').replace(':', '/').replace('.git', '');
    } else {
      finalUrl = url;
    }

    (0, _open2.default)(finalUrl);
  } catch (err) {
    console.log(_chalk2.default.red('No Git repo found'));
  }
}

module.exports = openRepo;