"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.EnvsReplaceCmd = void 0;
function _chalk() {
  const data = _interopRequireDefault(require("chalk"));
  _chalk = function () {
    return data;
  };
  return data;
}
function _envsSet() {
  const data = require("./envs-set.cmd");
  _envsSet = 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); }
class EnvsReplaceCmd {
  constructor(workspace) {
    this.workspace = workspace;
    _defineProperty(this, "name", 'replace <current-env> <new-env>');
    _defineProperty(this, "description", 'replace an existing env with another env for all components using the old env');
    _defineProperty(this, "options", []);
    _defineProperty(this, "group", 'development');
    _defineProperty(this, "arguments", [{
      name: 'current-env',
      description: 'the component id of the env to be replaced'
    }, {
      name: 'new-env',
      description: 'the component id of the new env'
    }]);
    _defineProperty(this, "examples", [{
      cmd: 'replace teambit.harmony/aspect teambit.harmony/node',
      description: "components configured to use the 'aspect' env will be configured to use the 'node' env, instead"
    }]);
  }
  async report([oldEnv, env]) {
    const envId = await this.workspace.resolveComponentId(env);
    const components = await this.workspace.getComponentsUsingEnv(oldEnv, true, true);
    const componentIds = components.map(comp => comp.id);
    await this.workspace.setEnvToComponents(envId, componentIds);
    return `added ${_chalk().default.bold(envId.toString())} env to the following component(s):
${componentIds.map(compId => compId.toString()).join('\n')}\n
${_envsSet().installAfterEnvChangesMsg}`;
  }
}
exports.EnvsReplaceCmd = EnvsReplaceCmd;

//# sourceMappingURL=envs-replace.cmd.js.map