"use strict";

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

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

_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 = scriptName => (0, _plugin.default)('RUN CUSTOM SCRIPT', ({
  reporter
}) => /*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
  if (!scriptName) {
    reporter.emit('message', 'No custom script name found, skipping step');
    return;
  } else {
    reporter.emit('message', 'Custom script found: ' + scriptName);
  }

  try {
    return new _promise.default((resolve, reject) => {
      const scriptCmd = `npm run ${scriptName}`;
      (0, _child_process.exec)(scriptCmd, err => {
        if (!!err) reject(err);
        return resolve();
      });
    });
  } catch (e) {
    return _promise.default.reject(e);
  }
}));

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