"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

function _child_process() {
  const data = require("child_process");

  _child_process = function () {
    return data;
  };

  return data;
}

function _path() {
  const data = _interopRequireDefault(require("path"));

  _path = function () {
    return data;
  };

  return data;
}

function _component() {
  const data = _interopRequireDefault(require("../../consumer/component"));

  _component = function () {
    return data;
  };

  return data;
}

function globalConfig() {
  const data = _interopRequireWildcard(require("../../api/consumer/lib/global-config"));

  globalConfig = function () {
    return data;
  };

  return data;
}

function _constants() {
  const data = require("../../constants");

  _constants = function () {
    return data;
  };

  return data;
}

function defaultCIFunc(id, scopePath) {
  const child = (0, _child_process().spawn)(process.argv[0], [_path().default.join(__dirname, 'ci-worker.js')], {
    detached: true,
    cwd: scopePath,
    env: {
      __id__: id,
      __scope__: scopePath
    },
    stdio: ['ignore', 'ignore', 'ignore']
  });
  child.unref();
}

var _default = (component, scopePath) => {
  const enableCI = globalConfig().getSync(_constants().CFG_CI_ENABLE_KEY);
  const ciFuncPath = globalConfig().getSync(_constants().CFG_CI_FUNCTION_PATH_KEY);
  if (enableCI !== 'true' && !ciFuncPath) return component;
  const id = component.id.toString();
  let ciFunc;
  if (!ciFuncPath) ciFunc = defaultCIFunc;else {
    // $FlowFixMe
    ciFunc = require(ciFuncPath);
  }
  ciFunc(id, scopePath);
  return component;
};

exports.default = _default;