forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalign-version.js
executable file
·34 lines (27 loc) · 1014 Bytes
/
align-version.js
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
#!/usr/bin/env node
//
// align the version in a package.json file to the version of the repo
//
const fs = require('fs');
const ver = require('./resolve-version');
const marker = ver.marker;
const repoVersion = ver.version;
for (const file of process.argv.splice(2)) {
const pkg = JSON.parse(fs.readFileSync(file).toString());
if (pkg.version !== marker) {
throw new Error(`unexpected - all package.json files in this repo should have a version of ${marker}: ${file}`);
}
pkg.version = repoVersion;
processSection(pkg.dependencies || { }, file);
processSection(pkg.devDependencies || { }, file);
processSection(pkg.peerDependencies || { }, file);
console.error(`${file} => ${repoVersion}`);
fs.writeFileSync(file, JSON.stringify(pkg, undefined, 2));
}
function processSection(section, file) {
for (const [ name, version ] of Object.entries(section)) {
if (version === marker || version === '^' + marker) {
section[name] = version.replace(marker, repoVersion);
}
}
}