2023-11-14 00:19:33 +00:00
|
|
|
# noqa: INP001
|
2023-11-21 13:35:54 +00:00
|
|
|
import shutil
|
2023-11-14 00:19:33 +00:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
|
|
|
|
|
|
|
|
|
|
class CustomBuildHook(BuildHookInterface):
|
|
|
|
def initialize(self, version, build_data):
|
|
|
|
super().initialize(version, build_data)
|
2023-11-21 13:35:54 +00:00
|
|
|
# A hack to stop building twice on run
|
|
|
|
if not build_data.get("force_include"):
|
|
|
|
return
|
|
|
|
print("Building Cista frontend...", version, build_data)
|
|
|
|
npm = shutil.which("npm")
|
|
|
|
if npm is None:
|
|
|
|
raise RuntimeError(
|
|
|
|
"NodeJS `npm` is required for building Cista but it was not found"
|
|
|
|
)
|
|
|
|
frontend = "frontend"
|
|
|
|
subprocess.run([npm, "install", "--prefix", frontend], check=True) # noqa: S603
|
|
|
|
subprocess.run([npm, "run", "build", "--prefix", frontend], check=True) # noqa: S603
|