From fdb6e326a43486f18f36e8c77161053dcac86603 Mon Sep 17 00:00:00 2001 From: psrok1 Date: Wed, 7 Aug 2024 16:11:56 +0200 Subject: [PATCH] Fix: 'mwdb-core configure web' command after transition to Vite --- mwdb/cli/web.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/mwdb/cli/web.py b/mwdb/cli/web.py index 63c92af80..57cbb4e57 100644 --- a/mwdb/cli/web.py +++ b/mwdb/cli/web.py @@ -1,3 +1,4 @@ +import pathlib import os import shutil import subprocess @@ -20,27 +21,25 @@ def discover_web_plugins(): def npm_build_web(target_dir): - config_paths = [ - "./package.json", - "./package-lock.json", - "./config-overrides.js", - "./public", - "./src", + paths_to_ignore = [ + "node_modules", + ".gitignore" ] with tempfile.TemporaryDirectory() as context_dirname: # Copy files to context directory logger.info("Creating build context...") - for path in config_paths: - src = os.path.join(web_package_dir, path) - dst = os.path.join(context_dirname, path) - if os.path.isfile(src): - shutil.copy(src, dst) - elif os.path.isdir(src): - shutil.copytree(src, dst) + dst = pathlib.Path(context_dirname) + for path in pathlib.Path(web_package_dir).iterdir(): + if path.name in paths_to_ignore: + continue + if path.is_file(): + shutil.copy(path, dst / path.name) + elif path.is_dir(): + shutil.copytree(path, dst / path.name) else: raise RuntimeError( - "Critical error: expected file {} doesn't exist".format(path) + "Critical error: file {} is not a regular file nor directory".format(path) ) # Run npm install for web core @@ -66,5 +65,5 @@ def npm_build_web(target_dir): shutil.rmtree(target_dir) logger.info("Collecting artifacts to %s", target_dir) - shutil.move(os.path.join(context_dirname, "build"), target_dir) + shutil.move(os.path.join(context_dirname, "dist"), target_dir) logger.info("Web application built successfully!")