Skip to content

Instantly share code, notes, and snippets.

@muhammaddadu
Created January 16, 2017 16:05
Show Gist options
  • Save muhammaddadu/3dc04c58531813c44f62c8b41c12d082 to your computer and use it in GitHub Desktop.
Save muhammaddadu/3dc04c58531813c44f62c8b41c12d082 to your computer and use it in GitHub Desktop.
comparse two node_module folders for versions
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const _ = require('lodash');
let p = (...args) => path.join.apply(this, [__dirname, '..', ...args]);
const NODE_MODULES_DIR = p('node_modules');
const NODE_MODULES_COMPARE_DIR = p('node_modules.bk');
const MANIFEST = require(p('package.json'));
const PACKAGES = Object.keys(MANIFEST.devDependencies);
let mapPackages = {};
function getPackageVersionsFromDir(dir, dest, identifier) {
PACKAGES.forEach((name) => {
let packageFile = path.join(dir, name, 'package.json');
let packageManifest = require(packageFile);
!dest[name] && (dest[name] = {
name: name,
version: MANIFEST.devDependencies[name]
});
dest[name][identifier] = packageManifest.version;
});
}
getPackageVersionsFromDir(NODE_MODULES_DIR, mapPackages, 'broken');
getPackageVersionsFromDir(NODE_MODULES_COMPARE_DIR, mapPackages, 'working');
mapPackages = _.filter(mapPackages, (data) => data.broken !== data.working);
console.log(JSON.stringify(mapPackages, null, '\t'));
// function listPackageVersionsFromDir(dir, dest, identifier) {
// fs.readdirSync(dir)
// .filter((name) => {
// let manifestPath = path.join(dir, name, 'package.json');
// let isPackage = fs.existsSync(manifestPath);
// if (!isPackage) {
// // console.warn(`${name} is not a package`);
// }
// return isPackage;
// })
// .forEach((name) => {
// let manifestPath = path.join(dir, name, 'package.json');
// let manifest = require(manifestPath);
// !dest[name] && (dest[name] = {
// name: name,
// version: MANIFEST.devDependencies[name]
// });
// dest[name][identifier] = manifest.version;
// });
// }
// listPackageVersionsFromDir(NODE_MODULES_DIR, mapPackages, 'broken');
// listPackageVersionsFromDir(NODE_MODULES_COMPARE_DIR, mapPackages, 'working');
// mapPackages = _.filter(mapPackages, (data) => data.broken !== data.working);
// console.log(JSON.stringify(mapPackages, null, '\t'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment