blob: 5c9a2d6ff28c3a2fb4b60a5dfa0b6140f279fe40 (
plain) (
tree)
|
|
#!/usr/bin/env node
import chalk from 'chalk';
import * as fs from 'fs';
import { sync as globSync } from 'glob';
import * as _ from 'lodash';
interface Dependencies {
[depName: string]: string;
}
interface Versions {
[packageName: string]: string;
}
interface VersionsByDependency {
[depName: string]: Versions;
}
const PACKAGE_JSON_GLOB = '../*/package.json';
function log(...args: any[]) {
console.log(...args); // tslint:disable-line:no-console
}
function getDependencies(path: string): Dependencies {
const file = fs.readFileSync(path).toString();
const parsed = JSON.parse(file);
const dependencies = {
...parsed.dependencies,
...parsed.devDependencies,
};
return dependencies;
}
const files = globSync(PACKAGE_JSON_GLOB);
const versionsByDependency: VersionsByDependency = {};
files.map(path => {
const [_1, packageName, _2] = path.split('/');
const dependencies = getDependencies(path);
_.map(dependencies, (version: string, depName: string) => {
if (_.isUndefined(versionsByDependency[depName])) {
versionsByDependency[depName] = {};
}
versionsByDependency[depName][packageName] = version;
});
});
_.map(versionsByDependency, (versions: Versions, depName: string) => {
if (_.uniq(_.values(versions)).length === 1) {
delete versionsByDependency[depName];
} else {
log(chalk.bold(depName));
_.map(versions, (version: string, packageName: string) => {
log(`├── ${packageName} -> ${version}`);
});
}
});
|