This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbumpVersion.ts
52 lines (41 loc) · 1.59 KB
/
bumpVersion.ts
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
import fs from 'fs'
const bumpMetric = process.argv[2];
const supportedBumps = ["major", "minor", "patch"]
const nodePackagJsonPath = 'package.json';
const adoExtensionJsonPath = 'ado-extension.json';
const adoTaskJsonPath = 'src/task.json';
if (process.argv.length != 3) {
throw "Need exactly one argument!"
}
if (!supportedBumps.includes(bumpMetric)) {
console.error("Cannot bump `" + bumpMetric + "`. Can only bump one of " + supportedBumps.join("/"))
throw "Invalid bump requested!"
}
var nodePackageJson = JSON.parse(fs.readFileSync(nodePackagJsonPath,'utf8'));
var adoExtensionJson = JSON.parse(fs.readFileSync(adoExtensionJsonPath,'utf8'));
var adoTaskJson = JSON.parse(fs.readFileSync(adoTaskJsonPath,'utf8'));
const versions = nodePackageJson['version'].split(".");
var major = Number(versions[0]);
var minor = Number(versions[1]);
var patch = Number(versions[2]);
if (bumpMetric == 'major') {
major += 1;
minor = 0;
patch = 0;
} else if (bumpMetric == 'minor') {
minor += 1;
patch = 0;
} else {
patch += 1;
}
const newVersion = major + "." + minor + "." + patch;
// Update each jsons
nodePackageJson['version'] = newVersion;
adoExtensionJson['version'] = newVersion;
adoTaskJson['version']['Major'] = major;
adoTaskJson['version']['Minor'] = minor;
adoTaskJson['version']['Patch'] = patch;
fs.writeFileSync(nodePackagJsonPath, JSON.stringify(nodePackageJson, null, 4));
fs.writeFileSync(adoExtensionJsonPath, JSON.stringify(adoExtensionJson, null, 4));
fs.writeFileSync(adoTaskJsonPath, JSON.stringify(adoTaskJson, null, 4));
console.log("New version is: " + newVersion);