Skip to content

Commit

Permalink
feat(fix-mismatches): output which files are (un)changed
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Feb 3, 2019
1 parent b198353 commit a79b078
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/fix-mismatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getIndent } from './lib/get-indent';
import { getPackages } from './lib/get-packages';
import { getMismatchedVersionsByName } from './lib/get-versions-by-name';
import { getNewest } from './lib/version';
import { CommanderApi } from './typings';
import { CommanderApi, IManifest } from './typings';

export const run = async (program: CommanderApi) => {
program
Expand All @@ -34,29 +34,38 @@ export const run = async (program: CommanderApi) => {
pkgs
);

Object.entries(mismatchedVersionsByName).forEach(([name, versions]) => {
const newest = getNewest(versions);
pkgs.forEach(({ data, path }) => {
dependencyTypes.forEach((type) => {
if (data[type] && data[type][name] && data[type][name] !== newest) {
await Promise.all(
pkgs.map(({ data, path }) => {
const nextData: IManifest = JSON.parse(JSON.stringify(data));
const shortPath = `./${relative('.', path)}`;
const changes: string[][] = [];
Object.entries(mismatchedVersionsByName).forEach(([name, versions]) => {
const newest = getNewest(versions);
dependencyTypes.forEach((type) => {
if (
nextData[type] &&
nextData[type][name] &&
nextData[type][name] !== newest
) {
changes.push([name, nextData[type][name], newest]);
nextData[type][name] = newest;
}
});
});
if (changes.length > 0) {
changes.forEach(([name, from, to]) => {
console.log(
relative(process.cwd(), path),
chalk.bgYellow.black(' FIXED '),
chalk.blue(shortPath),
name,
data[type][name],
'->',
newest
chalk.red(from),
'',
chalk.green(to)
);
data[type][name] = newest;
}
});
});
});

await Promise.all(
pkgs.map(({ data, path }) => writeJson(path, data, { spaces: indent }))
});
return writeJson(path, nextData, { spaces: indent });
}
console.log(chalk.bgGreen.black(' VALID '), chalk.blue(shortPath));
})
);

_.each(pkgs, (pkg) => {
console.log(chalk.blue(`./${relative('.', pkg.path)}`));
});
};

0 comments on commit a79b078

Please sign in to comment.