INNER CODE UNIT · Python
get_current_version_from_ref
jpush/jpush-react-native · .claude/skills/update-sdk/scripts/plugin_updater.py:33
def get_current_version_from_ref(ref: dict) -> str | None:
"""Read the current version string from a file ref."""
path = Path(ref["path"])
if not path.exists():
return None
content = path.read_text(encoding="utf-8")
if "pattern" in ref:
regex = re.escape(ref["pattern"]).replace(r"\{VERSION\}", r"([\d.]+(?:-\w+)?)")
match = re.search(regex, content)
return match.group(1) if match else None
elif "key" in ref:
if path.suffix in (".yaml", ".yml"):
match = re.search(r"^version:\s*(.+)$", content, re.MULTILINE)
return match.group(1).strip() if match else None
elif path.suffix == ".xml":
key = ref["key"]
match = re.search(rf'{re.escape(key)}="([^"]+)"', content)