Skip to content

Commit

Permalink
Try custom script
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmervdl committed Sep 3, 2024
1 parent 50c4a3b commit 42a574e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling", "hatch-requirements-txt", "hatch-build-scripts"]
requires = ["hatchling", "hatch-requirements-txt"]
build-backend = "hatchling.build"

[project]
Expand Down Expand Up @@ -53,10 +53,10 @@ include = ["/opuscleaner"]
[tool.hatch.build.force-include]
"frontend/dist" = "/opuscleaner/frontend"

[[tool.hatch.build.targets.sdist.hooks.build-scripts.scripts]]
work_dir = "frontend"
commands = ["npm clean-install && npm run build"]
artifacts = ["/frontend/dist"]
[tool.hatch.build.hooks.custom]
path = "utils/frontend_build_hook.py"
working_dir = "frontend"
artifacts = ["frontend/dist"]

[tool.hatch.metadata.hooks.requirements_txt]
files = ["requirements.txt"]
Expand Down
18 changes: 18 additions & 0 deletions utils/frontend_build_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import subprocess
import os
from typing import Any

from hatchling.builders.hooks.plugin.interface import BuildHookInterface


class NpmBuildHook(BuildHookInterface):
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
if all(os.path.exists(artifact) for artifact in self.config.get("artifacts", [])):
return
subprocess.check_output(
"npm install && npm run build",
shell=True,
cwd=self.config.get("working_dir", "."))

def clean(self, versions: list[str]) -> None:
subprocess.check_output("npm run clean", shell=True)

0 comments on commit 42a574e

Please sign in to comment.