"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");

require("core-js/modules/es.string.replace");

var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");

_Object$defineProperty(exports, "__esModule", {
  value: true
});

exports.default = void 0;

var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));

var _child_process = require("child_process");

var _plugin = _interopRequireDefault(require("@start/plugin"));

var _default = (params = '', cwd) => (0, _plugin.default)('YARN INSTALL', ({
  reporter
}) =>
/*#__PURE__*/
(0, _asyncToGenerator2.default)(function* () {
  return new _promise.default(
  /*#__PURE__*/
  function () {
    var _ref2 = (0, _asyncToGenerator2.default)(function* (resolve, reject) {
      const command = 'yarn install ';
      const child = (0, _child_process.exec)(command + params, {
        cwd: cwd
      });
      child.stdout.on('data', data => {
        reporter.emit('message', 'yarn', data.replace('\n', ''));
      });
      child.stderr.on('data', data => {
        reporter.emit('warning', 'yarn', data.replace('\n', ''));
      });
      child.on('close', code => {
        if (code === 0) {
          resolve();
        } else {
          reject('Error code: ' + code);
        }
      });
    });

    return function (_x, _x2) {
      return _ref2.apply(this, arguments);
    };
  }());
}));

exports.default = _default;
module.exports = exports.default;