UNPKG

@agility/cli

Version:

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

76 lines 3.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.changeDetection = changeDetection; var core_1 = require("../../../../core"); function changeDetection(sourceEntity, targetEntity, mapping, locale) { var _a, _b; if (!mapping && !targetEntity) { //if we have no target content and no mapping return { entity: null, shouldUpdate: false, shouldCreate: true, shouldSkip: false, isConflict: false, reason: 'Entity does not exist in target' }; } // Check if update is needed based on version or modification date var sourceVersion = ((_a = sourceEntity.properties) === null || _a === void 0 ? void 0 : _a.versionID) || 0; var targetVersion = ((_b = targetEntity.properties) === null || _b === void 0 ? void 0 : _b.versionID) || 0; var mappedSourceVersion = ((mapping === null || mapping === void 0 ? void 0 : mapping.sourceVersionID) || 0); var mappedTargetVersion = ((mapping === null || mapping === void 0 ? void 0 : mapping.targetVersionID) || 0); if (sourceVersion > 0 && targetVersion > 0) //both the source and the target exist if (sourceVersion > mappedSourceVersion && targetVersion > mappedTargetVersion) { //CONFLICT DETECTION // Source version is newer than mapped source version // and target version is newer than mapped target version //build the url to the source and target entity //TODO: if there are multiple guids we need to handle that var sourceUrl = "https://app.agilitycms.com/instance/".concat(core_1.state.sourceGuid[0], "/").concat(locale, "/content/listitem-").concat(sourceEntity.contentID); var targetUrl = "https://app.agilitycms.com/instance/".concat(core_1.state.targetGuid[0], "/").concat(locale, "/content/listitem-").concat(targetEntity.contentID); return { entity: targetEntity, shouldUpdate: false, shouldCreate: false, shouldSkip: false, isConflict: true, reason: "Both source and target versions have been updated. Please resolve manually.\n - source: ".concat(sourceUrl, " \n - target: ").concat(targetUrl, ".") }; } if (sourceVersion > mappedSourceVersion && targetVersion <= mappedTargetVersion) { //SOURCE UPDATE ONLY // Source version is newer the mapped source version // and target version is NOT newer than mapped target version return { entity: targetEntity, shouldUpdate: true, shouldCreate: false, shouldSkip: false, isConflict: false, reason: 'Source version is newer.' }; } var overwrite = core_1.state.overwrite; if (overwrite) { return { entity: targetEntity, shouldUpdate: true, shouldCreate: false, shouldSkip: false, isConflict: false, reason: 'Overwrite mode enabled' }; } return { entity: targetEntity, shouldUpdate: false, shouldCreate: false, shouldSkip: true, isConflict: false, // No update needed, target is up to date reason: 'Entity exists and is up to date' }; } //# sourceMappingURL=change-detection.js.map