# _*_ coding: utf-8 _*_ # @Time : 2025/7/24 17:15 # @Author : Hank # @Version:V 0.1 # @File : mini_interface.py # @desc : import os import re import time import subprocess import sys import platform # ----------------------- 执行说明 ------------------------- # 单个更新 # python update.py 1 wx1234567890abcdef # 批量更新,修改update_list # python update.py 2 # ----------------------- 执行说明 ------------------------- update_list = [] # 更新列表 update_list_hank = [ "wxa7a33088566e1292","wxdabfa5e02785fe9b","wxa13166979d7011c4","wx8a8aae7f462df482","wx1344c35820ac688e","wx8bd40e8ce9deb2b6", "wx9e90adce31181f7f","wx37dab28af5492d98","wx04b705205757217b","wxc4e78d0425e83571","wx9d93825db1c7dcbe","wx3fe2e6c200ec7133", "wx3800bb2ed4a326c5","wx60db1bff60cd771c","wxd40b677f35319eea","wx5a9dda0604c2ea67","wxdecb83db79aa5bc0","wx616a7e327bd9574a", "wxdcf60b8e89ff6fa0","wx54c216ec4ad011fd" ] # update_list.extend(update_list_hank) update_list_alex = [ "wxa721f4474e3d548a","wxc5e6b24889027032","wxef68681d5044ca05","wx706acdc696d025ad","wx8288d587b717897e","wx54a8d0e7b33c48c8", "wx0138dee6d680c705","wx4420e2d55b0ede27","wx1eb74c589da1731f","wxf2dd3343ad28ec14","wx6dacc3c0d8cb4b9f","wx39a47cc77988c431", "wx91a45e115ece8a3e","wx6b11ce533c3aca92","wx5d607cf4fa663c72","wxbece4f28b6b71271","wxf91f09a57b8aa3ae","wxdd1bde4de9f6a6a0", "wxbf40c735c0d263a5","wx3f464072571c1fd3","wx092045bdfe26a5ee","wx6c4bb5ef1e6c1e70","wxa9fb660c0d4bd708","wxcdfd21a368ed2ced", "wxf0248772f67666ee","wx7328fabfb0a5fb8d","wxdf7e08f21084c8e2", ] # update_list.extend(update_list_alex) # print(update_list) # 配置文件路径 config_file = 'config/config.js' project_file = 'project.config.json' project_path = os.getcwd() # 根据平台设置 CLI 路径 system = platform.system() if system == "Windows": cli_tool_path = r"C:\Users\hank\software\微信web开发者工具\cli.bat" # windows 项目路径 project_path = r"C:\Users\hank\Git\mini_read_space_front" elif system == "Darwin": # macOS cli_tool_path = "/Applications/wechatwebdevtools.app/Contents/MacOS/cli" else: print(f"[ERROR] 不支持的操作系统: {system}") sys.exit(1) def replace_in_file(file_path, pattern, replacement): with open(file_path, 'r', encoding='utf-8') as file: content = file.read() new_content, count = re.subn(pattern, replacement, content) if count > 0: with open(file_path, 'w', encoding='utf-8') as file: file.write(new_content) else: print(f"[WARN] No matches found in {file_path} for pattern: {pattern}") def upload_project(appid, version, description): print(f"[INFO] 更新 appid: {appid}") replace_in_file(config_file, r'const current_appid = "[^"]*"', f'const current_appid = "{appid}"') replace_in_file(project_file, r'"appid":\s*"[^"]*"', f'"appid": "{appid}"') # 准备上传环境,清除 NODE_OPTIONS(兼容微信开发者工具 CLI) env = os.environ.copy() env.pop("NODE_OPTIONS", None) # 删除 NODE_OPTIONS,如果存在 try: subprocess.run([ cli_tool_path, "upload", "--project", project_path, "-v", version, "-d", description ], check=True, env=env) print(f"[SUCCESS] 上传完成: {appid}\n") except subprocess.CalledProcessError as e: print(f"[ERROR] 上传失败: {appid}\n{e}") def main(version,description): if len(sys.argv) < 2: print("用法: python update.py <模式> [appid] <开发者账号>") print("模式 1: 单个更新,需提供 appid") print("模式 2: 批量更新,使用 update_list") print("开发者账号 1:hank") print("开发者账号 2:alex") return mode = sys.argv[1] if mode == "1": if len(sys.argv) < 3: print("请提供 appid,例如: python update.py 1 wx1234567890abcdef") return appid = sys.argv[2] upload_project(appid, version, description) elif mode == "2": account = sys.argv[2] if account == "1": update_list = update_list_hank elif account == "2": update_list = update_list_alex else: print("无效开发者账号,只能为 1 或 2") return for appid in update_list: print(f"{appid} 开始更新") upload_project(appid, version, description) time.sleep(3) print(f"{appid} 结束更新\n") else: print("无效模式,只能为 1 或 2") return if __name__ == "__main__": version = "2.1.2" description = "v2.1.2 优化一些问题" main(version,description)