android-release.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/usr/bin/env python3
  2. import os
  3. import shutil
  4. import subprocess
  5. import string
  6. import json
  7. import argparse
  8. import sys
  9. # 主要功能:
  10. # 1、修改VersionConfig.js, AllSDKConfig.js
  11. # VersionConfig.js: 修改APP_VERSION, RES_VERSION, CONF_VERSION, OPEN_DEBUG, RELEASE_SERVER_NAME
  12. # AllSDKConfig.js: 仅保留空999渠道配置
  13. # 2、根据是否调试,确定是否删除debug相关目录
  14. # 3、删除非android平台的代码
  15. # ex: python3 android-release.py --debug --appver 3.13.1 --resver 313001001 --confver 50 --hxCode 0 --servername TEST_FORMAL_SERVER
  16. # ex: python3 android-release.py --appver 3.13.1 --resver 313001 --confver 50 --hxCode 0 --servername FORMAL_SERVER
  17. parser = argparse.ArgumentParser()
  18. parser.add_argument('--debug', dest='debug', action='store_true', help = 'open debug')
  19. parser.add_argument('--appver', dest='appver', default=None, help = 'application version')
  20. parser.add_argument('--resver', dest='resver', default=None, help = 'resources version')
  21. parser.add_argument('--confver', dest='confver', default=None, help = 'config version')
  22. parser.add_argument('--hxCode', dest='hxCode', default=None, help = 'hx code')
  23. parser.add_argument('--servername', dest='servername', default=None, help = 'release server name')
  24. args = parser.parse_args()
  25. # 判断GIT_ROOT是否存在
  26. GIT_ROOT = os.environ.get('GIT_ROOT')
  27. if not GIT_ROOT:
  28. print('环境变量中未找到 GIT_ROOT')
  29. exit()
  30. # 目录
  31. project_root = os.path.join(GIT_ROOT, 'mj-creator')
  32. # 处理环境
  33. def handleEvn ():
  34. # 封包目录
  35. if not os.path.exists(project_root):
  36. print('封包目录不存在')
  37. exit()
  38. def handleVersionConfig():
  39. debug = 'false'
  40. if args.debug:
  41. debug = 'true'
  42. # 参数
  43. values = {
  44. 'appVersion' : args.appver,
  45. 'resVersion' : args.resver,
  46. 'confVersion' : args.confver,
  47. 'hxCode' : args.hxCode,
  48. 'openDebug' : debug,
  49. 'openSingle' : 'true',
  50. 'openPay' : 'true',
  51. 'iosChannel' : '999',
  52. 'androidChannel' : '999',
  53. 'releaseServerName' : args.servername,
  54. }
  55. # 模版
  56. t = string.Template("""
  57. module.exports = {
  58. init (ns) {
  59. ns.APP_VERSION = '${appVersion}';
  60. ns.RES_VERSION = ${resVersion};
  61. ns.CONF_VERSION = ${confVersion};
  62. ns.HX_CODE = ${hxCode};
  63. ns.OPEN_DEBUG = ${openDebug};
  64. ns.OPEN_SINGLE = ${openSingle};
  65. ns.OPEN_PAY = ${openPay};
  66. ns.IOS_CHANNEL = ${iosChannel};
  67. ns.ANDROID_CHANNEL = ${androidChannel};
  68. ns.RELEASE_SERVER_NAME = '${releaseServerName}';
  69. }
  70. };
  71. """)
  72. # 写文件
  73. path = os.path.join(project_root, 'assets/script/VersionConfig.js')
  74. with open(path, 'wt') as f:
  75. f.write(t.substitute(values))
  76. def handleSDKConfig():
  77. s = """module.exports = {
  78. ch999: {
  79. 'channel': '999'
  80. }
  81. };"""
  82. # 写文件
  83. path = os.path.join(project_root, 'assets/script/AllSDKConfig.js')
  84. with open(path, 'wt') as f:
  85. f.write(s)
  86. def delModules():
  87. isdebug = args.debug
  88. if not isdebug:
  89. # 删除debug
  90. src_dir = os.path.join(project_root, 'assets/script/debug')
  91. src_meta = os.path.join(project_root, 'assets/script/debug.meta')
  92. if os.path.exists(src_dir):
  93. shutil.rmtree(src_dir)
  94. if os.path.exists(src_meta):
  95. os.remove(src_meta)
  96. res_dir = os.path.join(project_root, 'assets/resources/debug')
  97. res_meta = os.path.join(project_root, 'assets/resources/debug.meta')
  98. if os.path.exists(res_dir):
  99. shutil.rmtree(res_dir)
  100. if os.path.exists(res_meta):
  101. os.remove(res_meta)
  102. # 删除非android的模块
  103. platform_root = os.path.join(project_root, 'assets/script/platform')
  104. for dirName in os.listdir(platform_root):
  105. path = os.path.join(platform_root, dirName)
  106. if os.path.isdir(path):
  107. if dirName != 'android':
  108. shutil.rmtree(path)
  109. os.remove(path + '.meta')
  110. def main():
  111. handleEvn()
  112. # 根据配置表生成version op sdk
  113. handleVersionConfig()
  114. handleSDKConfig()
  115. # 删除多余文件
  116. delModules()
  117. if __name__ == "__main__":
  118. main()