UNPKG

@agility/cli

Version:

Agility CLI for working with your content. (Public Beta)

98 lines 4.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContentItemMapper = void 0; var core_1 = require("../../core"); var ContentItemMapper = /** @class */ (function () { function ContentItemMapper(sourceGuid, targetGuid, locale) { this.sourceGuid = sourceGuid; this.targetGuid = targetGuid; this.directory = 'item'; this.locale = locale; // this will provide access to the /agility-files/{GUID}/{locale} folder this.fileOps = new core_1.fileOperations(targetGuid, locale); this.mappings = this.loadMapping(); } ContentItemMapper.prototype.getContentItemMapping = function (contentItem, type) { var mapping = this.mappings.find(function (m) { return type === 'source' ? m.sourceContentID === contentItem.contentID : m.targetContentID === contentItem.contentID; }); if (!mapping) return null; return mapping; }; ContentItemMapper.prototype.getContentItemMappingByContentID = function (contentID, type) { var mapping = this.mappings.find(function (m) { return type === 'source' ? m.sourceContentID === contentID : m.targetContentID === contentID; }); if (!mapping) return null; return mapping; }; ContentItemMapper.prototype.getMappedEntity = function (mapping, type) { //fetch the content item from the file system based on source or target GUID if (!mapping) return null; var guid = type === 'source' ? mapping.sourceGuid : mapping.targetGuid; var contentID = type === 'source' ? mapping.sourceContentID : mapping.targetContentID; var fileOps = new core_1.fileOperations(guid, this.locale); // Use the file operations to get the content item file path var contentData = fileOps.readJsonFile("item/".concat(contentID, ".json")); if (!contentData) return null; return contentData; }; ContentItemMapper.prototype.addMapping = function (sourceContentItem, targetContentItem) { var mapping = this.getContentItemMapping(targetContentItem, 'target'); if (mapping) { this.updateMapping(sourceContentItem, targetContentItem); } else { var newMapping = { sourceGuid: this.sourceGuid, targetGuid: this.targetGuid, sourceContentID: sourceContentItem.contentID, targetContentID: targetContentItem.contentID, sourceVersionID: sourceContentItem.properties.versionID, targetVersionID: targetContentItem.properties.versionID, }; this.mappings.push(newMapping); } this.saveMapping(); }; ContentItemMapper.prototype.updateMapping = function (sourceContentItem, targetContentItem) { var mapping = this.getContentItemMapping(targetContentItem, 'target'); if (mapping) { mapping.sourceGuid = this.sourceGuid; mapping.targetGuid = this.targetGuid; mapping.sourceContentID = sourceContentItem.contentID; mapping.targetContentID = targetContentItem.contentID; mapping.sourceVersionID = sourceContentItem.properties.versionID; mapping.targetVersionID = targetContentItem.properties.versionID; } this.saveMapping(); }; ContentItemMapper.prototype.loadMapping = function () { var mapping = this.fileOps.getMappingFile(this.directory, this.sourceGuid, this.targetGuid, this.locale); return mapping; }; ContentItemMapper.prototype.saveMapping = function () { this.fileOps.saveMappingFile(this.mappings, this.directory, this.sourceGuid, this.targetGuid, this.locale); }; ContentItemMapper.prototype.hasSourceChanged = function (sourceContentItem) { if (!sourceContentItem) return false; var mapping = this.getContentItemMapping(sourceContentItem, 'source'); if (!mapping) return true; return sourceContentItem.properties.versionID > mapping.sourceVersionID; }; ContentItemMapper.prototype.hasTargetChanged = function (targetContentItem) { var mapping = this.getContentItemMapping(targetContentItem, 'target'); if (!mapping) return false; return targetContentItem.properties.versionID > mapping.targetVersionID; }; return ContentItemMapper; }()); exports.ContentItemMapper = ContentItemMapper; //# sourceMappingURL=content-item-mapper.js.map