]> khamidou — GitHub mirrors - electron.git/commitdiff
Add tool to help bump version.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 7 Nov 2013 04:52:26 +0000 (12:52 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 7 Nov 2013 04:52:26 +0000 (12:52 +0800)
package.json
script/bump-version.py [new file with mode: 0644]

index f1dac6e99d8c85b1083a3c8a54162a2c2dc2b445..0084f6195d3bffb5290a6269aec1b970182a4b8d 100644 (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",
diff --git a/script/bump-version.py b/script/bump-version.py
new file mode 100644 (file)
index 0000000..7ba2f61
--- /dev/null
@@ -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())