@agility/cli
Version:
Agility CLI for working with your content. (Public Beta)
88 lines • 4.64 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.logModelDifferences = logModelDifferences;
exports.logFieldArrayDifferences = logFieldArrayDifferences;
var ansi_colors_1 = __importDefault(require("ansi-colors"));
var lodash_1 = __importDefault(require("lodash"));
/**
* Model Diff Logger - Extracted from model-pusher.ts
* Provides detailed logging for model differences during sync operations
*/
// Function to log detailed differences between two model objects
function logModelDifferences(source, target, modelName) {
console.log(ansi_colors_1.default.yellow("[DIFF] Differences for ".concat(modelName, ":")));
var allKeys = lodash_1.default.union(Object.keys(source), Object.keys(target)).sort();
for (var _i = 0, allKeys_1 = allKeys; _i < allKeys_1.length; _i++) {
var key = allKeys_1[_i];
var sourceVal = source[key];
var targetVal = target[key];
if (!lodash_1.default.has(target, key)) {
console.log(ansi_colors_1.default.green(" + Source only: ".concat(key, " = ").concat(JSON.stringify(sourceVal, null, 2))));
}
else if (!lodash_1.default.has(source, key)) {
console.log(ansi_colors_1.default.red(" - Target only: ".concat(key, " = ").concat(JSON.stringify(targetVal, null, 2))));
}
else if (!lodash_1.default.isEqual(sourceVal, targetVal)) {
console.log(ansi_colors_1.default.yellow(" ~ Different: ".concat(key)));
if (key === "fields" && Array.isArray(sourceVal) && Array.isArray(targetVal)) {
logFieldArrayDifferences(sourceVal, targetVal);
}
else if (typeof sourceVal === "object" &&
sourceVal !== null &&
typeof targetVal === "object" &&
targetVal !== null) {
// For nested objects, show both values if they are not too large
console.log(ansi_colors_1.default.green(" Source Value: ".concat(JSON.stringify(sourceVal, null, 2))));
console.log(ansi_colors_1.default.red(" Target Value: ".concat(JSON.stringify(targetVal, null, 2))));
}
else {
console.log(ansi_colors_1.default.green(" Source Value: ".concat(sourceVal)));
console.log(ansi_colors_1.default.red(" Target Value: ".concat(targetVal)));
}
}
}
}
function logFieldArrayDifferences(sourceFields, targetFields) {
var sourceFieldNames = sourceFields.map(function (f) { return f.name; });
var targetFieldNames = targetFields.map(function (f) { return f.name; });
// Fields only in source
sourceFields
.filter(function (sf) { return !targetFieldNames.includes(sf.name); })
.forEach(function (sf) {
console.log(ansi_colors_1.default.green(" + Source Field only: ".concat(sf.name, " (Type: ").concat(sf.type, ")")));
});
// Fields only in target
targetFields
.filter(function (tf) { return !sourceFieldNames.includes(tf.name); })
.forEach(function (tf) {
console.log(ansi_colors_1.default.red(" - Target Field only: ".concat(tf.name, " (Type: ").concat(tf.type, ")")));
});
// Fields in both - compare them
sourceFields
.filter(function (sf) { return targetFieldNames.includes(sf.name); })
.forEach(function (sf) {
var tf = targetFields.find(function (f) { return f.name === sf.name; });
var fieldDifferencesFound = false;
var diffMessages = [];
if (sf.label !== tf.label) {
diffMessages.push(" Label: Source='".concat(sf.label, "', Target='").concat(tf.label, "'"));
fieldDifferencesFound = true;
}
if (sf.type !== tf.type) {
diffMessages.push(" Type: Source='".concat(sf.type, "', Target='").concat(tf.type, "'"));
fieldDifferencesFound = true;
}
if (!lodash_1.default.isEqual(sf.settings, tf.settings)) {
diffMessages.push(" Settings: Source=".concat(JSON.stringify(sf.settings), ", Target=").concat(JSON.stringify(tf.settings)));
fieldDifferencesFound = true;
}
if (fieldDifferencesFound) {
console.log(ansi_colors_1.default.yellow(" ~ Field ".concat(sf.name, " (Type: ").concat(sf.type, ") differs:")));
diffMessages.forEach(function (msg) { return console.log(msg); });
}
});
}
//# sourceMappingURL=model-diff-logger.js.map