-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbumpVersion.js
More file actions
36 lines (28 loc) · 1.3 KB
/
bumpVersion.js
File metadata and controls
36 lines (28 loc) · 1.3 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
const path = require("path");
const fs = require("fs");
const semver = require("semver");
// Get bump type from CLI argument, e.g. "major", "minor", or "patch"; default is "patch"
const bumpType = process.argv[2] || "patch";
// 1) Path to version.json
const versionJsonPath = path.join(__dirname, "../version.json");
// 2) Path to package.json
const packageJsonPath = path.join(__dirname, "../package.json");
// 3) Read version.json
const versionData = JSON.parse(fs.readFileSync(versionJsonPath, "utf8"));
// 4) Bump the semver version
const oldVersion = versionData.version || "1.0.0";
const newVersion = semver.inc(oldVersion, bumpType);
// 5) Update the in-memory object
versionData.version = newVersion;
// 6) Write back to version.json
fs.writeFileSync(versionJsonPath, JSON.stringify(versionData, null, 2), "utf8");
// 7) Update package.json version
const packageData = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
const oldPkgVersion = packageData.version || "1.0.0";
packageData.version = newVersion;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageData, null, 2), "utf8");
// 8) Console log results
console.log("");
console.log(`✅ Bumped version from ${oldVersion} to ${newVersion}`);
console.log(`✅ Updated package.json version from ${oldPkgVersion} to ${newVersion}`);
console.log("");