-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.ts
61 lines (51 loc) · 1.25 KB
/
update.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
import fs from "fs";
let _version : string = '';
const Settings = {
major: false,
minor: false,
}
process.argv.forEach(function (val, i, arr) {
switch(val.toLowerCase()){
case '--version': case '-v':
_version = arr[i+1];
break;
case '--major': case '-mj':
Settings.major = true;
break;
case '--minor': case '-mn':
Settings.minor = true;
break;
default:
break;
}
});
fs.promises.readFile('./package.json').then((res)=>{
return JSON.parse(res.toString());
}).then(async(res)=>{
if(_version) res.version = _version;
if(res.version){
let version = res.version.split(".").map(c => Number(c));
let newVersion = version.slice();
if(!Settings.major && !Settings.minor){
//patch
newVersion[2] += 1;
}
if(Settings.minor){
//change minor version and reset patch number
newVersion[1] += 1;
newVersion[2] = 0;
}
if(Settings.major){
//change major version and reset major and patch numbers
newVersion[0] += 1;
newVersion[1] = 0;
newVersion[2] = 0;
}
let newRes = JSON.parse(JSON.stringify(res));
newRes.version = newVersion.join(".");
console.log({version, newVersion})
await fs.promises.writeFile('./package.json', JSON.stringify(newRes, null, 4));
}
}).catch((err)=>{
console.debug(err);
});