nomadweb/redmini/scripts/static_scan.py
eric bf7167c185 Rebuild redmini as full offline nomadro product mirror for XHS.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-27 13:04:35 -05:00

36 lines
1002 B
Python

#!/usr/bin/env python3
"""Fail if release/ contains networking APIs (XHS miniTool cannot network)."""
from __future__ import annotations
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
RELEASE = ROOT / "release"
# Ban callable network surfaces only — plain URL text in copy is OK.
BANNED = re.compile(
r"\b(fetch\s*\(|XMLHttpRequest|WebSocket\s*\(|navigator\.sendBeacon|"
r"axios\.|\$\.ajax|\$\.get\s*\(|\$\.post\s*\()",
re.I,
)
def main() -> int:
bad: list[str] = []
for p in RELEASE.rglob("*"):
if not p.is_file() or p.suffix.lower() not in {".js", ".html", ".css"}:
continue
text = p.read_text(encoding="utf-8", errors="replace")
if BANNED.search(text):
bad.append(str(p.relative_to(ROOT)))
if bad:
print("NETWORK_FORBIDDEN:", ", ".join(bad), file=sys.stderr)
return 1
print("offline_ok")
return 0
if __name__ == "__main__":
raise SystemExit(main())