Add dependency and check npm is exist

Signed-off-by: YoungSoo Shin <shinys000114@gmail.com>
This commit is contained in:
2025-08-27 10:51:24 +09:00
parent b419b4e514
commit db1733aa07

View File

@@ -2,6 +2,12 @@
set(WEB_APP_SOURCE_DIR ${CMAKE_SOURCE_DIR}/page) set(WEB_APP_SOURCE_DIR ${CMAKE_SOURCE_DIR}/page)
set(GZ_OUTPUT_FILE ${WEB_APP_SOURCE_DIR}/dist/index.html.gz) set(GZ_OUTPUT_FILE ${WEB_APP_SOURCE_DIR}/dist/index.html.gz)
# Check npm is available
find_program(NPM_EXECUTABLE npm)
if(NOT NPM_EXECUTABLE)
message(FATAL_ERROR "npm not found! Please install Node.js and npm.")
endif()
# Register the component. Now, CMake knows how GZ_OUTPUT_FILE is generated # Register the component. Now, CMake knows how GZ_OUTPUT_FILE is generated
# and can correctly handle the dependency for embedding. # and can correctly handle the dependency for embedding.
idf_component_register(SRC_DIRS "app" "nconfig" "wifi" "indicator" "system" "service" "ina226" idf_component_register(SRC_DIRS "app" "nconfig" "wifi" "indicator" "system" "service" "ina226"
@@ -16,9 +22,23 @@ add_custom_command(
COMMAND npm install COMMAND npm install
COMMAND npm run build COMMAND npm run build
WORKING_DIRECTORY ${WEB_APP_SOURCE_DIR} WORKING_DIRECTORY ${WEB_APP_SOURCE_DIR}
# Re-run the build if package.json or vite.config.js changes # Re-run the build if any of these files change
DEPENDS ${WEB_APP_SOURCE_DIR}/index.html ${WEB_APP_SOURCE_DIR}/src/main.js ${WEB_APP_SOURCE_DIR}/src/style.css DEPENDS
COMMENT "Building Node.js project to produce ${GZ_OUTPUT_FILE}" ${WEB_APP_SOURCE_DIR}/package.json
${WEB_APP_SOURCE_DIR}/vite.config.js
${WEB_APP_SOURCE_DIR}/index.html
${WEB_APP_SOURCE_DIR}/src/api.js
${WEB_APP_SOURCE_DIR}/src/chart.js
${WEB_APP_SOURCE_DIR}/src/dom.js
${WEB_APP_SOURCE_DIR}/src/events.js
${WEB_APP_SOURCE_DIR}/src/main.js
${WEB_APP_SOURCE_DIR}/src/style.css
${WEB_APP_SOURCE_DIR}/src/terminal.js
${WEB_APP_SOURCE_DIR}/src/ui.js
${WEB_APP_SOURCE_DIR}/src/utils.js
${WEB_APP_SOURCE_DIR}/src/websocket.js
COMMENT "Building Node.js project (npm install && npm run build)"
VERBATIM VERBATIM
) )