-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbump-version.js
48 lines (40 loc) · 1.46 KB
/
bump-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
47
48
function updateMajorVersion(semVersion) {
const versionParts = semVersion.split('.');
if (versionParts.length < 1) {
throw new Error("Invalid SemVer string: Major version not found.");
}
versionParts[0] = (parseInt(versionParts[0]) + 1).toString();
return versionParts.join('.');
}
function updateMinorVersion(semVersion) {
const versionParts = semVersion.split('.');
if (versionParts.length < 2) {
throw new Error("Invalid SemVer string: Minor version not found.");
}
versionParts[1] = (parseInt(versionParts[1]) + 1).toString();
return versionParts.join('.');
}
function updatePatchVersion(semVersion) {
const versionParts = semVersion.split('.');
if (versionParts.length < 3) {
console.error("Error: Patch version not found in SemVer string:", semVersion);
return semVersion;
}
versionParts[2] = (parseInt(versionParts[2]) + 1).toString();
return versionParts.join('.');
}
function semverToBuildNumber(version) {
// Split version into major, minor, and optional patch parts
const [major, minor, patch] = version.split('.').map(Number);
// If patch is not present, default it to 0
const actualPatch = patch === undefined ? 0 : patch;
// Calculate build number
const buildNumber = major * 10000 + minor * 100 + actualPatch;
return buildNumber;
}
module.exports = {
updateMajorVersion,
updateMinorVersion,
updatePatchVersion,
semverToBuildNumber
};