From d8d9c7d616e06e0bc02ec564942084bb691ebd91 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Fri, 5 Jul 2024 23:14:04 +0200 Subject: [PATCH] Do npm install as part of configuration step, use npm.cmd on Windows --- tools/Python/mcdisplay/webgl/CMakeLists.txt | 11 +++++++++-- tools/Python/mcdisplay/webgl/mcdisplay.py | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/Python/mcdisplay/webgl/CMakeLists.txt b/tools/Python/mcdisplay/webgl/CMakeLists.txt index 4ce7427801..45cfcd6c31 100644 --- a/tools/Python/mcdisplay/webgl/CMakeLists.txt +++ b/tools/Python/mcdisplay/webgl/CMakeLists.txt @@ -51,7 +51,7 @@ set(CPACK_NSIS_DISPLAY_NAME "${NSIS_NAME}") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${NSIS_NAME}") # Debian -set(CPACK_DEBIAN_PACKAGE_DEPENDS "${FLAVOR}-${MCCODE_VERSION}, python3, python3-ply, python3-numpy") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "${FLAVOR}-${MCCODE_VERSION}, python3, python3-ply, python3-numpy nodejs") # RPM if (RPMPROFILE) @@ -75,6 +75,13 @@ set(WORK "${PROJECT_BINARY_DIR}/work") # Configure fallback script configure_file("${CMAKE_CURRENT_SOURCE_DIR}/mcdisplay.in" "${WORK}/${P}display" @ONLY) +# Put package.json in $WORK +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/package.json" "${WORK}/package.json" @ONLY) + +# Run npm to install project +execute_process(COMMAND "npm" "install" + WORKING_DIRECTORY "${WORK}") + # Dist install( DIRECTORY "${PROJECT_SOURCE_DIR}/dist" @@ -84,7 +91,7 @@ install( # Node modules install( - DIRECTORY "${PROJECT_SOURCE_DIR}/node_modules" + DIRECTORY "${WORK}/node_modules" DESTINATION "${DEST_TOOLDIR}/${TOOLS_NAME}" ) diff --git a/tools/Python/mcdisplay/webgl/mcdisplay.py b/tools/Python/mcdisplay/webgl/mcdisplay.py index 63fd0b0fd3..5d9ffe4264 100755 --- a/tools/Python/mcdisplay/webgl/mcdisplay.py +++ b/tools/Python/mcdisplay/webgl/mcdisplay.py @@ -144,8 +144,13 @@ def copy(a, b): # Function to run npm commands and capture port def run_npm_and_capture_port(port_container): + if not os.name == 'nt': + npmexe = "npm" + else: + npmexe = "npm.cmd" + try: - proc = subprocess.Popen(["npm","run","dev"], cwd=str(destdist), stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + proc = subprocess.Popen([npmexe,"run","dev"], cwd=str(destdist), stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) for line in proc.stdout: print(line) if 'Local:' in line: