Skip to content

Commit

Permalink
chore(automation): schema-differ.js code cleanup/refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderblue committed Aug 8, 2024
1 parent c68e357 commit 29beb97
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions scripts/schema-differ.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,32 @@ function compareObjects(obj1, obj2, path = '') {
let differences = [];

for (let key in obj1) {
if (obj1.hasOwnProperty(key) && obj2.hasOwnProperty(key)) {
if (!obj2.hasOwnProperty(key)) {
differences.push({
old: obj1[key],
new: undefined,
property: `${path}.${key}`,
});

continue;
}

if (obj2.hasOwnProperty(key)) {
if (typeof obj1[key] === 'object' && typeof obj2[key] === 'object') {
differences = differences.concat(compareObjects(obj1[key], obj2[key], `${path}.${key}`));
} else if (obj1[key] !== obj2[key]) {

continue;
}

if (obj1[key] !== obj2[key]) {
differences.push({
old: obj1[key],
new: obj2[key],
property: `${path}.${key}`,
});

continue;
}
} else {
differences.push({
old: obj1[key],
new: obj2[key] ? obj2[key] : undefined,
property: `${path}.${key}`,
});
}
}

Expand Down

0 comments on commit 29beb97

Please sign in to comment.