-
Notifications
You must be signed in to change notification settings - Fork 0
/
increment-build.ts
77 lines (63 loc) · 2.43 KB
/
increment-build.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as fs from 'fs';
const vssExtensionfilePath = './vss-extension.json';
const taskFilePath = './MobbAutofixer/0.1.0/task.json'
function incrementVersionVssExtension(version: string): string {
const versionParts = version.split('.');
const lastPartIndex = versionParts.length - 1;
const lastPart = parseInt(versionParts[lastPartIndex]);
if(isNaN(lastPart)){
throw new Error('invalid version format');
}
versionParts[lastPartIndex] = (lastPart + 1).toString();
return versionParts.join('.');
}
fs.readFile(vssExtensionfilePath, 'utf-8',(err,data)=>{
if (err){
console.log('error reading the file: ', err);
return;
}
try {
const jsonData = JSON.parse(data);
const currentVersion = jsonData.version;
const newVersion = incrementVersionVssExtension(currentVersion);
console.log(`vss-exntension.json old Version: ${currentVersion}`);
console.log(`vss-exntension.json new Version: ${newVersion}`);
jsonData.version = newVersion;
fs.writeFile(vssExtensionfilePath,JSON.stringify(jsonData,null,4),'utf8',(writeErr)=>{
if (writeErr){
console.error('Error writing file: ', writeErr);
return;
}
console.log('vss-extension.json version updated successfullly!');
});
} catch(parseErr){
console.error('error parsing json: ', parseErr);
}
});
fs.readFile(taskFilePath, 'utf-8',(err,data)=>{
if (err){
console.log('error reading the file: ', err);
return;
}
try {
const jsonData = JSON.parse(data);
const currentVersion = jsonData.version.Patch;
const currentVersionInInt = parseInt(currentVersion);
if(isNaN(currentVersionInInt)){
throw new Error('invalid version format');
}
const newVersion = currentVersionInInt + 1;
console.log(`task.json old Version: ${currentVersion}`);
console.log(`task.json new Version: ${newVersion}`);
jsonData.version.Patch = newVersion;
fs.writeFile(taskFilePath,JSON.stringify(jsonData,null,4),'utf8',(writeErr)=>{
if (writeErr){
console.error('Error writing file: ', writeErr);
return;
}
console.log('task.json version updated successfullly!');
});
} catch(parseErr){
console.error('error parsing json: ', parseErr);
}
});