25 lines
865 B
Python
25 lines
865 B
Python
# hatch_build.py
|
|
import pathlib
|
|
import shutil
|
|
import subprocess
|
|
|
|
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
|
|
|
|
class MarkdownBuildHook(BuildHookInterface):
|
|
def initialize(self, version, build_data):
|
|
# 1. Compile the UI exactly once per build
|
|
ui_dir = pathlib.Path(__file__).parent / "markdown_view_plugin" / "ui"
|
|
dist_dir = ui_dir / "dist"
|
|
|
|
# Clean any existing dist directory to ensure fresh build
|
|
if dist_dir.exists():
|
|
shutil.rmtree(dist_dir)
|
|
|
|
# Install dependencies and build the UI
|
|
subprocess.run(["pnpm", "install", "--frozen-lockfile"], cwd=ui_dir, check=True)
|
|
subprocess.run(["pnpm", "run", "build"], cwd=ui_dir, check=True)
|
|
|
|
# 2. Force-include the compiled assets in the wheel
|
|
build_data["force_include"][str(dist_dir)] = "ui/dist"
|