6b642d7674
* refactor: bundled webui static files into wheel and replace astrbot cli log with English - Translated and standardized log messages in cmd_conf.py for better clarity. - Updated initialization logic in cmd_init.py to provide clearer user prompts and error handling. - Improved plugin management commands in cmd_plug.py with consistent language and error messages. - Enhanced run command in cmd_run.py with clearer status messages and error handling. - Updated utility functions in basic.py and plugin.py to improve readability and maintainability. - Added version comparison logic in version_comparator.py with clearer comments. - Enhanced logging configuration in log.py to suppress noisy loggers. - Updated the updater logic in updator.py to provide clearer error messages for users. - Improved IO utility functions in io.py to handle dashboard versioning more effectively. - Enhanced dashboard server logic in server.py to prioritize bundled assets and improve user feedback. - Updated pyproject.toml to include bundled dashboard assets and custom build hooks. - Added a custom build script (hatch_build.py) to automate dashboard builds during package creation. * refactor: improve exception messages and formatting in CLI command validation * perf: change npm install to npm ci for consistent dependency installation * fix
64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
"""
|
||
Custom Hatchling build hook.
|
||
|
||
During `hatch build` (or `pip wheel`), this hook:
|
||
1. Runs `npm run build` inside the `dashboard/` directory.
|
||
2. Copies the resulting `dashboard/dist/` tree into
|
||
`astrbot/dashboard/dist/` so the static assets are shipped
|
||
inside the Python wheel.
|
||
"""
|
||
|
||
import shutil
|
||
import subprocess
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
||
|
||
|
||
class CustomBuildHook(BuildHookInterface):
|
||
PLUGIN_NAME = "custom"
|
||
|
||
def initialize(self, version: str, build_data: dict) -> None:
|
||
root = Path(self.root)
|
||
dashboard_src = root / "dashboard"
|
||
dist_src = dashboard_src / "dist"
|
||
dist_target = root / "astrbot" / "dashboard" / "dist"
|
||
|
||
if not dashboard_src.exists():
|
||
print(
|
||
"[hatch_build] 'dashboard/' directory not found – skipping dashboard build.",
|
||
file=sys.stderr,
|
||
)
|
||
return
|
||
|
||
# ── Install Node dependencies if node_modules is absent ─────────────
|
||
if not (dashboard_src / "node_modules").exists():
|
||
print("[hatch_build] Installing dashboard Node dependencies...")
|
||
subprocess.run(
|
||
["npm", "install"],
|
||
cwd=dashboard_src,
|
||
check=True,
|
||
)
|
||
|
||
# ── Build the Vue/Vite dashboard ──────────────────────────────────────
|
||
print("[hatch_build] Building Vue dashboard (npm run build)...")
|
||
subprocess.run(
|
||
["npm", "run", "build"],
|
||
cwd=dashboard_src,
|
||
check=True,
|
||
)
|
||
|
||
if not dist_src.exists():
|
||
print(
|
||
"[hatch_build] dashboard/dist not found after build – skipping copy.",
|
||
file=sys.stderr,
|
||
)
|
||
return
|
||
|
||
# ── Copy into the Python package tree ────────────────────────────────
|
||
if dist_target.exists():
|
||
shutil.rmtree(dist_target)
|
||
shutil.copytree(dist_src, dist_target)
|
||
print(f"[hatch_build] Dashboard dist copied → {dist_target.relative_to(root)}")
|