From 85693e99d04740eec8b5eae14f9477ce20e6bb47 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Tue, 21 Nov 2023 13:35:54 +0000 Subject: [PATCH] Fix build --- scripts/build-frontend.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/build-frontend.py b/scripts/build-frontend.py index 10c1756..4bd0d43 100644 --- a/scripts/build-frontend.py +++ b/scripts/build-frontend.py @@ -1,4 +1,5 @@ # noqa: INP001 +import shutil import subprocess from hatchling.builders.hooks.plugin.interface import BuildHookInterface @@ -7,6 +8,15 @@ from hatchling.builders.hooks.plugin.interface import BuildHookInterface class CustomBuildHook(BuildHookInterface): def initialize(self, version, build_data): super().initialize(version, build_data) - print("Building Cista frontend...") - subprocess.run("npm install --prefix frontend".split(" "), check=True) # noqa: S603 - subprocess.run("npm run build --prefix frontend".split(" "), check=True) # noqa: S603 + # 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