diff --git a/lib/cMake.js b/lib/cMake.js index 75f410ee..6ec0a79a 100644 --- a/lib/cMake.js +++ b/lib/cMake.js @@ -13,8 +13,6 @@ const npmConfigData = require('rc')('npm') const Toolset = require('./toolset') const headers = require('node-api-headers') -const path_to_api = require('../share/cmake/api') - class CMake { get path() { return this.options.cmakePath || 'cmake' diff --git a/share/cmake/api.js b/share/cmake/api.js deleted file mode 100644 index bf2f2fee..00000000 --- a/share/cmake/api.js +++ /dev/null @@ -1,3 +0,0 @@ -// The CLI needs a portable path to the API -const path_to_api = __dirname; -module.exports = path_to_api; diff --git a/tests/targets/cmake-js/.gitignore b/tests/api/hello_c/.gitignore similarity index 100% rename from tests/targets/cmake-js/.gitignore rename to tests/api/hello_c/.gitignore diff --git a/tests/api/hello_c/CMakeLists.txt b/tests/api/hello_c/CMakeLists.txt new file mode 100644 index 00000000..7f42dce7 --- /dev/null +++ b/tests/api/hello_c/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.15) + +project(hello_c) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/node_modules/cmake-js/share/cmake") +include(CMakeJS) + +# cmakejs_setup_node_api_c_library() # This can be used, but is called by cmakejs_create_node_api_addon + +cmakejs_create_node_api_addon( + addon + "src/hello/addon.c" +) \ No newline at end of file diff --git a/tests/targets/cmake-js/README.md b/tests/api/hello_c/README.md similarity index 100% rename from tests/targets/cmake-js/README.md rename to tests/api/hello_c/README.md diff --git a/tests/api/hello_c/index.js b/tests/api/hello_c/index.js new file mode 100644 index 00000000..a4971b05 --- /dev/null +++ b/tests/api/hello_c/index.js @@ -0,0 +1,5 @@ +// This small codeblock in your root-level index.js allows others to consume +// your addon as any other NodeJS module + +const addon = require(`./build/lib/addon.node`); +module.exports = addon; diff --git a/tests/targets/node-addon-api/package.json b/tests/api/hello_c/package.json similarity index 91% rename from tests/targets/node-addon-api/package.json rename to tests/api/hello_c/package.json index f96e4de1..f3268504 100644 --- a/tests/targets/node-addon-api/package.json +++ b/tests/api/hello_c/package.json @@ -1,5 +1,5 @@ { - "name": "@vendor/hello", + "name": "@vendor/hello-c", "version": "1.0.0", "description": "A test addon made using CMakeJS.cmake", "main": "index.js", @@ -17,7 +17,6 @@ }, "dependencies": { "cmake-js": "link:../../../", - "node-addon-api": "^7.1.0", "node-api-headers": "^1.1.0" } } diff --git a/tests/api/hello_c/src/hello/addon.c b/tests/api/hello_c/src/hello/addon.c new file mode 100644 index 00000000..9986a2c1 --- /dev/null +++ b/tests/api/hello_c/src/hello/addon.c @@ -0,0 +1,43 @@ +/** + * @file addon.cpp + * @brief A quick 'hello world' Napi Addon in C++ +*/ + +// Required header and flag +#if __has_include() && BUILDING_NODE_EXTENSION + +#include + +napi_value vendor_addon_hello(napi_env env, napi_callback_info args) +{ + napi_value greeting; + napi_status status; + + status = napi_create_string_utf8(env, "addon.node is online!", NAPI_AUTO_LENGTH, &greeting); + if (status != napi_ok) return NULL; + return greeting; +} + +napi_value vendor_addon_init(napi_env env, napi_value exports) +{ + napi_status status; + napi_value fn; + + // Export a chosen C function under a given Javascript key + + status = napi_create_function(env, NULL, 0, vendor_addon_hello, NULL, &fn); // Name of function on Javascript side... + if (status != napi_ok) return NULL; + + status = napi_set_named_property(env, exports, "hello", fn); // Name of function on C side... + if (status != napi_ok) return NULL; + + // The above expose the C function 'addon_hello' as a javascript function named '.hello', etc... + return exports; +} + +// Register a new addon with the intializer function defined above +NAPI_MODULE(addon, vendor_addon_init) // ( to use, initializer to use) + +#else // !__has_include() || !BUILDING_NODE_EXTENSION + #warning "Warning: Cannot find '' - try running 'npm -g install cmake-js'..." +#endif diff --git a/tests/targets/README.md b/tests/targets/README.md deleted file mode 100644 index d6f35c5d..00000000 --- a/tests/targets/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# CMakeJS.cmake targets - -The four directories here correspond to the four CMake targets we currently export: - -| dir | target | provides | link level | -| -------------- | ------------------------ | ------------------------------- | ----------- | -| node-dev | cmake-js::node-dev | \ | 0 | -| node-api | cmake-js::node-api | \ | 1 | -| node-addon-api | cmake-js::node-addon-api | \ | 2 | -| cmake-js | cmake-js::cmake-js | cmakejs_create_node_api_addon() | 3 (default) | - -Each target in the above order _depends on_ the one before it; they have also all been made relocatable. - -The first three targets, cmake-js::node-\*, each carries it's own set of headers, as indicated by their given names, and further clarified in the table above. - -Our proposed `--link-level` CLI switch can control how far down the list they want to go. User who specify a `--link-level=1` on their cmake-js CLI command(s) will handily find that they are automatically linked with and provided the header sets provided by cmake-js::node-api (the C addon headers), _as well as_ cmake-js::node-dev (which the C headers depend on). What they won't recieve or be linked with is any of the header set from cmake-js::node-addon-api (the C++ Addon wrappers). This is [desireable behaviour](). - -cmake-js::cmake-js is unique in that it doesn't carry any headers of it's own, but since it _does_ carry all the other targets by being last in the consumer chain, users linking to this target will recieve the full set of developer headers, _and_ will be able to use our very nice `cmakejs_create_node_api_addon()` function in their CMakeLists.txt, which vastly reduces the amount of intermediate/advanced CMake config they might otherwise be faced with. - -Everything is powered by a tidy combination of cmake-js' Javascript CLI and it's CMake API. - -As a cherry on the cake, users will be able to call CPack on their addons, and find that their CMake source and binary dirs are bundled up along with the header sets that they requested via `--link-level` (and nothing more). diff --git a/tests/targets/cmake-js/CMakeLists.txt b/tests/targets/cmake-js/CMakeLists.txt deleted file mode 100644 index 6c747613..00000000 --- a/tests/targets/cmake-js/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(hello) - -# For CMake IDE tools support (do yarn/install first and keep your node_modules folder around) -if(NOT DEFINED CMAKE_JS_VERSION) - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/node_modules/cmake-js/share/cmake") -endif() - -include(CMakeJS) - -add_library(addon SHARED "src/hello/addon.cpp") -target_link_libraries(addon PRIVATE cmake-js::cmake-js) # relocatable deps resolved! -set_target_properties(addon PROPERTIES PREFIX "" SUFFIX ".node") -set_target_properties(addon PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") -target_compile_definitions(addon PUBLIC BUILDING_NODE_EXTENSION) -target_compile_definitions(addon PUBLIC NAPI_VERSION=8) -target_compile_definitions(addon PUBLIC NAPI_CPP_EXCEPTIONS_MAYBE) - -# For Visual Studio generators -if(MSVC) - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" CACHE STRING "Select the MSVC runtime library for use by compilers targeting the MSVC ABI." FORCE) - if(CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET) - execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS}) - endif() -endif() diff --git a/tests/targets/cmake-js/index.js b/tests/targets/cmake-js/index.js deleted file mode 100644 index 4e5b1cdb..00000000 --- a/tests/targets/cmake-js/index.js +++ /dev/null @@ -1,10 +0,0 @@ -// This small codeblock in your root-level index.js allows others to consume -// your addon as any other NodeJS module -const platform = process.platform; -var buildDir = "/build/lib/"; - -if(platform === "win32") - buildDir = "\\build\\bin\\Release\\"; - -const hello = require(`.${buildDir}addon.node`); -module.exports = hello; diff --git a/tests/targets/cmake-js/package.json b/tests/targets/cmake-js/package.json deleted file mode 100644 index 43c42242..00000000 --- a/tests/targets/cmake-js/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "@vendor/hello", - "version": "1.0.0", - "description": "A test addon made using CMakeJS.cmake", - "main": "index.js", - "license": "MIT", - "scripts": { - "start": "node -p \"const addon = require('./index'); console.log(addon.hello());\"", - "install": "cmake-js install", - "postinstall": "cmake-js compile", - "configure": "cmake-js configure", - "reconfigure": "cmake-js reconfigure", - "build": "cmake-js build", - "rebuild": "cmake-js rebuild", - "clean": "cmake-js clean", - "wipe": "cmake-js clean && rm -rvf ./node_modules" - }, - "dependencies": { - "cmake-js": "link:../../../", - "node-addon-api": "^7.1.0", - "node-api-headers": "^1.1.0" - } -} diff --git a/tests/targets/cmake-js/src/hello/addon.cpp b/tests/targets/cmake-js/src/hello/addon.cpp deleted file mode 100644 index 57c7c072..00000000 --- a/tests/targets/cmake-js/src/hello/addon.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @file addon.cpp - * @brief A quick 'hello world' Napi Addon in C++ -*/ - -// Required header and C++ flag -#if __has_include() && BUILDING_NODE_EXTENSION - -#include - -Napi::Value Hello(const Napi::CallbackInfo& info) { - return Napi::String::New(info.Env(), "addon.node is online!"); -} - -Napi::Value Version(const Napi::CallbackInfo& info) { - return Napi::Number::New(info.Env(), NAPI_VERSION); -} - -Napi::Object Init(Napi::Env env, Napi::Object exports) { - - // Export a chosen C++ function under a given Javascript key - exports.Set( - Napi::String::New(env, "hello"), // Name of function on Javascript side... - Napi::Function::New(env, Hello) // Name of function on C++ side... - ); - - exports.Set( - Napi::String::New(env, "version"), - Napi::Function::New(env, Version) - ); - - // The above will expose the C++ function 'Hello' as a javascript function - // named 'hello', etc... - return exports; -} - -// Register a new addon with the intializer function defined above -NODE_API_MODULE(addon, Init) // (name to use, initializer to use) - - -#else // !__has_include() || !BUILDING_NODE_EXTENSION - #warning "Warning: Cannot find '' - try running 'npm -g install cmake-js'..." -#endif diff --git a/tests/targets/node-addon-api/.gitignore b/tests/targets/node-addon-api/.gitignore deleted file mode 100644 index 4c561b01..00000000 --- a/tests/targets/node-addon-api/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules -build -install diff --git a/tests/targets/node-addon-api/CMakeLists.txt b/tests/targets/node-addon-api/CMakeLists.txt deleted file mode 100644 index 17402452..00000000 --- a/tests/targets/node-addon-api/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(hello) - -set(CMAKEJS_USING_CMAKEJS FALSE) # this should have been done with '--link-level=2' on the CLI, testing this way for now - -# For CMake IDE tools support (do yarn/install first and keep your node_modules folder around) -if(NOT DEFINED CMAKE_JS_VERSION) - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/node_modules/cmake-js/share/cmake") -endif() - -include(CMakeJS) - -add_library(addon SHARED "src/hello/addon.cpp") -target_link_libraries(addon PRIVATE cmake-js::node-addon-api) # relocatable deps resolved! -set_target_properties(addon PROPERTIES PREFIX "" SUFFIX ".node") -set_target_properties(addon PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") -target_compile_definitions(addon PUBLIC BUILDING_NODE_EXTENSION) -target_compile_definitions(addon PUBLIC NAPI_VERSION=8) -target_compile_definitions(addon PUBLIC NAPI_CPP_EXCEPTIONS_MAYBE) - -# For Visual Studio generators -if(MSVC) - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" CACHE STRING "Select the MSVC runtime library for use by compilers targeting the MSVC ABI." FORCE) - if(CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET) - execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS}) - endif() -endif() diff --git a/tests/targets/node-addon-api/README.md b/tests/targets/node-addon-api/README.md deleted file mode 100644 index e5f46ff0..00000000 --- a/tests/targets/node-addon-api/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## I am an addon made with Napi Addon API in C++. - -You can build me, export me as a Javscript module, extend my functionality with your own code ideas, connecting Javascript and C++ functionality together in one binding package. Any importing consumers can get me from '@vendor/hello' in their package.json deps... see 'hello_consumer'! - -Please see my package.json to understand how I work. - -Powered by cmake-js CLI diff --git a/tests/targets/node-addon-api/index.js b/tests/targets/node-addon-api/index.js deleted file mode 100644 index 4e5b1cdb..00000000 --- a/tests/targets/node-addon-api/index.js +++ /dev/null @@ -1,10 +0,0 @@ -// This small codeblock in your root-level index.js allows others to consume -// your addon as any other NodeJS module -const platform = process.platform; -var buildDir = "/build/lib/"; - -if(platform === "win32") - buildDir = "\\build\\bin\\Release\\"; - -const hello = require(`.${buildDir}addon.node`); -module.exports = hello; diff --git a/tests/targets/node-addon-api/src/hello/addon.cpp b/tests/targets/node-addon-api/src/hello/addon.cpp deleted file mode 100644 index 57c7c072..00000000 --- a/tests/targets/node-addon-api/src/hello/addon.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @file addon.cpp - * @brief A quick 'hello world' Napi Addon in C++ -*/ - -// Required header and C++ flag -#if __has_include() && BUILDING_NODE_EXTENSION - -#include - -Napi::Value Hello(const Napi::CallbackInfo& info) { - return Napi::String::New(info.Env(), "addon.node is online!"); -} - -Napi::Value Version(const Napi::CallbackInfo& info) { - return Napi::Number::New(info.Env(), NAPI_VERSION); -} - -Napi::Object Init(Napi::Env env, Napi::Object exports) { - - // Export a chosen C++ function under a given Javascript key - exports.Set( - Napi::String::New(env, "hello"), // Name of function on Javascript side... - Napi::Function::New(env, Hello) // Name of function on C++ side... - ); - - exports.Set( - Napi::String::New(env, "version"), - Napi::Function::New(env, Version) - ); - - // The above will expose the C++ function 'Hello' as a javascript function - // named 'hello', etc... - return exports; -} - -// Register a new addon with the intializer function defined above -NODE_API_MODULE(addon, Init) // (name to use, initializer to use) - - -#else // !__has_include() || !BUILDING_NODE_EXTENSION - #warning "Warning: Cannot find '' - try running 'npm -g install cmake-js'..." -#endif diff --git a/tests/targets/node-api/.gitignore b/tests/targets/node-api/.gitignore deleted file mode 100644 index 4c561b01..00000000 --- a/tests/targets/node-api/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules -build -install diff --git a/tests/targets/node-api/CMakeLists.txt b/tests/targets/node-api/CMakeLists.txt deleted file mode 100644 index 92659acd..00000000 --- a/tests/targets/node-api/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(hello) - -set(CMAKEJS_USING_NODE_ADDON_API FALSE) # this should have been done with '--link-level=1' on the CLI, testing this way for now - -# For CMake IDE tools support (do yarn/install first and keep your node_modules folder around) -if(NOT DEFINED CMAKE_JS_VERSION) - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/node_modules/cmake-js/share/cmake") -endif() - -include(CMakeJS) - -add_library(addon SHARED "src/hello/addon.cc") -target_link_libraries(addon PRIVATE cmake-js::node-api) # relocatable deps resolved! -set_target_properties(addon PROPERTIES PREFIX "" SUFFIX ".node") -set_target_properties(addon PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") - -# For Visual Studio generators -if(MSVC) - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" CACHE STRING "Select the MSVC runtime library for use by compilers targeting the MSVC ABI." FORCE) - if(CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET) - execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS}) - endif() -endif() diff --git a/tests/targets/node-api/README.md b/tests/targets/node-api/README.md deleted file mode 100644 index 9928f18d..00000000 --- a/tests/targets/node-api/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## I am an addon made with Napi Addon API in C. - -You can build me, export me as a Javscript module, extend my functionality with your own code ideas, connecting Javascript and C functionality together in one binding package. Any importing consumers can get me from '@vendor/hello' in their package.json deps... see 'hello_consumer'! - -Please see my package.json to understand how I work. - -Powered by cmake-js CLI diff --git a/tests/targets/node-api/index.js b/tests/targets/node-api/index.js deleted file mode 100644 index 4e5b1cdb..00000000 --- a/tests/targets/node-api/index.js +++ /dev/null @@ -1,10 +0,0 @@ -// This small codeblock in your root-level index.js allows others to consume -// your addon as any other NodeJS module -const platform = process.platform; -var buildDir = "/build/lib/"; - -if(platform === "win32") - buildDir = "\\build\\bin\\Release\\"; - -const hello = require(`.${buildDir}addon.node`); -module.exports = hello; diff --git a/tests/targets/node-api/package.json b/tests/targets/node-api/package.json deleted file mode 100644 index c5f26daf..00000000 --- a/tests/targets/node-api/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "@vendor/hello", - "version": "1.0.0", - "description": "A test addon made using CMakeJS.cmake", - "main": "index.js", - "license": "MIT", - "scripts": { - "start": "node -p \"const addon = require('./index'); console.log(addon.hello());\"", - "install": "cmake-js install", - "postinstall": "cmake-js compile", - "configure": "cmake-js configure", - "reconfigure": "cmake-js reconfigure", - "build": "cmake-js build", - "rebuild": "cmake-js rebuild", - "clean": "cmake-js clean", - "wipe": "cmake-js clean && rm -rvf ./node_modules" - }, - "dependencies": { - "cmake-js": "link:../../../", - "node-api-headers": "^1.1.0" - } -} diff --git a/tests/targets/node-api/src/hello/addon.cc b/tests/targets/node-api/src/hello/addon.cc deleted file mode 100644 index 6ed16d48..00000000 --- a/tests/targets/node-api/src/hello/addon.cc +++ /dev/null @@ -1,56 +0,0 @@ -/** - * @file addon.cc - * @brief A quick 'hello world' Node Addon in C - * - * Please note that this example is from the NodeJS Addon - * official docs, and uses 'nullptr', which does not exist - * in 'pure' C. If you name your addon source file with an - * extension of just '.c', the compiler/generator will assume - * you are building in 'pure' C and this useage of 'nullptr' - * will cause the build to fail. - * - * To have a more 'C-like' experience building addons in C, - * we recommend using the extension '.cc' for your sources, - * because this extension does not differentiate between - * being a C file or a C++ file, unlike both '.c' and the - * various '.cpp/cxx' file extensions. -*/ - -// Required header -#if __has_include() - -#include - -napi_value vendor_addon_hello(napi_env env, napi_callback_info args) -{ - napi_value greeting; - napi_status status; - - status = napi_create_string_utf8(env, "addon.node is online!", NAPI_AUTO_LENGTH, &greeting); - if (status != napi_ok) return nullptr; - return greeting; -} - -napi_value vendor_addon_init(napi_env env, napi_value exports) -{ - napi_status status; - napi_value fn; - - // Export a chosen C function under a given Javascript key - - status = napi_create_function(env, nullptr, 0, vendor_addon_hello, nullptr, &fn); // Name of function on Javascript side... - if (status != napi_ok) return nullptr; - - status = napi_set_named_property(env, exports, "hello", fn); // Name of function on C side... - if (status != napi_ok) return nullptr; - - // The above expose the C function 'addon_hello' as a javascript function named '.hello', etc... - return exports; -} - -// Register a new addon with the intializer function defined above -NAPI_MODULE(addon, vendor_addon_init) // ( to use, initializer to use) - -#else // !__has_include() - #warning "Warning: Cannot find '' - try running 'npm -g install cmake-js'..." -#endif diff --git a/tests/targets/node-dev/.gitignore b/tests/targets/node-dev/.gitignore deleted file mode 100644 index 4c561b01..00000000 --- a/tests/targets/node-dev/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules -build -install diff --git a/tests/targets/node-dev/CMakeLists.txt b/tests/targets/node-dev/CMakeLists.txt deleted file mode 100644 index ccf87e11..00000000 --- a/tests/targets/node-dev/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(hello) - -set(CMAKEJS_USING_NODE_API FALSE) # this should have been done with '--link-level=0' on the CLI, testing this way for now - -# For CMake IDE tools support (do yarn/install first and keep your node_modules folder around) -if(NOT DEFINED CMAKE_JS_VERSION) - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/node_modules/cmake-js/share/cmake") -endif() - -include(CMakeJS) - -add_library(addon SHARED "src/hello/addon.cc") -target_link_libraries(addon PRIVATE cmake-js::node-dev) # relocatable deps resolved! -set_target_properties(addon PROPERTIES PREFIX "" SUFFIX ".node") -set_target_properties(addon PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") - -# For Visual Studio generators -if(MSVC) - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" CACHE STRING "Select the MSVC runtime library for use by compilers targeting the MSVC ABI." FORCE) - if(CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET) - execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS}) - endif() -endif() diff --git a/tests/targets/node-dev/README.md b/tests/targets/node-dev/README.md deleted file mode 100644 index dbc35886..00000000 --- a/tests/targets/node-dev/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## I am an addon made with Node API in C++. - -You can build me, export me as a Javscript module, extend my functionality with your own code ideas, connecting Javascript and C++ functionality together in one binding package. Any importing consumers can get me from '@vendor/hello' in their package.json deps... see 'hello_consumer'! - -Please see my package.json to understand how I work. - -Powered by cmake-js CLI diff --git a/tests/targets/node-dev/index.js b/tests/targets/node-dev/index.js deleted file mode 100644 index 4e5b1cdb..00000000 --- a/tests/targets/node-dev/index.js +++ /dev/null @@ -1,10 +0,0 @@ -// This small codeblock in your root-level index.js allows others to consume -// your addon as any other NodeJS module -const platform = process.platform; -var buildDir = "/build/lib/"; - -if(platform === "win32") - buildDir = "\\build\\bin\\Release\\"; - -const hello = require(`.${buildDir}addon.node`); -module.exports = hello; diff --git a/tests/targets/node-dev/package.json b/tests/targets/node-dev/package.json deleted file mode 100644 index ea8bfdfd..00000000 --- a/tests/targets/node-dev/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@vendor/hello", - "version": "1.0.0", - "description": "A test addon made using CMakeJS.cmake", - "main": "index.js", - "license": "MIT", - "scripts": { - "start": "node -p \"const addon = require('./index'); console.log(addon.hello());\"", - "install": "cmake-js install", - "postinstall": "cmake-js compile", - "configure": "cmake-js configure", - "reconfigure": "cmake-js reconfigure", - "build": "cmake-js build", - "rebuild": "cmake-js rebuild", - "clean": "cmake-js clean", - "wipe": "cmake-js clean && rm -rvf ./node_modules" - }, - "dependencies": { - "cmake-js": "link:../../../" - } -} diff --git a/tests/targets/node-dev/src/hello/addon.cc b/tests/targets/node-dev/src/hello/addon.cc deleted file mode 100644 index ad8203e9..00000000 --- a/tests/targets/node-dev/src/hello/addon.cc +++ /dev/null @@ -1,47 +0,0 @@ -/** - * @file addon.cc - * @brief A quick 'hello world' Node Addon in C++ -*/ - -// Required header -#if __has_include() - -#include - -namespace vendor { - -void Hello(const v8::FunctionCallbackInfo& args) -{ - v8::Isolate* isolate = args.GetIsolate(); - args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "addon.node is online!").ToLocalChecked()); -} - -// void Version(const v8::FunctionCallbackInfo& args) -// { -// v8::Isolate* isolate = args.GetIsolate(); -// args.GetReturnValue().Set(NODE_VERSION); // should be a v8::Number... -// } - -// Expose the C++ function 'Hello' as a javascript function named 'hello', etc... -void Initialize(v8::Local exports) -{ - // Export a chosen C++ function under a given Javascript key - NODE_SET_METHOD(exports, - "hello", // Name of function on Javascript side... - Hello // Name of function on C++ side... - ); - - // NODE_SET_METHOD(exports, - // "version", - // Version - // ); -} - -// Register a new addon with the intializer function defined above -NODE_MODULE(addon, Initialize) // (name to use, initializer to use) - -} // namespace vendor - -#else // !__has_include() - #warning "Warning: Cannot find '' - try running 'npm -g install cmake-js'..." -#endif