Mount /vip with nomadvip+payjsapi, add @nomadro/pay|pb|sdk, apps/api, /admin shell, and backup/rollback scripts under git.nomadro.cn workflow. Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
from pathlib import Path
|
|
import re
|
|
|
|
ROOT = Path("apps/nomadvip")
|
|
IMPORT = 'import { vipPath } from "@vip/app/lib/vipPath";\n'
|
|
n = 0
|
|
for f in list(ROOT.rglob("*.tsx")) + list(ROOT.rglob("*.ts")):
|
|
if f.name in {"vipPath.ts", "vip.mock.ts", "resolveVipDataFile.ts"}:
|
|
continue
|
|
if any(p in f.parts for p in ("node_modules", ".next")):
|
|
continue
|
|
t = f.read_text(encoding="utf-8")
|
|
if "/cloudphone" not in t and "/ebook" not in t and "/topic/" not in t:
|
|
continue
|
|
# only files with bare href paths
|
|
if not re.search(r'href=\{?[`"]/(cloudphone|ebook|topic/)', t):
|
|
continue
|
|
orig = t
|
|
if "@vip/app/lib/vipPath" not in t:
|
|
lines = t.splitlines(True)
|
|
idx = 0
|
|
for i, line in enumerate(lines):
|
|
if line.startswith("import ") or "use client" in line:
|
|
idx = i + 1
|
|
lines.insert(idx, IMPORT)
|
|
t = "".join(lines)
|
|
t = re.sub(r'href=\{`/(cloudphone[^`]*)`\}', r'href={vipPath(`/\1`)}', t)
|
|
t = re.sub(r'href=\{`/(topic[^`]*)`\}', r'href={vipPath(`/\1`)}', t)
|
|
t = re.sub(r'href="(/(?:cloudphone|ebook|topic|paid)[^"]*)"', r'href={vipPath("\1")}', t)
|
|
if t != orig:
|
|
f.write_text(t, encoding="utf-8")
|
|
print(f.as_posix())
|
|
n += 1
|
|
print("patched", n)
|