From 29beb97fb7df8fa385bcf59dc21ba51592a1bfa9 Mon Sep 17 00:00:00 2001 From: Sander Blue Date: Wed, 7 Aug 2024 13:27:29 -0500 Subject: [PATCH] chore(automation): schema-differ.js code cleanup/refactor --- scripts/schema-differ.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/scripts/schema-differ.js b/scripts/schema-differ.js index 6bf4e7638..61a29e118 100644 --- a/scripts/schema-differ.js +++ b/scripts/schema-differ.js @@ -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}`, - }); } }