fix: cocoon FE and add to both json

This commit is contained in:
Richard Macias
2026-02-14 10:41:28 -06:00
parent d370ce11dc
commit dcef4f7d75
9 changed files with 239 additions and 177 deletions

View File

@@ -177,6 +177,7 @@ def generate_app_entry(
variant: str,
include_prereleases: bool = False,
verify_latest_tag: bool = False,
allow_id_change: bool = False,
app_name_override: str | None = None,
url_override: str | None = None,
) -> dict:
@@ -197,6 +198,7 @@ def generate_app_entry(
"preferredApkIndex": 0,
"additionalSettings": json.dumps(settings, separators=(",", ":")),
"categories": categories,
"allowIdChange": allow_id_change,
"overrideSource": source,
}
@@ -277,6 +279,10 @@ def main() -> int:
verify_latest_tag = prompt_yes_no("Verify latest tag?", False)
print(f" Verify latest tag: {'Yes' if verify_latest_tag else 'No'}")
# Allow ID change
allow_id_change = prompt_yes_no("Allow ID change?", False)
print(f" Allow ID change: {'Yes' if allow_id_change else 'No'}")
# Optional overrides
print("")
app_name_override = input(
@@ -298,6 +304,7 @@ def main() -> int:
variant=variant,
include_prereleases=include_prereleases,
verify_latest_tag=verify_latest_tag,
allow_id_change=allow_id_change,
app_name_override=app_name_override or None,
url_override=url_override or None,
)

85
scripts/normalize-json.py Normal file
View File

@@ -0,0 +1,85 @@
#!/usr/bin/env python3
import json
import sys
from pathlib import Path
from constants import SRC_FILE
# Canonical key order - matches the output of generate_app_entry() in add-app.py
KEY_ORDER = [
"id",
"url",
"author",
"name",
"preferredApkIndex",
"additionalSettings",
"categories",
"allowIdChange",
"overrideSource",
"meta",
]
# Fields to backfill with defaults when missing
DEFAULTS: dict[str, object] = {
"allowIdChange": False,
}
def normalize_app(app: dict) -> dict:
for key, default in DEFAULTS.items():
if key not in app:
app[key] = default
ordered: dict[str, object] = {}
for key in KEY_ORDER:
if key in app:
ordered[key] = app[key]
# Preserve any unexpected keys at the end (safety net)
for key in app:
if key not in ordered:
ordered[key] = app[key]
return ordered
def normalize(input_path: str) -> int:
path = Path(input_path)
if not path.exists():
print(f"Error: {path} not found.")
return 1
with open(path, "r", encoding="utf-8") as f:
data = json.load(f)
apps = data.get("apps", [])
if not apps:
print("No apps found in file.")
return 1
changes = 0
for i, app in enumerate(apps):
normalized = normalize_app(app)
# Check if anything changed (key order or new defaults)
if list(app.keys()) != list(normalized.keys()) or app != normalized:
changes += 1
apps[i] = normalized
with open(path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2, ensure_ascii=False)
f.write("\n")
if changes:
print(f"Normalized {changes} app(s) in {path}")
else:
print(f"All {len(apps)} apps already normalized")
return 0
if __name__ == "__main__":
input_file = sys.argv[1] if len(sys.argv) > 1 else SRC_FILE
sys.exit(normalize(input_file))