import os

ROOT = "D:/work/绿水青山/清道夫App/src"

for dirpath, _, filenames in os.walk(ROOT):
    for filename in filenames:
        if filename.endswith((".vue", ".ts", ".js", ".json")):
            filepath = os.path.join(dirpath, filename)
            try:
                with open(filepath, "r", encoding="utf-8") as f:
                    content = f.read()
                # 只把源码路径中的 subpackages/ 改回 subPackages/
                # 但 pages.json 里的 root 和 preloadRule 也要改回 subPackages/
                new_content = content.replace("/subpackages/", "/subPackages/")
                # 避免把 pages.json 的 "subPackages": [ 字段名改掉（上面替换不影响，因为没有斜杠）
                # 但 root 里的 subpackages/pages-common 需要改成 subPackages/pages-common
                new_content = new_content.replace("subpackages/pages-", "subPackages/pages-")
                if new_content != content:
                    with open(filepath, "w", encoding="utf-8") as f:
                        f.write(new_content)
                    print(f"Updated: {filepath}")
            except Exception as e:
                print(f"Skip {filepath}: {e}")

print("Done")
