Updated frontend build script
This commit is contained in:
parent
2b03fa74cd
commit
21035568f9
@ -1,16 +1,26 @@
|
|||||||
# noqa: INP001
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from contextlib import contextmanager
|
||||||
from sys import stderr
|
from sys import stderr
|
||||||
|
|
||||||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def chdir(path):
|
||||||
|
original = os.getcwd()
|
||||||
|
os.chdir(path)
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
os.chdir(original)
|
||||||
|
|
||||||
|
|
||||||
class CustomBuildHook(BuildHookInterface):
|
class CustomBuildHook(BuildHookInterface):
|
||||||
def initialize(self, version, build_data):
|
def initialize(self, version, build_data):
|
||||||
super().initialize(version, build_data)
|
super().initialize(version, build_data)
|
||||||
stderr.write(">>> Building Jacloud frontend\n")
|
stderr.write(">>> Building the frontend\n")
|
||||||
npm = None
|
npm = None
|
||||||
bun = shutil.which("bun")
|
bun = shutil.which("bun")
|
||||||
if bun is None:
|
if bun is None:
|
||||||
@ -20,18 +30,18 @@ class CustomBuildHook(BuildHookInterface):
|
|||||||
"Bun or NodeJS `npm` is required for building but neither was found"
|
"Bun or NodeJS `npm` is required for building but neither was found"
|
||||||
)
|
)
|
||||||
# npm --prefix doesn't work on Windows, so we chdir instead
|
# npm --prefix doesn't work on Windows, so we chdir instead
|
||||||
os.chdir("frontend")
|
with chdir("frontend"):
|
||||||
try:
|
try:
|
||||||
if npm:
|
if npm:
|
||||||
stderr.write("### npm install\n")
|
stderr.write("### npm install\n")
|
||||||
subprocess.run([npm, "install"], check=True) # noqa: S603
|
subprocess.run([npm, "install"], check=True) # noqa: S603
|
||||||
stderr.write("\n### npm run build\n")
|
stderr.write("\n### npm run build\n")
|
||||||
subprocess.run([npm, "run", "build"], check=True) # noqa: S603
|
subprocess.run([npm, "run", "build"], check=True) # noqa: S603
|
||||||
else:
|
else:
|
||||||
assert bun
|
assert bun
|
||||||
stderr.write("### bun install\n")
|
stderr.write("### bun --bun install\n")
|
||||||
subprocess.run([bun, "install"], check=True) # noqa: S603
|
subprocess.run([bun, "--bun", "install"], check=True) # noqa: S603
|
||||||
stderr.write("\n### bun run build\n")
|
stderr.write("\n### bun --bun run build\n")
|
||||||
subprocess.run([bun, "run", "build"], check=True) # noqa: S603
|
subprocess.run([bun, "--bun", "run", "build"], check=True) # noqa: S603
|
||||||
finally:
|
except Exception:
|
||||||
os.chdir("..")
|
stderr.write("Error occurred while building frontend\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user