UNPKG

@abaplint/core

Version:
50 lines 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RenameICFService = void 0; const __1 = require(".."); const renamer_helper_1 = require("./renamer_helper"); class RenameICFService { constructor(reg) { this.reg = reg; } buildEdits(obj, oldName, newName) { var _a, _b, _c, _d; if (!(obj instanceof __1.ICFService)) { throw new Error("RenameICFService, not a ICF Service"); } // Preserve GUID suffix from the stored object/file name for the filename rename // SICF files follow pattern: servicename.sicf or servicename {GUID}.sicf const fileNewName = (() => { // Look for pattern: space + GUID (32 hex chars in braces) + optional extension const guidPattern = / \{[0-9A-Fa-f]{16,32}\}/; const match = oldName.match(guidPattern); if (match) { // Extract everything from the GUID onwards (includes .sicf extension if present) const guidIndex = match.index; const suffix = oldName.substring(guidIndex); // Only append suffix if newName doesn't already contain it return newName.includes(suffix) ? newName : newName + suffix; } // Fallback: preserve any suffix after first space (legacy behavior) const space = oldName.indexOf(" "); if (space > -1) { const suffix = oldName.substring(space); return newName.includes(suffix) ? newName : newName + suffix; } return newName; })(); const cleanOldName = (_b = (_a = oldName.match(/^[^ ]+/)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : oldName; const cleanNewName = (_d = (_c = newName.match(/^[^ ]+/)) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : newName; let changes = []; const helper = new renamer_helper_1.RenamerHelper(this.reg); changes = changes.concat(helper.buildURLFileEdits(obj, cleanOldName, cleanNewName)); changes = changes.concat(helper.buildXMLFileEdits(obj, "ICF_NAME", cleanOldName, cleanNewName)); changes = changes.concat(helper.buildXMLFileEdits(obj, "ORIG_NAME", cleanOldName, cleanNewName, true)); changes = changes.concat(helper.renameFiles(obj, oldName, fileNewName)); return { documentChanges: changes, }; } } exports.RenameICFService = RenameICFService; //# sourceMappingURL=rename_icf_service.js.map