"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ScopeSetCmd = void 0;
function _constants() {
  const data = require("@teambit/legacy/dist/constants");
  _constants = function () {
    return data;
  };
  return data;
}
function _chalk() {
  const data = _interopRequireDefault(require("chalk"));
  _chalk = 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 ScopeSetCmd {
  constructor(workspace) {
    this.workspace = workspace;
    _defineProperty(this, "name", 'set <scope-name> [component-pattern]');
    _defineProperty(this, "description", 'Sets the scope for specified component/s. If no component is specified, sets the default scope of the workspace');
    _defineProperty(this, "arguments", [{
      name: 'scope-name',
      description: 'name of the scope to set'
    }, {
      name: 'component-pattern',
      description: _constants().COMPONENT_PATTERN_HELP
    }]);
    _defineProperty(this, "options", []);
    _defineProperty(this, "group", 'development');
    _defineProperty(this, "extendedDescription", `default scopes for components are set in the bitmap file. the default scope for a workspace is set in the workspace.jsonc.
a component is set with a scope (as oppose to default scope) only once it is versioned.'

${(0, _constants().PATTERN_HELP)('scope set scope-name')}`);
  }
  async report([scopeName, pattern]) {
    if (pattern) {
      const componentsIds = await this.workspace.idsByPattern(pattern);
      const changedIds = await this.workspace.setDefaultScopeToComponents(componentsIds, scopeName);
      return _chalk().default.green(`successfully set ${_chalk().default.bold(scopeName)} as the default-scope for the following component(s):
  ${_chalk().default.reset(changedIds.map(id => id.toString()).join('\n'))}`);
    }
    const oldScope = this.workspace.defaultScope;
    await this.workspace.setDefaultScope(scopeName);
    return _chalk().default.green(`successfully set the workspace's default-scope to ${_chalk().default.bold(scopeName)}. (previous scope was "${oldScope}")`);
  }
}
exports.ScopeSetCmd = ScopeSetCmd;

//# sourceMappingURL=scope-set.cmd.js.map