"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
function _path() {
  const data = _interopRequireDefault(require("path"));
  _path = function () {
    return data;
  };
  return data;
}
function _chalk() {
  const data = _interopRequireDefault(require("chalk"));
  _chalk = function () {
    return data;
  };
  return data;
}
function _constants() {
  const data = require("@teambit/legacy/dist/constants");
  _constants = function () {
    return data;
  };
  return data;
}
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
// From the cli we might get those as string in case we run it like --propagate true (return string) as opposed to only --propagate

class EjectConfCmd {
  constructor(workspace) {
    this.workspace = workspace;
    _defineProperty(this, "name", 'eject-conf <pattern>');
    _defineProperty(this, "description", 'eject components configuration (create a `component.json` file)');
    _defineProperty(this, "extendedDescription", `note this can be reversed at any time by snapping/tagging changes and deleting the component.json file \n${(0, _constants().PATTERN_HELP)('eject-conf')}`);
    _defineProperty(this, "alias", '');
    _defineProperty(this, "group", 'development');
    _defineProperty(this, "options", [['p', 'propagate', 'mark propagate true in the config file, so that component.json configs will be merge with workspace configs'], ['o', 'override', 'override file if exist']]);
  }
  async report(args, options) {
    const ejectResult = await this.json(args, options);
    const paths = ejectResult.map(result => result.configPath).map(p => _path().default.relative(this.workspace.path, p)).join('\n');
    return _chalk().default.green(`successfully ejected config to the following path(s)
${_chalk().default.bold(paths)}`);
  }
  async json([pattern], options) {
    const ejectOptions = options;
    if (ejectOptions.propagate === 'true') {
      ejectOptions.propagate = true;
    }
    if (ejectOptions.override === 'true') {
      ejectOptions.override = true;
    }
    const componentIds = await this.workspace.idsByPattern(pattern);
    const results = await this.workspace.ejectMultipleConfigs(componentIds, ejectOptions);
    return results;
  }
}
exports.default = EjectConfCmd;

//# sourceMappingURL=eject-conf.cmd.js.map