generate_manifests.py: auto-increment cache version
Hunter
Friday, March 20th, 2026 at 11:02 PM
94 return "#080a0c"
95
96
97 +def _next_cache_name(app_name, manifest_path):
98 + """Determine the next cache name by incrementing the version in an existing manifest.
99 +
100 + If manifest.json doesn't exist or has no versioned cache_name, returns "{app_name}-v1".
101 + If it already has e.g. "heaven-v1", returns "heaven-v1.1".
102 + If it already has e.g. "heaven-v1.3", returns "heaven-v1.4".
103 + """
104 + if manifest_path.exists():
105 + try:
106 + with open(manifest_path, 'r', encoding='utf-8') as f:
107 + existing = json.load(f)
108 + old_cache = existing.get("cache_name", "")
109 + # Match pattern like "appname-v1" or "appname-v1.3"
110 + match = re.match(r'^(.+)-v(\d+)(?:\.(\d+))?$', old_cache)
111 + if match:
112 + prefix = match.group(1)
113 + major = int(match.group(2))
114 + minor = int(match.group(3)) if match.group(3) is not None else 0
115 + # If app was renamed, start fresh with new name
116 + if prefix != app_name:
117 + return f"{app_name}-v1"
118 + return f"{app_name}-v{major}.{minor + 1}"
119 + except (json.JSONDecodeError, KeyError):
120 + pass
121 + return f"{app_name}-v1"
122 +
123 +
124 def generate_pwa_manifests(app_name=None, base_path=None):
125 """Generate PWA manifest files based on tracks.json
126
134
135 # Derived values
136 short_name = app_name
- cache_name = app_name
137 + cache_name = _next_cache_name(app_name, SCRIPT_DIR / "manifest.json")
138 app_description = f"{app_name}"
139
140 print("Generating PWA manifests...")
141 + print(f" Cache name: {cache_name}")
142
143 # Load tracks.json
144 if not TRACKS_JSON.exists():