UNPKG

@teambit/renaming

Version:
64 lines (62 loc) 3.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScopeRenameCmd = void 0; exports.renameScopeOutput = renameScopeOutput; function _cli() { const data = require("@teambit/cli"); _cli = function () { return data; }; return data; } 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 ScopeRenameCmd { constructor(renaming) { this.renaming = renaming; _defineProperty(this, "name", 'rename <current-scope-name> <new-scope-name>'); _defineProperty(this, "description", "rename the scope name for all components with the specified 'current scope name'. if exported, create new components and delete the original ones"); _defineProperty(this, "extendedDescription", `Note: if \`<current-scope-name>\` is also the defaultScope for the workspace, this command will set \`<new-scope-name>\` as the defaultScope instead, and that will then be set for all components by default. You may see updates in your .bitmap file as a result of this change`); _defineProperty(this, "arguments", [{ name: 'current-scope-name', description: 'the scope name to be replaced by another scope name' }, { name: 'new-scope-name', description: 'a new scope name to replace the current scope name' }]); _defineProperty(this, "options", [['', 'preserve', 'avoid renaming files and variables/classes according to the new scope name'], ['r', 'refactor', 'update the import statements in all dependent components to the new package name (i.e. with the new scope name)'], ['', 'deprecate', 'for exported components, instead of deleting the original components, deprecate them'], ['x', 'skip-dependency-installation', 'do not install dependencies after the rename']]); _defineProperty(this, "group", 'component-config'); _defineProperty(this, "loader", true); } async report([oldName, newName], { refactor, deprecate, preserve, skipDependencyInstallation }) { const result = await this.renaming.renameScope(oldName, newName, { refactor, deprecate, preserve, skipDependencyInstallation }); const renameOutput = renameScopeOutput(result); return (0, _cli().joinSections)([(0, _cli().formatSuccessSummary)(`replaced "${oldName}" scope with "${newName}"`), renameOutput]); } } exports.ScopeRenameCmd = ScopeRenameCmd; function renameScopeOutput(renameResult) { const { renameData, refactoredIds } = renameResult; const renamedSection = renameData.length ? [(0, _cli().formatTitle)(`affected components (${renameData.length})`), ...renameData.map(item => (0, _cli().formatItem)(`${item.sourceId.toStringWithoutVersion()} ${item.isTagged ? '(deprecated) ' : ''}-> ${item.targetId.toString()}`))].join('\n') : ''; const refactoredSection = refactoredIds.length ? [(0, _cli().formatTitle)(`refactored components (${refactoredIds.length})`), ...refactoredIds.map(id => (0, _cli().formatItem)(id.toString()))].join('\n') : ''; return (0, _cli().joinSections)([renamedSection, refactoredSection]); } //# sourceMappingURL=scope-rename.cmd.js.map