-
Notifications
You must be signed in to change notification settings - Fork 2
/
updateVersion.ts
52 lines (38 loc) · 2.05 KB
/
updateVersion.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 * as fs from "fs";
import * as os from "os";
import version from "./version";
function updateVersionInackageJsonFile(packageJsonFilePath: string, version: string): void {
const packageJsonContent = fs.readFileSync(packageJsonFilePath, "utf8");
const packageJson = JSON.parse(packageJsonContent);
packageJson.version = version;
fs.writeFileSync(packageJsonFilePath, JSON.stringify(packageJson, null, 2).concat(os.EOL));
}
function updateVersionInVssExtensionJsonFile(vssExtensionJsonFilePath: string, version: string): void {
const vssExtensionJsonContent = fs.readFileSync(vssExtensionJsonFilePath, "utf8");
const vssExtensionJson = JSON.parse(vssExtensionJsonContent);
vssExtensionJson.version = version.split("-")[0];
fs.writeFileSync(vssExtensionJsonFilePath, JSON.stringify(vssExtensionJson, null, 4).concat(os.EOL));
}
function updateVersionInTaskJsonFile(taskJsonFilePath: string, version: string): void {
const taskJsonContent = fs.readFileSync(taskJsonFilePath, "utf8");
const taskJson = JSON.parse(taskJsonContent);
const splittedVersion = version.split(".");
taskJson.version.Major = Number(splittedVersion[0]);
taskJson.version.Minor = Number(splittedVersion[1]);
taskJson.version.Patch = Number(splittedVersion[2].split("-")[0]);
const Preview = "Preview";
if (version.split("-").length > 1 && !taskJson.visibility.includes(Preview)) {
taskJson.visibility.push(Preview);
}
if (version.split("-").length === 1 && taskJson.visibility.includes(Preview)) {
const index = taskJson.visibility.indexOf(Preview, 0);
if (index > -1) {
taskJson.visibility.splice(index, 1);
}
}
fs.writeFileSync(taskJsonFilePath, JSON.stringify(taskJson, null, 4).concat(os.EOL));
}
updateVersionInackageJsonFile("./package.json", version);
updateVersionInackageJsonFile("./tasks/cloc-build-task/package.json", version);
updateVersionInVssExtensionJsonFile("./vss-extension.json", version);
updateVersionInTaskJsonFile("./tasks/cloc-build-task/task.json", version);