INNER CODE UNIT · Python
update_by_pattern
jpush/jpush-react-native · .claude/skills/update-sdk/scripts/plugin_updater.py:65
def update_by_pattern(file_path: str, pattern: str, new_version: str) -> bool:
"""Replace version in file using a pattern with {VERSION} placeholder."""
path = Path(file_path)
if not path.exists():
print(f" WARNING: File not found: {file_path}")
return False
content = path.read_text(encoding="utf-8")
regex = re.escape(pattern).replace(r"\{VERSION\}", r"([\d.]+(?:-\w+)?)")
replacement = pattern.replace("{VERSION}", new_version)
match = re.search(regex, content)
if not match:
print(f" WARNING: Pattern not found in {file_path}")
print(f" Pattern: {pattern}")
return False
old_version = match.group(1)