2023-11-14 00:19:33 +00:00
|
|
|
# noqa: INP001
|
2023-11-21 13:40:17 +00:00
|
|
|
import os
|
2023-11-21 13:35:54 +00:00
|
|
|
import shutil
|
2023-11-14 00:19:33 +00:00
|
|
|
import subprocess
|
2023-11-21 13:52:56 +00:00
|
|
|
from sys import stderr
|
2023-11-14 00:19:33 +00:00
|
|
|
|
|
|
|
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
|
2023-11-21 14:06:21 +00:00
|
|
|
stderr.write(">>> Building Cista frontend\n")
|
2023-11-21 13:35:54 +00:00
|
|
|
npm = shutil.which("npm")
|
|
|
|
if npm is None:
|
|
|
|
raise RuntimeError(
|
|
|
|
"NodeJS `npm` is required for building Cista but it was not found"
|
|
|
|
)
|
2023-11-21 13:40:17 +00:00
|
|
|
# npm --prefix doesn't work on Windows, so we chdir instead
|
|
|
|
os.chdir("frontend")
|
|
|
|
try:
|
2023-11-21 14:06:21 +00:00
|
|
|
stderr.write("### npm install\n")
|
2023-11-21 13:40:17 +00:00
|
|
|
subprocess.run([npm, "install"], check=True) # noqa: S603
|
2023-11-21 14:06:21 +00:00
|
|
|
stderr.write("\n### npm run build\n")
|
2023-11-21 13:40:17 +00:00
|
|
|
subprocess.run([npm, "run", "build"], check=True) # noqa: S603
|
|
|
|
finally:
|
|
|
|
os.chdir("..")
|