@@ -21,23 +21,75 @@ echo "Syncing version to ${NEW_VERSION} across all files..."
2121
2222# 1. library.json
2323if [[ -f library.json ]]; then
24- sed -i -E " s/\" version\" *: *\" [^\" ]+\" /\" version\" : \" ${NEW_VERSION} \" /" library.json
24+ python3 - << 'PY ' "${NEW_VERSION}"
25+ import json
26+ import sys
27+
28+ new_version = sys.argv[1]
29+ path = "library.json"
30+
31+ with open(path, "r", encoding="utf-8") as f:
32+ data = json.load(f)
33+
34+ if not isinstance(data, dict) or "version" not in data:
35+ raise SystemExit("library.json missing top-level 'version' field")
36+
37+ data["version"] = new_version
38+
39+ with open(path, "w", encoding="utf-8", newline="\n") as f:
40+ json.dump(data, f, indent=2, ensure_ascii=False)
41+ f.write("\n")
42+ PY
2543 echo " ✓ library.json"
2644else
2745 echo " ✗ library.json not found"
2846fi
2947
3048# 2. library.properties
3149if [[ -f library.properties ]]; then
32- sed -i -E " s/^version=.*/version=${NEW_VERSION} /" library.properties
50+ python3 - << 'PY ' "${NEW_VERSION}"
51+ import re
52+ import sys
53+
54+ new_version = sys.argv[1]
55+ path = "library.properties"
56+
57+ with open(path, "r", encoding="utf-8") as f:
58+ text = f.read()
59+
60+ updated, count = re.subn(r"^version=.*$", f"version={new_version}", text, flags=re.MULTILINE)
61+ if count == 0:
62+ raise SystemExit("library.properties missing 'version=' line")
63+
64+ with open(path, "w", encoding="utf-8", newline="\n") as f:
65+ f.write(updated)
66+ PY
3367 echo " ✓ library.properties"
3468else
3569 echo " ✗ library.properties not found"
3670fi
3771
3872# 3. src/HttpCommon.h
3973if [[ -f src/HttpCommon.h ]]; then
40- sed -i -E " s/#define ESP_ASYNC_WEB_CLIENT_VERSION \" [^\" ]+\" /#define ESP_ASYNC_WEB_CLIENT_VERSION \" ${NEW_VERSION} \" /" src/HttpCommon.h
74+ python3 - << 'PY ' "${NEW_VERSION}"
75+ import re
76+ import sys
77+
78+ new_version = sys.argv[1]
79+ path = "src/HttpCommon.h"
80+
81+ with open(path, "r", encoding="utf-8") as f:
82+ text = f.read()
83+
84+ pattern = r'#define ESP_ASYNC_WEB_CLIENT_VERSION "[^"]+"'
85+ replacement = f'#define ESP_ASYNC_WEB_CLIENT_VERSION "{new_version}"'
86+ updated, count = re.subn(pattern, replacement, text)
87+ if count == 0:
88+ raise SystemExit("src/HttpCommon.h missing ESP_ASYNC_WEB_CLIENT_VERSION define")
89+
90+ with open(path, "w", encoding="utf-8", newline="\n") as f:
91+ f.write(updated)
92+ PY
4193 echo " ✓ src/HttpCommon.h"
4294else
4395 echo " ✗ src/HttpCommon.h not found"
0 commit comments