UNPKG

@teambit/renaming

Version:
63 lines (61 loc) 3.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScopeRenameCmd = void 0; exports.renameScopeOutput = renameScopeOutput; 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 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, deprecating them']]); _defineProperty(this, "group", 'component-config'); } async report([oldName, newName], { refactor, deprecate, preserve }) { const result = await this.renaming.renameScope(oldName, newName, { refactor, deprecate, preserve }); const title = _chalk().default.green(`successfully replaced "${oldName}" scope with "${newName}"`); const renameOutput = renameScopeOutput(result); return `${title}\n${renameOutput}`; } } exports.ScopeRenameCmd = ScopeRenameCmd; function renameScopeOutput(renameResult) { const { renameData, refactoredIds } = renameResult; const renamedIdsStr = renameData.length ? `\n${_chalk().default.bold('the following components were affected by this scope-name change:')}\n${renameData.map(item => `${item.sourceId.toStringWithoutVersion()} ${item.isTagged ? '(deprecated) ' : ''}-> ${item.targetId.toString()}`).join('\n')}` : ''; const refactoredStr = refactoredIds.length ? `\n\n${_chalk().default.bold('the following components have been refactored:')}\n${refactoredIds.join('\n')}` : ''; return renamedIdsStr + refactoredStr; } //# sourceMappingURL=scope-rename.cmd.js.map