forked from aws/jsii
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalign-version.js
executable file
·46 lines (37 loc) · 1.27 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
//
// align the version in a package.json file to the version of the repo
//
const fs = require('fs');
const marker = require('./get-version-marker');
const repoVersion = require('./get-version');
const exclude = [
'jsii-calc',
'@scope/jsii-calc-base-of-base'
]
for (const file of process.argv.splice(2)) {
const pkg = JSON.parse(fs.readFileSync(file).toString());
// Ignore fixture packages
if (pkg.name === '@fixtures/jsii-calc-bundled') {
continue;
}
// jsii-calc have special versions to test golang major version suffix
if (!exclude.includes(pkg.name)) {
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);
}
}
}