This commit is contained in:
eric
2026-03-28 18:10:43 -05:00
parent 513c2b7b8c
commit 8001baabf8
15 changed files with 227 additions and 489 deletions

View File

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""启动前环境分析Python 依赖、ffmpeg、Node/npm、端口提示Windows / Linux 通用)。"""
"""启动前环境分析Python 依赖、ffmpeg、Node/npm、端口提示Linux"""
from __future__ import annotations
import importlib.util
@@ -56,11 +56,11 @@ def print_env_report(
ok = False
if fp:
print(f"│ ✓ ffplay: {fp}")
elif sys.platform != "win32":
else:
print("│ ⚠ 未找到 ffplayHDMI 全屏播放需要完整 ffmpeg 套件)")
if need_npm:
npm = shutil.which("npm") or shutil.which("npm.cmd")
npm = shutil.which("npm")
if npm:
print(f"│ ✓ npm: {npm}")
else:

View File

@@ -59,18 +59,11 @@ def load_runtime_env() -> None:
def _which_npm() -> str | None:
return shutil.which("npm") or shutil.which("npm.cmd")
return shutil.which("npm")
def _npm(args: list[str], *, cwd: Path, env: dict | None = None) -> int:
full_env = {**os.environ, **(env or {})}
if sys.platform == "win32":
return subprocess.call(
"npm " + " ".join(args),
cwd=cwd,
shell=True,
env=full_env,
)
npm = _which_npm()
if not npm:
return 127
@@ -138,21 +131,17 @@ def run_dev(host: str, port: str, next_port: str) -> None:
os.chdir(ROOT)
api: subprocess.Popen | None = None
ui: subprocess.Popen | None = None
next_args = f"npm run dev -- --hostname 0.0.0.0 --port {next_port}"
try:
api = subprocess.Popen(api_cmd, cwd=ROOT)
time.sleep(0.6)
if api.poll() is not None:
print("[launch] API 进程异常退出,请检查端口是否被占用。")
sys.exit(api.returncode or 1)
if sys.platform == "win32":
ui = subprocess.Popen(next_args, cwd=CONSOLE, shell=True, env=env)
else:
ui = subprocess.Popen(
["npm", "run", "dev", "--", "--hostname", "0.0.0.0", "--port", next_port],
cwd=CONSOLE,
env=env,
)
ui = subprocess.Popen(
["npm", "run", "dev", "--", "--hostname", "0.0.0.0", "--port", next_port],
cwd=CONSOLE,
env=env,
)
print()
print(" —— 开发模式(局域网可访问)——")
print(f" 控制台界面: http://0.0.0.0:{next_port} 或用本机 IP + 端口")