Add tool to help bump version.

This commit is contained in:
Cheng Zhao 2013-11-07 12:52:26 +08:00
parent d1dc041aaf
commit e075a8b49e
2 changed files with 47 additions and 2 deletions

View file

@ -1,6 +1,6 @@
{
"name" : "atom-shell",
"version" : "0.6.3",
"name": "atom-shell",
"version": "0.6.8",
"devDependencies": {
"coffee-script": "~1.6.3",

45
script/bump-version.py Normal file
View file

@ -0,0 +1,45 @@
#!/usr/bin/env python
import os
import re
import subprocess
import sys
def main():
if len(sys.argv) != 2:
print 'Usage: bump-version.py version'
return 1
version = sys.argv[1]
if version[0] == 'v':
version = version[1:]
versions = parse_version(version)
os.chdir(os.path.dirname(os.path.dirname(__file__)))
update_package_json(version)
def parse_version(version):
vs = version.split('.')
if len(vs) > 4:
return vs[0:4]
else:
return vs + [0] * (4 - len(vs))
def update_package_json(version):
pattern = re.compile(' *"version" *: *"[0-9.]+"')
with open('package.json', 'r') as f:
lines = f.readlines()
for i in range(0, len(lines)):
if pattern.match(lines[i]):
lines[i] = ' "version": "{0}",\n'.format(version)
with open('package.json', 'w') as f:
f.write(''.join(lines))
return
if __name__ == '__main__':
sys.exit(main())