Skip to content

Commit a641de4

Browse files
committed
fix(copy-values): write results to disk
1 parent 5efe240 commit a641de4

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/copy-values.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@ import path from 'path';
22
import chalk from 'chalk';
33
import { get, set } from 'lodash';
44
import getFiles from './lib/get-files';
5+
import writeJson from './lib/write-json';
56

67
const getPackage = location => ({ location, json: require(location) });
7-
const formatValue = value => JSON.stringify(value);
8+
const toJson = value => JSON.stringify(value);
9+
10+
const reportChange = (key, previous, next) => {
11+
if (toJson(previous) === toJson(next)) {
12+
console.log(`${key}: ${chalk.green('✓ unchanged')}`);
13+
} else {
14+
console.log(`${key}: ${chalk.red(toJson(previous))}${chalk.green(toJson(next))}`);
15+
}
16+
};
817

918
export default async ({ keys, packagesPattern, sourcePattern }) => {
1019
const [source] = (await getFiles(sourcePattern)).map(getPackage);
1120
const packages = (await getFiles(packagesPattern)).map(getPackage);
12-
1321
packages.forEach(pkg => {
1422
console.log(chalk.grey.underline(path.relative(process.cwd(), pkg.location)));
1523
keys.forEach(key => {
1624
const value = get(source.json, key);
17-
const previousValue = formatValue(get(pkg.json, key));
25+
const previousValue = get(pkg.json, key);
1826
set(pkg.json, key, value);
19-
const nextValue = formatValue(value);
20-
if (previousValue === nextValue) {
21-
console.log(`${key}: ${chalk.green('✓ unchanged')}`);
22-
} else {
23-
console.log(`${key}: ${chalk.red(previousValue)}${chalk.green(nextValue)}`);
24-
}
27+
writeJson(pkg.location, pkg.json);
28+
reportChange(key, previousValue, value);
2529
});
2630
});
2731
};

0 commit comments

Comments
 (0)