Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created March 29, 2017 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelrinaldi/da862542437211251b37ad3b2c1f8b51 to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/da862542437211251b37ad3b2c1f8b51 to your computer and use it in GitHub Desktop.
/**
* Simple script that compares our npm manifest against Oscar's manifest
* and list all results that don't match versions.
*
* Usage:
*
* node tools/diff-package-json.js path/to/oscar/package.json
**/
const current = require('../package');
const target = require(process.argv[2]);
function getDependencies(source) {
return Object.assign(source.dependencies, source.devDependencies);
}
function diff(mine, theirs) {
const myKeys = Object.keys(mine);
const theirKeys = Object.keys(theirs);
const changes = theirKeys
.filter(dependency => {
return myKeys.includes(dependency);
})
.filter(dependency => {
const myVersion = mine[dependency];
const theirVersion = theirs[dependency];
return myVersion !== theirVersion;
});
const size = changes.reduce((previous, next) => {
return next.length > previous.length ? next : previous;
}, 'Dependency').length;
const format = (content, size) => {
const difference = (size - content.length) + 1;
const pad = new Array(difference).join(' ');
return `${content}${pad}`;
};
console.log(`${format('Dependency', size)} | Mine\t| Theirs`);
changes.forEach(change => {
const myVersion = mine[change];
const theirVersion = theirs[change];
console.log(`${format(change, size)} | ${myVersion}\t| ${theirVersion}`);
});
}
const mine = getDependencies(current);
const theirs = getDependencies(target);
console.log(diff(mine, theirs));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment