Collapse portal under src/, unify pnpm workspace/scripts, thin VIP topic re-exports, drop orphan vip scaffolds and one-shot scripts, ignore xhs/release, document root commands. Co-authored-by: Cursor <cursoragent@cursor.com>
93 lines
2.8 KiB
Python
93 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Build admin SPA and rsync dist to admin.nomadro.cn (frontend only)."""
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import tarfile
|
|
import time
|
|
from io import BytesIO
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
ADMIN = ROOT # SPA root (flattened)
|
|
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
|
|
|
|
|
|
def main() -> int:
|
|
print("building…", flush=True)
|
|
r = subprocess.run(
|
|
["pnpm", "build"],
|
|
cwd=ADMIN,
|
|
shell=True,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
if r.returncode != 0:
|
|
print(r.stdout)
|
|
print(r.stderr)
|
|
# fallback npm
|
|
r2 = subprocess.run(
|
|
"npm run build",
|
|
cwd=ADMIN,
|
|
shell=True,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
print(r2.stdout)
|
|
print(r2.stderr)
|
|
if r2.returncode != 0:
|
|
return r2.returncode or 1
|
|
else:
|
|
print(r.stdout[-800:] if r.stdout else "ok", flush=True)
|
|
|
|
dist = ADMIN / "dist"
|
|
if not dist.exists():
|
|
print("no dist")
|
|
return 1
|
|
|
|
buf = BytesIO()
|
|
with tarfile.open(fileobj=buf, mode="w:gz") as tar:
|
|
for p in dist.rglob("*"):
|
|
if p.is_file():
|
|
tar.add(p, arcname="admin-dist/" + p.relative_to(dist).as_posix())
|
|
buf.seek(0)
|
|
print(f"pack {buf.getbuffer().nbytes} bytes", flush=True)
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/dy-ui-admin.tar.gz", "wb") as rf:
|
|
rf.write(buf.read())
|
|
sftp.close()
|
|
|
|
cmd = r"""
|
|
set -e
|
|
cd /tmp
|
|
rm -rf dy-ui-unpack && mkdir dy-ui-unpack
|
|
tar -xzf dy-ui-admin.tar.gz -C dy-ui-unpack
|
|
sudo rsync -a --delete dy-ui-unpack/admin-dist/ /www/wwwroot/admin.nomadro.cn/
|
|
sudo chown -R www:www /www/wwwroot/admin.nomadro.cn
|
|
curl -sk -o /dev/null -w "admin %{http_code}\n" https://admin.nomadro.cn/
|
|
curl -sk -o /dev/null -w "douyin %{http_code}\n" https://admin.nomadro.cn/douyin
|
|
ls /www/wwwroot/admin.nomadro.cn/assets/ | head -8
|
|
rm -rf dy-ui-unpack dy-ui-admin.tar.gz
|
|
"""
|
|
_, stdout, _ = c.exec_command(cmd, timeout=120, get_pty=True)
|
|
while not stdout.channel.exit_status_ready():
|
|
if stdout.channel.recv_ready():
|
|
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
|
|
time.sleep(0.05)
|
|
while stdout.channel.recv_ready():
|
|
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
|
|
code = stdout.channel.recv_exit_status()
|
|
print(f"[exit {code}]", flush=True)
|
|
c.close()
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|