Skip to content

Instantly share code, notes, and snippets.

@KMR-zoar
Created June 5, 2019 06:10
Show Gist options
  • Save KMR-zoar/2be0174418d6a9c429eafc771daf5462 to your computer and use it in GitHub Desktop.
Save KMR-zoar/2be0174418d6a9c429eafc771daf5462 to your computer and use it in GitHub Desktop.
const master = process.argv[2]
const source = process.argv[3]
const fs = require('fs')
if (master === undefined || source === undefined) {
console.log('Insufficient arguments.')
process.exit(1)
}
const masterObj = JSON.parse(fs.readFileSync(master, { encoding: 'utf8' }))
const sourceObj = JSON.parse(fs.readFileSync(source, { encoding: 'utf8' }))
const increasedKeyArray = {}
const decreasedKeyArray = {}
Object.keys(masterObj).forEach(key => {
if (!(sourceObj[key] === undefined)) {
masterObj[key] = sourceObj[key]
} else {
increasedKeyArray[key] = masterObj[key]
}
})
Object.keys(sourceObj).forEach(key => {
if (masterObj[key] === undefined) {
decreasedKeyArray[key] = sourceObj[key]
}
})
fs.writeFileSync('result.json', JSON.stringify(masterObj, null, 2))
fs.writeFileSync(
'increasedKeys.json',
JSON.stringify(increasedKeyArray, null, 2)
)
fs.writeFileSync(
'decreasedKeys.json',
JSON.stringify(decreasedKeyArray, null, 2)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment