Skip to content
Snippets Groups Projects
Commit 379677fe authored by Mattia Mancini's avatar Mattia Mancini
Browse files

OSB-6: Fix CMake macro and package.json

parent 09cec9a8
No related branches found
No related tags found
2 merge requests!89Monitoring maintenance Epic branch merge,!1Resolve OSB-13 "Monitoringmaintenance "
......@@ -30,7 +30,7 @@ find_package(NPM)
# function npm_install
#
function(npm_install NPM_PACKAGE_SPECIFICATION)
# Precondition check.
# Precondition check.
if(NOT NPM_EXECUTABLE)
message(FATAL_ERROR "npm_install: cannot find npm")
endif(NOT NPM_EXECUTABLE)
......@@ -38,81 +38,85 @@ function(npm_install NPM_PACKAGE_SPECIFICATION)
# Parsing arguments
set(one_value_arguments PUBLIC SOURCE DESTINATION)
## syntax is cmake_parse_arguments(prefix options one_value_arguments multi_value_arguments arguments_to_be_parsed)
cmake_parse_arguments(NPM_INSTALL "" "${one_value_arguments}" "" ${ARGN} )
# Checks if all the required arguments have been specified
if(NOT NPM_INSTALL_PUBLIC)
message(FATAL_ERROR "specify public directory.\n ex npm_install(project.json PUBLIC public_dir SOURCE source_dir DESTINATION install_dir)")
endif(NOT NPM_INSTALL_PUBLIC)
if(NOT NPM_INSTALL_SOURCE)
message(FATAL_ERROR "specify source directory.\n ex npm_install(project.json PUBLIC public_dir SOURCE source_dir DESTINATION install_dir)")
endif(NOT NPM_INSTALL_SOURCE)
# Compute the full path to the source, and the public directory, and the json spec
get_filename_component(WEBSITE_PUBLIC_DIR "${NPM_INSTALL_PUBLIC}" REALPATH)
get_filename_component(WEBSITE_SOURCE_DIR "${NPM_INSTALL_SOURCE}" REALPATH)
get_filename_component(JSON_PACKAGE_SPECIFICATION "${NPM_PACKAGE_SPECIFICATION}" REALPATH)
# Checks if the directories public and source are actually present in the disk
if(EXISTS WEBSITE_PUBLIC_DIR)
message(FATAL_ERROR "public directory \"${NPM_INSTALL_PUBLIC}\" cannot be found.")
endif(EXISTS WEBSITE_PUBLIC_DIR)
if(EXISTS WEBSITE_SOURCE_DIR)
message(FATAL_ERROR "source directory \"${NPM_INSTALL_SOURCE}\" cannot be found.")
endif(EXISTS WEBSITE_SOURCE_DIR)
get_filename_component(NPM_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" REALPATH)
add_custom_target(copy_src_public ALL SOURCES "public" "src" COMMENT "Copying src and public directory into build directory")
add_custom_target(download_npm_dependencies ALL SOURCES "node_modules" "package-lock.json" DEPENDS copy_src_public package_json COMMENT "Attempt downloading of required npm dependencies")
add_custom_target(packing_javascript_files ALL SOURCES build COMMENT "Attempt packing of javascript files")
add_custom_target(start_development_server_${PACKAGE_NAME} SOURCES "node_modules" "package-lock.json" COMMENT "Start start_development_server for ${PACKAGE_NAME}")
add_custom_command(
OUTPUT package_json
COMMAND ${CMAKE_COMMAND} -E copy_if_different
cmake_parse_arguments(NPM_INSTALL "" "${one_value_arguments}" "" ${ARGN} )
# Checks if all the required arguments have been specified
if(NOT NPM_INSTALL_PUBLIC)
message(FATAL_ERROR "specify public directory.\n ex npm_install(project.json PUBLIC public_dir SOURCE source_dir DESTINATION install_dir)")
endif(NOT NPM_INSTALL_PUBLIC)
if(NOT NPM_INSTALL_SOURCE)
message(FATAL_ERROR "specify source directory.\n ex npm_install(project.json PUBLIC public_dir SOURCE source_dir DESTINATION install_dir)")
endif(NOT NPM_INSTALL_SOURCE)
# Compute the full path to the source, and the public directory, and the json spec
get_filename_component(WEBSITE_PUBLIC_DIR "${NPM_INSTALL_PUBLIC}" REALPATH)
get_filename_component(WEBSITE_SOURCE_DIR "${NPM_INSTALL_SOURCE}" REALPATH)
get_filename_component(JSON_PACKAGE_SPECIFICATION "${NPM_PACKAGE_SPECIFICATION}" REALPATH)
# Checks if the directories public and source are actually present in the disk
if(EXISTS WEBSITE_PUBLIC_DIR)
message(FATAL_ERROR "public directory \"${NPM_INSTALL_PUBLIC}\" cannot be found.")
endif(EXISTS WEBSITE_PUBLIC_DIR)
if(EXISTS WEBSITE_SOURCE_DIR)
message(FATAL_ERROR "source directory \"${NPM_INSTALL_SOURCE}\" cannot be found.")
endif(EXISTS WEBSITE_SOURCE_DIR)
get_filename_component(NPM_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" REALPATH)
add_custom_target(copy_src_public SOURCES ${NPM_BINARY_DIR}/public ${NPM_BINARY_DIR}/src)
add_custom_target(copy_package_json SOURCES "${NPM_BINARY_DIR}/package.json")
add_custom_target(download_npm_dependencies SOURCES "${NPM_BINARY_DIR}/node_modules" "${NPM_BINARY_DIR}/package-lock.json" DEPENDS copy_src_public copy_package_json)
add_custom_target(packing_javascript_files ALL SOURCES ${NPM_BINARY_DIR}/build)
add_custom_target(start_development_server_${PACKAGE_NAME} SOURCES "${NPM_BINARY_DIR}/node_modules" "${NPM_BINARY_DIR}/package-lock.json" "${NPM_BINARY_DIR}/package.json"
COMMENT "Start start_development_server for ${PACKAGE_NAME}")
add_custom_command(
OUTPUT "${NPM_BINARY_DIR}/package.json"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${JSON_PACKAGE_SPECIFICATION} ${NPM_BINARY_DIR}/package.json
COMMENT "Copying package.json")
add_custom_command(
OUTPUT "src"
COMMAND ${CMAKE_COMMAND} -E copy_directory
DEPENDS ${JSON_PACKAGE_SPECIFICATION}
COMMENT "Copying package.json")
add_custom_command(
OUTPUT "${NPM_BINARY_DIR}/src"
COMMAND ${CMAKE_COMMAND} -E copy_directory
${WEBSITE_SOURCE_DIR} ${NPM_BINARY_DIR}/src
COMMENT "Copying javascript src directory")
add_custom_command(
OUTPUT "public"
COMMAND ${CMAKE_COMMAND} -E copy_directory
COMMENT "Copying javascript src directory")
add_custom_command(
OUTPUT "${NPM_BINARY_DIR}/public"
COMMAND ${CMAKE_COMMAND} -E copy_directory
${WEBSITE_PUBLIC_DIR} ${NPM_BINARY_DIR}/public
COMMENT "Copying public directory")
add_custom_command(
OUTPUT "node_modules" "package-lock.json"
COMMAND npm install
DEPENDS "package.json"
WORKING_DIRECTORY ${NPM_BINARY_DIR}
COMMENT "Downloading npm dependencies for ${NPM_BINARY_DIR}/package.json")
add_custom_command(
TARGET start_development_server_${PACKAGE_NAME}
COMMAND npm start
WORKING_DIRECTORY ${NPM_BINARY_DIR}
COMMENT "Starting development server")
add_custom_command(
OUTPUT "build"
COMMAND npm run build
DEPENDS copy_src_public download_npm_dependencies
COMMENT "Packing javascript files for deploy")
message(${NPM_INSTALL_DESTINATION})
install(DIRECTORY ${NPM_BINARY_DIR}/build/ DESTINATION ${CMAKE_INSTALL_PREFIX}/${NPM_INSTALL_DESTINATION})
COMMENT "Copying public directory")
add_custom_command(
OUTPUT "${NPM_BINARY_DIR}/node_modules" "${NPM_BINARY_DIR}/package-lock.json"
COMMAND npm install
DEPENDS "package.json"
WORKING_DIRECTORY ${NPM_BINARY_DIR}
COMMENT "Downloading npm dependencies for ${NPM_BINARY_DIR}/package.json")
add_custom_command(
TARGET start_development_server_${PACKAGE_NAME}
COMMAND npm start
WORKING_DIRECTORY ${NPM_BINARY_DIR}
COMMENT "Starting development server")
add_custom_command(
OUTPUT "${NPM_BINARY_DIR}/build"
COMMAND npm run build
DEPENDS copy_src_public download_npm_dependencies
COMMENT "Packing javascript files for deploy")
message(${NPM_INSTALL_DESTINATION})
install(DIRECTORY ${NPM_BINARY_DIR}/build/ DESTINATION ${CMAKE_INSTALL_PREFIX}/${NPM_INSTALL_DESTINATION})
endfunction(npm_install)
......@@ -8,7 +8,7 @@
"watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive",
"start-js": "react-scripts start",
"build-js": "react-scripts build",
"start": "npm run -p watch-css && npm run start-js",
"start": "npm run -p watch-css & npm run start-js",
"build": "npm run build-css && npm run build-js",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment