aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts/src/deps_versions.ts
blob: d8728daded118c64e0a99673ae237c55000ef6de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node

import { logUtils } from '@0xproject/utils';
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 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 {
        logUtils.log(chalk.bold(depName));
        _.map(versions, (version: string, packageName: string) => {
            logUtils.log(`├── ${packageName} -> ${version}`);
        });
    }
});