-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbump-version.js
More file actions
59 lines (49 loc) · 1.92 KB
/
Copy pathbump-version.js
File metadata and controls
59 lines (49 loc) · 1.92 KB
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
54
55
56
57
58
59
const { globSync } = require("glob");
const fs = require("fs");
const newVersion = process.argv[2];
if (!newVersion) {
console.log("please specify the new version as an argument, e.g. '1.3.0-rc.0'");
process.exit(1);
}
let peerDepVersion = `^${newVersion}`;
if (newVersion.indexOf("-") > 0) {
const idx = newVersion.lastIndexOf(".");
peerDepVersion = `^${newVersion.substr(0, idx)}`;
}
console.log(`bumping to version ${newVersion}, peer dependency = ${peerDepVersion}`);
for (const file of globSync("**/package.json", { ignore: ["node_modules/**", "package.json"] })) {
updatePackageLock(file);
}
// Also bump the root package.json version (used as the release version tag)
updateRootVersion("package.json");
function updateRootVersion(path) {
const spec = JSON.parse(fs.readFileSync(path, { encoding: "utf8" }));
spec.version = newVersion;
fs.writeFileSync(path, JSON.stringify(spec, undefined, 4), { options: "utf8" });
fs.appendFileSync(path, "\n", { encoding: "utf8" });
console.log(` bumped root package.json to ${newVersion}`);
}
function updatePackageLock(path) {
const spec = JSON.parse(fs.readFileSync(path, { encoding: "utf8" }));
if (!spec.name) return;
if (spec.name.startsWith("@walmartlabs/") && !spec.deprecated) {
spec.version = newVersion;
} else if (spec.deprecated) {
console.log(` skipping version bump for deprecated package: ${spec.name}`);
}
const sections = [
"dependencies",
"devDependencies",
"peerDependencies",
];
for (const section of sections) {
if (!spec[section]) continue;
for (const name in spec[section]) {
if (name.startsWith("@walmartlabs/")) {
spec[section][name] = peerDepVersion;
}
}
}
fs.writeFileSync(path, JSON.stringify(spec, undefined, 4), { options: "utf8" });
fs.appendFileSync(path, "\n", { encoding: "utf8" });
}