From 64d606f0a403695f1d006e4b1ff870e5c8d89790 Mon Sep 17 00:00:00 2001 From: th3r00t Date: Sat, 11 Mar 2023 01:00:04 -0500 Subject: [PATCH] Handle javascript dependencies. --- src/frontend/lib/objects.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/frontend/lib/objects.py diff --git a/src/frontend/lib/objects.py b/src/frontend/lib/objects.py new file mode 100644 index 0000000..c6e26b5 --- /dev/null +++ b/src/frontend/lib/objects.py @@ -0,0 +1,23 @@ +"""pyShelf's Frontend Objects.""" +from sys import exit +from shutil import which +from subprocess import run +from pathlib import Path +from ...backend.lib.config import Config + + +class JSInterface(): + """A class to interface with the JavaScript side of pyShelf.""" + + def __init__(self, config: Config): + """Initialize the JSInterface object.""" + self.package_json: Path = Path(config.root, "src/frontend/package.json") + self.config: Config = config + + def install(self): + """Install the JavaScript dependencies.""" + if which("npm"): + run(["npm", "install"], cwd=self.package_json.parent) + else: + self.config.logger.error("npm is not installed.") + exit(1)