forked from calzoneman/sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.py
73 lines (68 loc) · 2.41 KB
/
version.py
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
#!/usr/bin/python3
import re
import sys
PKGVER = re.compile(r'"version":(?:\s+)?"(\d)\.(\d)\.(\d)"')
SERVER = re.compile(r'VERSION(?:\s+)?=(?:\s+)"(\d)\.(\d)\.(\d)";')
OP = "patch"
if len(sys.argv) > 1 and sys.argv[1] in ["patch", "minor", "major"]:
OP = sys.argv[1]
pkgbuf = []
with open("package.json") as f:
for line in f:
m = PKGVER.search(line)
sb = []
if m:
sb.append(line[:m.start(1)])
if OP == "major":
sb.append(str(int(line[m.start(1):m.end(1)])+1))
else:
sb.append(line[m.start(1):m.end(1)])
sb.append(line[m.end(1):m.start(2)])
if OP == "minor":
sb.append(str(int(line[m.start(2):m.end(2)])+1))
elif OP == "major":
sb.append("0")
else:
sb.append(line[m.start(2):m.end(2)])
sb.append(line[m.end(2):m.start(3)])
if OP == "patch":
sb.append(str(int(line[m.start(3):m.end(3)])+1))
elif OP == "minor" or OP == "major":
sb.append("0")
sb.append(line[m.end(3):])
pkgbuf.append("".join(sb))
print("package.json: {} => {}".format(line, "".join(sb)))
else:
pkgbuf.append(line)
with open("package.json", "w") as f:
f.write("".join(pkgbuf))
serbuf = []
with open("lib/server.js") as f:
for line in f:
m = SERVER.search(line)
sb = []
if m:
sb.append(line[:m.start(1)])
if OP == "major":
sb.append(str(int(line[m.start(1):m.end(1)])+1))
else:
sb.append(line[m.start(1):m.end(1)])
sb.append(line[m.end(1):m.start(2)])
if OP == "minor":
sb.append(str(int(line[m.start(2):m.end(2)])+1))
elif OP == "major":
sb.append("0")
else:
sb.append(line[m.start(2):m.end(2)])
sb.append(line[m.end(2):m.start(3)])
if OP == "patch":
sb.append(str(int(line[m.start(3):m.end(3)])+1))
elif OP == "minor" or OP == "major":
sb.append("0")
sb.append(line[m.end(3):])
serbuf.append("".join(sb))
print("server.js: {} => {}".format(line, "".join(sb)))
else:
serbuf.append(line)
with open("lib/server.js", "w") as f:
f.write("".join(serbuf))