diff --git a/.gitignore b/.gitignore index 3413a6eb..1b45478e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ build/ -build_with_cmake/ node_modules/ Debug/ Release/ diff --git a/README.md b/README.md index 58a8031f..5e46f501 100644 --- a/README.md +++ b/README.md @@ -15,37 +15,45 @@ Implementations against unsupported versions of Node.js are provided for completeness and historical context. They are not maintained. The examples are primarily maintained for Node-API and node-addon-api and as outlined in -the Node.js [documentation](https://nodejs.org/dist/latest/docs/api/addons.html), +the Node.js [documentation](https://nodejs.org/dist/latest/docs/api/addons.html), unless there is a need for direct access to functionality which -is not exposed by Node-API, use Node-API. +is not exposed by Node-API, use Node-API. -The [Node-API Resource](http://nodejs.github.io/node-addon-examples/) offers an -excellent orientation and tips for developers just getting started with Node-API +The [Node-API Resource](http://nodejs.github.io/node-addon-examples/) offers an +excellent orientation and tips for developers just getting started with Node-API and `node-addon-api`. ## Usage The directory structure is as follows: +```sh +REPO_ROOT +├── test_all.js +├── package.json +├── README.md +└── src + ├── 1-getting-started + │ ├── example1 + │ │ ├── nan + │ │ ├── node-addon-api + │ │ └── napi + │ ├── example2 + │ └── example3 + ├── 2-js-to-native-conversion + ├── 3-context-awareness + ├── 4-references-and-handle-scope + ├── 5-async-work + ├── 6-threadsafe-function + ├── 7-events + └── 8-tooling ``` - - | - +--- - | | - | +--- files... - +--- - . | - . +--- files... - . -``` - In each example's implementation subdirectory, run ```text -$ npm install -$ node ./ +npm install +node ./ ``` to see the example in action. - diff --git a/1_hello_world/README.md b/src/1-getting-started/1_hello_world/README.md similarity index 100% rename from 1_hello_world/README.md rename to src/1-getting-started/1_hello_world/README.md diff --git a/1_hello_world/nan/binding.gyp b/src/1-getting-started/1_hello_world/nan/binding.gyp similarity index 100% rename from 1_hello_world/nan/binding.gyp rename to src/1-getting-started/1_hello_world/nan/binding.gyp diff --git a/1_hello_world/nan/hello.cc b/src/1-getting-started/1_hello_world/nan/hello.cc similarity index 100% rename from 1_hello_world/nan/hello.cc rename to src/1-getting-started/1_hello_world/nan/hello.cc diff --git a/1_hello_world/nan/hello.js b/src/1-getting-started/1_hello_world/nan/hello.js similarity index 100% rename from 1_hello_world/nan/hello.js rename to src/1-getting-started/1_hello_world/nan/hello.js diff --git a/1_hello_world/nan/package.json b/src/1-getting-started/1_hello_world/nan/package.json similarity index 100% rename from 1_hello_world/nan/package.json rename to src/1-getting-started/1_hello_world/nan/package.json diff --git a/1_hello_world/napi/binding.gyp b/src/1-getting-started/1_hello_world/napi/binding.gyp similarity index 100% rename from 1_hello_world/napi/binding.gyp rename to src/1-getting-started/1_hello_world/napi/binding.gyp diff --git a/1_hello_world/napi/hello.c b/src/1-getting-started/1_hello_world/napi/hello.c similarity index 100% rename from 1_hello_world/napi/hello.c rename to src/1-getting-started/1_hello_world/napi/hello.c diff --git a/1_hello_world/napi/hello.js b/src/1-getting-started/1_hello_world/napi/hello.js similarity index 100% rename from 1_hello_world/napi/hello.js rename to src/1-getting-started/1_hello_world/napi/hello.js diff --git a/1_hello_world/napi/package.json b/src/1-getting-started/1_hello_world/napi/package.json similarity index 100% rename from 1_hello_world/napi/package.json rename to src/1-getting-started/1_hello_world/napi/package.json diff --git a/1_hello_world/node-addon-api-addon-class/binding.gyp b/src/1-getting-started/1_hello_world/node-addon-api-addon-class/binding.gyp similarity index 100% rename from 1_hello_world/node-addon-api-addon-class/binding.gyp rename to src/1-getting-started/1_hello_world/node-addon-api-addon-class/binding.gyp diff --git a/1_hello_world/node-addon-api-addon-class/hello.cc b/src/1-getting-started/1_hello_world/node-addon-api-addon-class/hello.cc similarity index 73% rename from 1_hello_world/node-addon-api-addon-class/hello.cc rename to src/1-getting-started/1_hello_world/node-addon-api-addon-class/hello.cc index 02429a0a..549ea1ff 100644 --- a/1_hello_world/node-addon-api-addon-class/hello.cc +++ b/src/1-getting-started/1_hello_world/node-addon-api-addon-class/hello.cc @@ -3,9 +3,8 @@ class HelloAddon : public Napi::Addon { public: HelloAddon(Napi::Env env, Napi::Object exports) { - DefineAddon(exports, { - InstanceMethod("hello", &HelloAddon::Hello, napi_enumerable) - }); + DefineAddon(exports, + {InstanceMethod("hello", &HelloAddon::Hello, napi_enumerable)}); } private: diff --git a/1_hello_world/node-addon-api-addon-class/hello.js b/src/1-getting-started/1_hello_world/node-addon-api-addon-class/hello.js similarity index 100% rename from 1_hello_world/node-addon-api-addon-class/hello.js rename to src/1-getting-started/1_hello_world/node-addon-api-addon-class/hello.js diff --git a/1_hello_world/node-addon-api-addon-class/package.json b/src/1-getting-started/1_hello_world/node-addon-api-addon-class/package.json similarity index 100% rename from 1_hello_world/node-addon-api-addon-class/package.json rename to src/1-getting-started/1_hello_world/node-addon-api-addon-class/package.json diff --git a/1_hello_world/node-addon-api/binding.gyp b/src/1-getting-started/1_hello_world/node-addon-api/binding.gyp similarity index 100% rename from 1_hello_world/node-addon-api/binding.gyp rename to src/1-getting-started/1_hello_world/node-addon-api/binding.gyp diff --git a/1_hello_world/node-addon-api/hello.cc b/src/1-getting-started/1_hello_world/node-addon-api/hello.cc similarity index 100% rename from 1_hello_world/node-addon-api/hello.cc rename to src/1-getting-started/1_hello_world/node-addon-api/hello.cc diff --git a/1_hello_world/node-addon-api/hello.js b/src/1-getting-started/1_hello_world/node-addon-api/hello.js similarity index 100% rename from 1_hello_world/node-addon-api/hello.js rename to src/1-getting-started/1_hello_world/node-addon-api/hello.js diff --git a/1_hello_world/node-addon-api/package.json b/src/1-getting-started/1_hello_world/node-addon-api/package.json similarity index 100% rename from 1_hello_world/node-addon-api/package.json rename to src/1-getting-started/1_hello_world/node-addon-api/package.json diff --git a/2_function_arguments/README.md b/src/1-getting-started/2_function_arguments/README.md similarity index 100% rename from 2_function_arguments/README.md rename to src/1-getting-started/2_function_arguments/README.md diff --git a/2_function_arguments/nan/addon.cc b/src/1-getting-started/2_function_arguments/nan/addon.cc similarity index 100% rename from 2_function_arguments/nan/addon.cc rename to src/1-getting-started/2_function_arguments/nan/addon.cc diff --git a/2_function_arguments/nan/addon.js b/src/1-getting-started/2_function_arguments/nan/addon.js similarity index 100% rename from 2_function_arguments/nan/addon.js rename to src/1-getting-started/2_function_arguments/nan/addon.js diff --git a/2_function_arguments/nan/binding.gyp b/src/1-getting-started/2_function_arguments/nan/binding.gyp similarity index 100% rename from 2_function_arguments/nan/binding.gyp rename to src/1-getting-started/2_function_arguments/nan/binding.gyp diff --git a/2_function_arguments/nan/package.json b/src/1-getting-started/2_function_arguments/nan/package.json similarity index 100% rename from 2_function_arguments/nan/package.json rename to src/1-getting-started/2_function_arguments/nan/package.json diff --git a/2_function_arguments/napi/addon.c b/src/1-getting-started/2_function_arguments/napi/addon.c similarity index 100% rename from 2_function_arguments/napi/addon.c rename to src/1-getting-started/2_function_arguments/napi/addon.c diff --git a/2_function_arguments/napi/addon.js b/src/1-getting-started/2_function_arguments/napi/addon.js similarity index 100% rename from 2_function_arguments/napi/addon.js rename to src/1-getting-started/2_function_arguments/napi/addon.js diff --git a/2_function_arguments/napi/binding.gyp b/src/1-getting-started/2_function_arguments/napi/binding.gyp similarity index 100% rename from 2_function_arguments/napi/binding.gyp rename to src/1-getting-started/2_function_arguments/napi/binding.gyp diff --git a/2_function_arguments/napi/package.json b/src/1-getting-started/2_function_arguments/napi/package.json similarity index 100% rename from 2_function_arguments/napi/package.json rename to src/1-getting-started/2_function_arguments/napi/package.json diff --git a/2_function_arguments/node-addon-api/addon.cc b/src/1-getting-started/2_function_arguments/node-addon-api/addon.cc similarity index 100% rename from 2_function_arguments/node-addon-api/addon.cc rename to src/1-getting-started/2_function_arguments/node-addon-api/addon.cc diff --git a/2_function_arguments/node-addon-api/addon.js b/src/1-getting-started/2_function_arguments/node-addon-api/addon.js similarity index 100% rename from 2_function_arguments/node-addon-api/addon.js rename to src/1-getting-started/2_function_arguments/node-addon-api/addon.js diff --git a/2_function_arguments/node-addon-api/binding.gyp b/src/1-getting-started/2_function_arguments/node-addon-api/binding.gyp similarity index 100% rename from 2_function_arguments/node-addon-api/binding.gyp rename to src/1-getting-started/2_function_arguments/node-addon-api/binding.gyp diff --git a/2_function_arguments/node-addon-api/package.json b/src/1-getting-started/2_function_arguments/node-addon-api/package.json similarity index 100% rename from 2_function_arguments/node-addon-api/package.json rename to src/1-getting-started/2_function_arguments/node-addon-api/package.json diff --git a/3_callbacks/nan/addon.cc b/src/1-getting-started/3_callbacks/nan/addon.cc similarity index 100% rename from 3_callbacks/nan/addon.cc rename to src/1-getting-started/3_callbacks/nan/addon.cc diff --git a/3_callbacks/nan/addon.js b/src/1-getting-started/3_callbacks/nan/addon.js similarity index 100% rename from 3_callbacks/nan/addon.js rename to src/1-getting-started/3_callbacks/nan/addon.js diff --git a/3_callbacks/nan/binding.gyp b/src/1-getting-started/3_callbacks/nan/binding.gyp similarity index 100% rename from 3_callbacks/nan/binding.gyp rename to src/1-getting-started/3_callbacks/nan/binding.gyp diff --git a/3_callbacks/nan/package.json b/src/1-getting-started/3_callbacks/nan/package.json similarity index 100% rename from 3_callbacks/nan/package.json rename to src/1-getting-started/3_callbacks/nan/package.json diff --git a/3_callbacks/napi/addon.c b/src/1-getting-started/3_callbacks/napi/addon.c similarity index 100% rename from 3_callbacks/napi/addon.c rename to src/1-getting-started/3_callbacks/napi/addon.c diff --git a/3_callbacks/napi/addon.js b/src/1-getting-started/3_callbacks/napi/addon.js similarity index 100% rename from 3_callbacks/napi/addon.js rename to src/1-getting-started/3_callbacks/napi/addon.js diff --git a/3_callbacks/napi/binding.gyp b/src/1-getting-started/3_callbacks/napi/binding.gyp similarity index 100% rename from 3_callbacks/napi/binding.gyp rename to src/1-getting-started/3_callbacks/napi/binding.gyp diff --git a/3_callbacks/napi/package.json b/src/1-getting-started/3_callbacks/napi/package.json similarity index 100% rename from 3_callbacks/napi/package.json rename to src/1-getting-started/3_callbacks/napi/package.json diff --git a/3_callbacks/node-addon-api/addon.cc b/src/1-getting-started/3_callbacks/node-addon-api/addon.cc similarity index 100% rename from 3_callbacks/node-addon-api/addon.cc rename to src/1-getting-started/3_callbacks/node-addon-api/addon.cc diff --git a/3_callbacks/node-addon-api/addon.js b/src/1-getting-started/3_callbacks/node-addon-api/addon.js similarity index 100% rename from 3_callbacks/node-addon-api/addon.js rename to src/1-getting-started/3_callbacks/node-addon-api/addon.js diff --git a/3_callbacks/node-addon-api/binding.gyp b/src/1-getting-started/3_callbacks/node-addon-api/binding.gyp similarity index 100% rename from 3_callbacks/node-addon-api/binding.gyp rename to src/1-getting-started/3_callbacks/node-addon-api/binding.gyp diff --git a/3_callbacks/node-addon-api/package.json b/src/1-getting-started/3_callbacks/node-addon-api/package.json similarity index 100% rename from 3_callbacks/node-addon-api/package.json rename to src/1-getting-started/3_callbacks/node-addon-api/package.json diff --git a/4_object_factory/nan/addon.cc b/src/1-getting-started/4_object_factory/nan/addon.cc similarity index 100% rename from 4_object_factory/nan/addon.cc rename to src/1-getting-started/4_object_factory/nan/addon.cc diff --git a/4_object_factory/nan/addon.js b/src/1-getting-started/4_object_factory/nan/addon.js similarity index 100% rename from 4_object_factory/nan/addon.js rename to src/1-getting-started/4_object_factory/nan/addon.js diff --git a/4_object_factory/nan/binding.gyp b/src/1-getting-started/4_object_factory/nan/binding.gyp similarity index 100% rename from 4_object_factory/nan/binding.gyp rename to src/1-getting-started/4_object_factory/nan/binding.gyp diff --git a/4_object_factory/nan/package.json b/src/1-getting-started/4_object_factory/nan/package.json similarity index 100% rename from 4_object_factory/nan/package.json rename to src/1-getting-started/4_object_factory/nan/package.json diff --git a/4_object_factory/napi/addon.c b/src/1-getting-started/4_object_factory/napi/addon.c similarity index 100% rename from 4_object_factory/napi/addon.c rename to src/1-getting-started/4_object_factory/napi/addon.c diff --git a/4_object_factory/napi/addon.js b/src/1-getting-started/4_object_factory/napi/addon.js similarity index 100% rename from 4_object_factory/napi/addon.js rename to src/1-getting-started/4_object_factory/napi/addon.js diff --git a/4_object_factory/napi/binding.gyp b/src/1-getting-started/4_object_factory/napi/binding.gyp similarity index 100% rename from 4_object_factory/napi/binding.gyp rename to src/1-getting-started/4_object_factory/napi/binding.gyp diff --git a/4_object_factory/napi/package.json b/src/1-getting-started/4_object_factory/napi/package.json similarity index 100% rename from 4_object_factory/napi/package.json rename to src/1-getting-started/4_object_factory/napi/package.json diff --git a/4_object_factory/node-addon-api/addon.cc b/src/1-getting-started/4_object_factory/node-addon-api/addon.cc similarity index 100% rename from 4_object_factory/node-addon-api/addon.cc rename to src/1-getting-started/4_object_factory/node-addon-api/addon.cc diff --git a/4_object_factory/node-addon-api/addon.js b/src/1-getting-started/4_object_factory/node-addon-api/addon.js similarity index 100% rename from 4_object_factory/node-addon-api/addon.js rename to src/1-getting-started/4_object_factory/node-addon-api/addon.js diff --git a/4_object_factory/node-addon-api/binding.gyp b/src/1-getting-started/4_object_factory/node-addon-api/binding.gyp similarity index 100% rename from 4_object_factory/node-addon-api/binding.gyp rename to src/1-getting-started/4_object_factory/node-addon-api/binding.gyp diff --git a/4_object_factory/node-addon-api/package.json b/src/1-getting-started/4_object_factory/node-addon-api/package.json similarity index 100% rename from 4_object_factory/node-addon-api/package.json rename to src/1-getting-started/4_object_factory/node-addon-api/package.json diff --git a/5_function_factory/nan/addon.cc b/src/1-getting-started/5_function_factory/nan/addon.cc similarity index 100% rename from 5_function_factory/nan/addon.cc rename to src/1-getting-started/5_function_factory/nan/addon.cc diff --git a/5_function_factory/nan/addon.js b/src/1-getting-started/5_function_factory/nan/addon.js similarity index 100% rename from 5_function_factory/nan/addon.js rename to src/1-getting-started/5_function_factory/nan/addon.js diff --git a/5_function_factory/nan/binding.gyp b/src/1-getting-started/5_function_factory/nan/binding.gyp similarity index 100% rename from 5_function_factory/nan/binding.gyp rename to src/1-getting-started/5_function_factory/nan/binding.gyp diff --git a/5_function_factory/nan/package.json b/src/1-getting-started/5_function_factory/nan/package.json similarity index 100% rename from 5_function_factory/nan/package.json rename to src/1-getting-started/5_function_factory/nan/package.json diff --git a/5_function_factory/napi/addon.c b/src/1-getting-started/5_function_factory/napi/addon.c similarity index 100% rename from 5_function_factory/napi/addon.c rename to src/1-getting-started/5_function_factory/napi/addon.c diff --git a/5_function_factory/napi/addon.js b/src/1-getting-started/5_function_factory/napi/addon.js similarity index 100% rename from 5_function_factory/napi/addon.js rename to src/1-getting-started/5_function_factory/napi/addon.js diff --git a/5_function_factory/napi/binding.gyp b/src/1-getting-started/5_function_factory/napi/binding.gyp similarity index 100% rename from 5_function_factory/napi/binding.gyp rename to src/1-getting-started/5_function_factory/napi/binding.gyp diff --git a/5_function_factory/napi/package.json b/src/1-getting-started/5_function_factory/napi/package.json similarity index 100% rename from 5_function_factory/napi/package.json rename to src/1-getting-started/5_function_factory/napi/package.json diff --git a/5_function_factory/node-addon-api/addon.cc b/src/1-getting-started/5_function_factory/node-addon-api/addon.cc similarity index 100% rename from 5_function_factory/node-addon-api/addon.cc rename to src/1-getting-started/5_function_factory/node-addon-api/addon.cc diff --git a/5_function_factory/node-addon-api/addon.js b/src/1-getting-started/5_function_factory/node-addon-api/addon.js similarity index 100% rename from 5_function_factory/node-addon-api/addon.js rename to src/1-getting-started/5_function_factory/node-addon-api/addon.js diff --git a/5_function_factory/node-addon-api/binding.gyp b/src/1-getting-started/5_function_factory/node-addon-api/binding.gyp similarity index 100% rename from 5_function_factory/node-addon-api/binding.gyp rename to src/1-getting-started/5_function_factory/node-addon-api/binding.gyp diff --git a/5_function_factory/node-addon-api/package.json b/src/1-getting-started/5_function_factory/node-addon-api/package.json similarity index 100% rename from 5_function_factory/node-addon-api/package.json rename to src/1-getting-started/5_function_factory/node-addon-api/package.json diff --git a/6_object_wrap/nan/addon.cc b/src/1-getting-started/6_object_wrap/nan/addon.cc similarity index 100% rename from 6_object_wrap/nan/addon.cc rename to src/1-getting-started/6_object_wrap/nan/addon.cc diff --git a/6_object_wrap/nan/addon.js b/src/1-getting-started/6_object_wrap/nan/addon.js similarity index 100% rename from 6_object_wrap/nan/addon.js rename to src/1-getting-started/6_object_wrap/nan/addon.js diff --git a/6_object_wrap/nan/binding.gyp b/src/1-getting-started/6_object_wrap/nan/binding.gyp similarity index 100% rename from 6_object_wrap/nan/binding.gyp rename to src/1-getting-started/6_object_wrap/nan/binding.gyp diff --git a/6_object_wrap/nan/myobject.cc b/src/1-getting-started/6_object_wrap/nan/myobject.cc similarity index 100% rename from 6_object_wrap/nan/myobject.cc rename to src/1-getting-started/6_object_wrap/nan/myobject.cc diff --git a/6_object_wrap/nan/myobject.h b/src/1-getting-started/6_object_wrap/nan/myobject.h similarity index 100% rename from 6_object_wrap/nan/myobject.h rename to src/1-getting-started/6_object_wrap/nan/myobject.h diff --git a/6_object_wrap/nan/package.json b/src/1-getting-started/6_object_wrap/nan/package.json similarity index 100% rename from 6_object_wrap/nan/package.json rename to src/1-getting-started/6_object_wrap/nan/package.json diff --git a/6_object_wrap/napi/addon.cc b/src/1-getting-started/6_object_wrap/napi/addon.cc similarity index 100% rename from 6_object_wrap/napi/addon.cc rename to src/1-getting-started/6_object_wrap/napi/addon.cc diff --git a/6_object_wrap/napi/addon.js b/src/1-getting-started/6_object_wrap/napi/addon.js similarity index 100% rename from 6_object_wrap/napi/addon.js rename to src/1-getting-started/6_object_wrap/napi/addon.js diff --git a/6_object_wrap/napi/binding.gyp b/src/1-getting-started/6_object_wrap/napi/binding.gyp similarity index 100% rename from 6_object_wrap/napi/binding.gyp rename to src/1-getting-started/6_object_wrap/napi/binding.gyp diff --git a/6_object_wrap/napi/myobject.cc b/src/1-getting-started/6_object_wrap/napi/myobject.cc similarity index 100% rename from 6_object_wrap/napi/myobject.cc rename to src/1-getting-started/6_object_wrap/napi/myobject.cc diff --git a/6_object_wrap/napi/myobject.h b/src/1-getting-started/6_object_wrap/napi/myobject.h similarity index 100% rename from 6_object_wrap/napi/myobject.h rename to src/1-getting-started/6_object_wrap/napi/myobject.h diff --git a/6_object_wrap/napi/package.json b/src/1-getting-started/6_object_wrap/napi/package.json similarity index 100% rename from 6_object_wrap/napi/package.json rename to src/1-getting-started/6_object_wrap/napi/package.json diff --git a/6_object_wrap/node-addon-api/addon.cc b/src/1-getting-started/6_object_wrap/node-addon-api/addon.cc similarity index 100% rename from 6_object_wrap/node-addon-api/addon.cc rename to src/1-getting-started/6_object_wrap/node-addon-api/addon.cc diff --git a/6_object_wrap/node-addon-api/addon.js b/src/1-getting-started/6_object_wrap/node-addon-api/addon.js similarity index 100% rename from 6_object_wrap/node-addon-api/addon.js rename to src/1-getting-started/6_object_wrap/node-addon-api/addon.js diff --git a/6_object_wrap/node-addon-api/binding.gyp b/src/1-getting-started/6_object_wrap/node-addon-api/binding.gyp similarity index 100% rename from 6_object_wrap/node-addon-api/binding.gyp rename to src/1-getting-started/6_object_wrap/node-addon-api/binding.gyp diff --git a/6_object_wrap/node-addon-api/myobject.cc b/src/1-getting-started/6_object_wrap/node-addon-api/myobject.cc similarity index 100% rename from 6_object_wrap/node-addon-api/myobject.cc rename to src/1-getting-started/6_object_wrap/node-addon-api/myobject.cc diff --git a/6_object_wrap/node-addon-api/myobject.h b/src/1-getting-started/6_object_wrap/node-addon-api/myobject.h similarity index 100% rename from 6_object_wrap/node-addon-api/myobject.h rename to src/1-getting-started/6_object_wrap/node-addon-api/myobject.h diff --git a/6_object_wrap/node-addon-api/package.json b/src/1-getting-started/6_object_wrap/node-addon-api/package.json similarity index 100% rename from 6_object_wrap/node-addon-api/package.json rename to src/1-getting-started/6_object_wrap/node-addon-api/package.json diff --git a/7_factory_wrap/nan/addon.cc b/src/1-getting-started/7_factory_wrap/nan/addon.cc similarity index 100% rename from 7_factory_wrap/nan/addon.cc rename to src/1-getting-started/7_factory_wrap/nan/addon.cc diff --git a/7_factory_wrap/nan/addon.js b/src/1-getting-started/7_factory_wrap/nan/addon.js similarity index 100% rename from 7_factory_wrap/nan/addon.js rename to src/1-getting-started/7_factory_wrap/nan/addon.js diff --git a/7_factory_wrap/nan/binding.gyp b/src/1-getting-started/7_factory_wrap/nan/binding.gyp similarity index 100% rename from 7_factory_wrap/nan/binding.gyp rename to src/1-getting-started/7_factory_wrap/nan/binding.gyp diff --git a/7_factory_wrap/nan/myobject.cc b/src/1-getting-started/7_factory_wrap/nan/myobject.cc similarity index 100% rename from 7_factory_wrap/nan/myobject.cc rename to src/1-getting-started/7_factory_wrap/nan/myobject.cc diff --git a/7_factory_wrap/nan/myobject.h b/src/1-getting-started/7_factory_wrap/nan/myobject.h similarity index 100% rename from 7_factory_wrap/nan/myobject.h rename to src/1-getting-started/7_factory_wrap/nan/myobject.h diff --git a/7_factory_wrap/nan/package.json b/src/1-getting-started/7_factory_wrap/nan/package.json similarity index 100% rename from 7_factory_wrap/nan/package.json rename to src/1-getting-started/7_factory_wrap/nan/package.json diff --git a/7_factory_wrap/napi/addon.cc b/src/1-getting-started/7_factory_wrap/napi/addon.cc similarity index 100% rename from 7_factory_wrap/napi/addon.cc rename to src/1-getting-started/7_factory_wrap/napi/addon.cc diff --git a/7_factory_wrap/napi/addon.js b/src/1-getting-started/7_factory_wrap/napi/addon.js similarity index 100% rename from 7_factory_wrap/napi/addon.js rename to src/1-getting-started/7_factory_wrap/napi/addon.js diff --git a/7_factory_wrap/napi/binding.gyp b/src/1-getting-started/7_factory_wrap/napi/binding.gyp similarity index 100% rename from 7_factory_wrap/napi/binding.gyp rename to src/1-getting-started/7_factory_wrap/napi/binding.gyp diff --git a/7_factory_wrap/napi/myobject.cc b/src/1-getting-started/7_factory_wrap/napi/myobject.cc similarity index 100% rename from 7_factory_wrap/napi/myobject.cc rename to src/1-getting-started/7_factory_wrap/napi/myobject.cc diff --git a/7_factory_wrap/napi/myobject.h b/src/1-getting-started/7_factory_wrap/napi/myobject.h similarity index 100% rename from 7_factory_wrap/napi/myobject.h rename to src/1-getting-started/7_factory_wrap/napi/myobject.h diff --git a/7_factory_wrap/napi/package.json b/src/1-getting-started/7_factory_wrap/napi/package.json similarity index 100% rename from 7_factory_wrap/napi/package.json rename to src/1-getting-started/7_factory_wrap/napi/package.json diff --git a/7_factory_wrap/node-addon-api/addon.cc b/src/1-getting-started/7_factory_wrap/node-addon-api/addon.cc similarity index 100% rename from 7_factory_wrap/node-addon-api/addon.cc rename to src/1-getting-started/7_factory_wrap/node-addon-api/addon.cc diff --git a/7_factory_wrap/node-addon-api/addon.js b/src/1-getting-started/7_factory_wrap/node-addon-api/addon.js similarity index 100% rename from 7_factory_wrap/node-addon-api/addon.js rename to src/1-getting-started/7_factory_wrap/node-addon-api/addon.js diff --git a/7_factory_wrap/node-addon-api/binding.gyp b/src/1-getting-started/7_factory_wrap/node-addon-api/binding.gyp similarity index 100% rename from 7_factory_wrap/node-addon-api/binding.gyp rename to src/1-getting-started/7_factory_wrap/node-addon-api/binding.gyp diff --git a/7_factory_wrap/node-addon-api/myobject.cc b/src/1-getting-started/7_factory_wrap/node-addon-api/myobject.cc similarity index 100% rename from 7_factory_wrap/node-addon-api/myobject.cc rename to src/1-getting-started/7_factory_wrap/node-addon-api/myobject.cc diff --git a/7_factory_wrap/node-addon-api/myobject.h b/src/1-getting-started/7_factory_wrap/node-addon-api/myobject.h similarity index 100% rename from 7_factory_wrap/node-addon-api/myobject.h rename to src/1-getting-started/7_factory_wrap/node-addon-api/myobject.h diff --git a/7_factory_wrap/node-addon-api/package.json b/src/1-getting-started/7_factory_wrap/node-addon-api/package.json similarity index 100% rename from 7_factory_wrap/node-addon-api/package.json rename to src/1-getting-started/7_factory_wrap/node-addon-api/package.json diff --git a/a-first-project/node-addon-api/README.md b/src/1-getting-started/a-first-project/node-addon-api/README.md similarity index 100% rename from a-first-project/node-addon-api/README.md rename to src/1-getting-started/a-first-project/node-addon-api/README.md diff --git a/a-first-project/node-addon-api/binding.gyp b/src/1-getting-started/a-first-project/node-addon-api/binding.gyp similarity index 100% rename from a-first-project/node-addon-api/binding.gyp rename to src/1-getting-started/a-first-project/node-addon-api/binding.gyp diff --git a/a-first-project/node-addon-api/lib/binding.js b/src/1-getting-started/a-first-project/node-addon-api/lib/binding.js similarity index 100% rename from a-first-project/node-addon-api/lib/binding.js rename to src/1-getting-started/a-first-project/node-addon-api/lib/binding.js diff --git a/a-first-project/node-addon-api/package.json b/src/1-getting-started/a-first-project/node-addon-api/package.json similarity index 100% rename from a-first-project/node-addon-api/package.json rename to src/1-getting-started/a-first-project/node-addon-api/package.json diff --git a/a-first-project/node-addon-api/src/hello_world.cc b/src/1-getting-started/a-first-project/node-addon-api/src/hello_world.cc similarity index 100% rename from a-first-project/node-addon-api/src/hello_world.cc rename to src/1-getting-started/a-first-project/node-addon-api/src/hello_world.cc diff --git a/a-first-project/node-addon-api/test/test_binding.js b/src/1-getting-started/a-first-project/node-addon-api/test/test_binding.js similarity index 100% rename from a-first-project/node-addon-api/test/test_binding.js rename to src/1-getting-started/a-first-project/node-addon-api/test/test_binding.js diff --git a/8_passing_wrapped/nan/addon.cc b/src/2-js-to-native-conversion/8_passing_wrapped/nan/addon.cc similarity index 100% rename from 8_passing_wrapped/nan/addon.cc rename to src/2-js-to-native-conversion/8_passing_wrapped/nan/addon.cc diff --git a/8_passing_wrapped/nan/addon.js b/src/2-js-to-native-conversion/8_passing_wrapped/nan/addon.js similarity index 100% rename from 8_passing_wrapped/nan/addon.js rename to src/2-js-to-native-conversion/8_passing_wrapped/nan/addon.js diff --git a/8_passing_wrapped/nan/binding.gyp b/src/2-js-to-native-conversion/8_passing_wrapped/nan/binding.gyp similarity index 100% rename from 8_passing_wrapped/nan/binding.gyp rename to src/2-js-to-native-conversion/8_passing_wrapped/nan/binding.gyp diff --git a/8_passing_wrapped/nan/myobject.cc b/src/2-js-to-native-conversion/8_passing_wrapped/nan/myobject.cc similarity index 100% rename from 8_passing_wrapped/nan/myobject.cc rename to src/2-js-to-native-conversion/8_passing_wrapped/nan/myobject.cc diff --git a/8_passing_wrapped/nan/myobject.h b/src/2-js-to-native-conversion/8_passing_wrapped/nan/myobject.h similarity index 100% rename from 8_passing_wrapped/nan/myobject.h rename to src/2-js-to-native-conversion/8_passing_wrapped/nan/myobject.h diff --git a/8_passing_wrapped/nan/package.json b/src/2-js-to-native-conversion/8_passing_wrapped/nan/package.json similarity index 100% rename from 8_passing_wrapped/nan/package.json rename to src/2-js-to-native-conversion/8_passing_wrapped/nan/package.json diff --git a/8_passing_wrapped/napi/addon.cc b/src/2-js-to-native-conversion/8_passing_wrapped/napi/addon.cc similarity index 100% rename from 8_passing_wrapped/napi/addon.cc rename to src/2-js-to-native-conversion/8_passing_wrapped/napi/addon.cc diff --git a/8_passing_wrapped/napi/addon.js b/src/2-js-to-native-conversion/8_passing_wrapped/napi/addon.js similarity index 100% rename from 8_passing_wrapped/napi/addon.js rename to src/2-js-to-native-conversion/8_passing_wrapped/napi/addon.js diff --git a/8_passing_wrapped/napi/binding.gyp b/src/2-js-to-native-conversion/8_passing_wrapped/napi/binding.gyp similarity index 100% rename from 8_passing_wrapped/napi/binding.gyp rename to src/2-js-to-native-conversion/8_passing_wrapped/napi/binding.gyp diff --git a/8_passing_wrapped/napi/myobject.cc b/src/2-js-to-native-conversion/8_passing_wrapped/napi/myobject.cc similarity index 100% rename from 8_passing_wrapped/napi/myobject.cc rename to src/2-js-to-native-conversion/8_passing_wrapped/napi/myobject.cc diff --git a/8_passing_wrapped/napi/myobject.h b/src/2-js-to-native-conversion/8_passing_wrapped/napi/myobject.h similarity index 100% rename from 8_passing_wrapped/napi/myobject.h rename to src/2-js-to-native-conversion/8_passing_wrapped/napi/myobject.h diff --git a/8_passing_wrapped/napi/package.json b/src/2-js-to-native-conversion/8_passing_wrapped/napi/package.json similarity index 100% rename from 8_passing_wrapped/napi/package.json rename to src/2-js-to-native-conversion/8_passing_wrapped/napi/package.json diff --git a/8_passing_wrapped/node-addon-api/addon.cc b/src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/addon.cc similarity index 100% rename from 8_passing_wrapped/node-addon-api/addon.cc rename to src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/addon.cc diff --git a/8_passing_wrapped/node-addon-api/addon.js b/src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/addon.js similarity index 100% rename from 8_passing_wrapped/node-addon-api/addon.js rename to src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/addon.js diff --git a/8_passing_wrapped/node-addon-api/binding.gyp b/src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/binding.gyp similarity index 100% rename from 8_passing_wrapped/node-addon-api/binding.gyp rename to src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/binding.gyp diff --git a/8_passing_wrapped/node-addon-api/myobject.cc b/src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/myobject.cc similarity index 73% rename from 8_passing_wrapped/node-addon-api/myobject.cc rename to src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/myobject.cc index 02254e13..7083269c 100644 --- a/8_passing_wrapped/node-addon-api/myobject.cc +++ b/src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/myobject.cc @@ -12,8 +12,9 @@ void MyObject::Init(Napi::Env env, Napi::Object exports) { Napi::FunctionReference* constructor = new Napi::FunctionReference(); *constructor = Napi::Persistent(func); - env.SetInstanceData(constructor); //NOTE: this assumes only 1 class is exported - //for multiple exported classes, need a struct or other mechanism + env.SetInstanceData(constructor); // NOTE: this assumes only 1 class is + // exported for multiple exported classes, + // need a struct or other mechanism exports.Set("MyObject", func); } diff --git a/8_passing_wrapped/node-addon-api/myobject.h b/src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/myobject.h similarity index 100% rename from 8_passing_wrapped/node-addon-api/myobject.h rename to src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/myobject.h diff --git a/8_passing_wrapped/node-addon-api/package.json b/src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/package.json similarity index 100% rename from 8_passing_wrapped/node-addon-api/package.json rename to src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api/package.json diff --git a/array_buffer_to_native/node-addon-api/array_buffer_to_native.cc b/src/2-js-to-native-conversion/array_buffer_to_native/node-addon-api/array_buffer_to_native.cc similarity index 100% rename from array_buffer_to_native/node-addon-api/array_buffer_to_native.cc rename to src/2-js-to-native-conversion/array_buffer_to_native/node-addon-api/array_buffer_to_native.cc diff --git a/array_buffer_to_native/node-addon-api/binding.gyp b/src/2-js-to-native-conversion/array_buffer_to_native/node-addon-api/binding.gyp similarity index 100% rename from array_buffer_to_native/node-addon-api/binding.gyp rename to src/2-js-to-native-conversion/array_buffer_to_native/node-addon-api/binding.gyp diff --git a/array_buffer_to_native/node-addon-api/index.js b/src/2-js-to-native-conversion/array_buffer_to_native/node-addon-api/index.js similarity index 100% rename from array_buffer_to_native/node-addon-api/index.js rename to src/2-js-to-native-conversion/array_buffer_to_native/node-addon-api/index.js diff --git a/array_buffer_to_native/node-addon-api/package.json b/src/2-js-to-native-conversion/array_buffer_to_native/node-addon-api/package.json similarity index 100% rename from array_buffer_to_native/node-addon-api/package.json rename to src/2-js-to-native-conversion/array_buffer_to_native/node-addon-api/package.json diff --git a/object-template-demo/README.md b/src/2-js-to-native-conversion/object-template-demo/README.md similarity index 100% rename from object-template-demo/README.md rename to src/2-js-to-native-conversion/object-template-demo/README.md diff --git a/object-template-demo/nan/binding.gyp b/src/2-js-to-native-conversion/object-template-demo/nan/binding.gyp similarity index 100% rename from object-template-demo/nan/binding.gyp rename to src/2-js-to-native-conversion/object-template-demo/nan/binding.gyp diff --git a/object-template-demo/nan/index.js b/src/2-js-to-native-conversion/object-template-demo/nan/index.js similarity index 100% rename from object-template-demo/nan/index.js rename to src/2-js-to-native-conversion/object-template-demo/nan/index.js diff --git a/object-template-demo/nan/object-template-demo.cc b/src/2-js-to-native-conversion/object-template-demo/nan/object-template-demo.cc similarity index 73% rename from object-template-demo/nan/object-template-demo.cc rename to src/2-js-to-native-conversion/object-template-demo/nan/object-template-demo.cc index 8ab5f47d..d8ee11b2 100644 --- a/object-template-demo/nan/object-template-demo.cc +++ b/src/2-js-to-native-conversion/object-template-demo/nan/object-template-demo.cc @@ -15,9 +15,9 @@ class NamedInterceptor : public ObjectWrap { char buf[256]; public: - NamedInterceptor() { std::strncpy(this->buf, "foo", sizeof (this->buf)); } + NamedInterceptor() { std::strncpy(this->buf, "foo", sizeof(this->buf)); } static NAN_MODULE_INIT(Init); - static v8::Local NewInstance (); + static v8::Local NewInstance(); static NAN_METHOD(New); static NAN_PROPERTY_GETTER(PropertyGetter); @@ -35,33 +35,32 @@ NAN_METHOD(CreateNew) { NAN_MODULE_INIT(NamedInterceptor::Init) { v8::Local tpl = - Nan::New(NamedInterceptor::New); + Nan::New(NamedInterceptor::New); namedinterceptors_constructor.Reset(tpl); tpl->SetClassName(Nan::New("NamedInterceptor").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); v8::Local inst = tpl->InstanceTemplate(); - SetNamedPropertyHandler( - inst - , NamedInterceptor::PropertyGetter - , NamedInterceptor::PropertySetter - , NamedInterceptor::PropertyQuery - , NamedInterceptor::PropertyDeleter - , NamedInterceptor::PropertyEnumerator); + SetNamedPropertyHandler(inst, + NamedInterceptor::PropertyGetter, + NamedInterceptor::PropertySetter, + NamedInterceptor::PropertyQuery, + NamedInterceptor::PropertyDeleter, + NamedInterceptor::PropertyEnumerator); v8::Local createnew = - Nan::GetFunction(Nan::New(CreateNew)) - .ToLocalChecked(); + Nan::GetFunction(Nan::New(CreateNew)) + .ToLocalChecked(); Set(target, Nan::New("create").ToLocalChecked(), createnew); } -v8::Local NamedInterceptor::NewInstance () { +v8::Local NamedInterceptor::NewInstance() { EscapableHandleScope scope; v8::Local constructorHandle = Nan::New(namedinterceptors_constructor); v8::Local instance = - Nan::NewInstance(GetFunction(constructorHandle).ToLocalChecked()) - .ToLocalChecked(); + Nan::NewInstance(GetFunction(constructorHandle).ToLocalChecked()) + .ToLocalChecked(); return scope.Escape(instance); } @@ -71,10 +70,9 @@ NAN_METHOD(NamedInterceptor::New) { info.GetReturnValue().Set(info.This()); } - NAN_PROPERTY_GETTER(NamedInterceptor::PropertyGetter) { NamedInterceptor* interceptor = - ObjectWrap::Unwrap(info.Holder()); + ObjectWrap::Unwrap(info.Holder()); if (!std::strcmp(*Nan::Utf8String(property), "prop")) { info.GetReturnValue().Set(Nan::New(interceptor->buf).ToLocalChecked()); } else { @@ -84,12 +82,10 @@ NAN_PROPERTY_GETTER(NamedInterceptor::PropertyGetter) { NAN_PROPERTY_SETTER(NamedInterceptor::PropertySetter) { NamedInterceptor* interceptor = - ObjectWrap::Unwrap(info.Holder()); + ObjectWrap::Unwrap(info.Holder()); if (!std::strcmp(*Nan::Utf8String(property), "prop")) { std::strncpy( - interceptor->buf - , *Nan::Utf8String(value) - , sizeof (interceptor->buf)); + interceptor->buf, *Nan::Utf8String(value), sizeof(interceptor->buf)); info.GetReturnValue().Set(info.This()); } else { info.GetReturnValue().Set(info.This()); @@ -104,8 +100,8 @@ NAN_PROPERTY_ENUMERATOR(NamedInterceptor::PropertyEnumerator) { NAN_PROPERTY_DELETER(NamedInterceptor::PropertyDeleter) { NamedInterceptor* interceptor = - ObjectWrap::Unwrap(info.Holder()); - std::strncpy(interceptor->buf, "goober", sizeof (interceptor->buf)); + ObjectWrap::Unwrap(info.Holder()); + std::strncpy(interceptor->buf, "goober", sizeof(interceptor->buf)); info.GetReturnValue().Set(True()); } diff --git a/object-template-demo/nan/package.json b/src/2-js-to-native-conversion/object-template-demo/nan/package.json similarity index 100% rename from object-template-demo/nan/package.json rename to src/2-js-to-native-conversion/object-template-demo/nan/package.json diff --git a/object-template-demo/napi/binding.gyp b/src/2-js-to-native-conversion/object-template-demo/napi/binding.gyp similarity index 100% rename from object-template-demo/napi/binding.gyp rename to src/2-js-to-native-conversion/object-template-demo/napi/binding.gyp diff --git a/object-template-demo/napi/index.js b/src/2-js-to-native-conversion/object-template-demo/napi/index.js similarity index 100% rename from object-template-demo/napi/index.js rename to src/2-js-to-native-conversion/object-template-demo/napi/index.js diff --git a/object-template-demo/napi/node-api-common.h b/src/2-js-to-native-conversion/object-template-demo/napi/node-api-common.h similarity index 100% rename from object-template-demo/napi/node-api-common.h rename to src/2-js-to-native-conversion/object-template-demo/napi/node-api-common.h diff --git a/object-template-demo/napi/object-template-demo.cc b/src/2-js-to-native-conversion/object-template-demo/napi/object-template-demo.cc similarity index 100% rename from object-template-demo/napi/object-template-demo.cc rename to src/2-js-to-native-conversion/object-template-demo/napi/object-template-demo.cc index 6846e1fc..5b049202 100644 --- a/object-template-demo/napi/object-template-demo.cc +++ b/src/2-js-to-native-conversion/object-template-demo/napi/object-template-demo.cc @@ -1,5 +1,5 @@ -#include #include +#include #include #include "proxy-template.h" diff --git a/object-template-demo/napi/package.json b/src/2-js-to-native-conversion/object-template-demo/napi/package.json similarity index 100% rename from object-template-demo/napi/package.json rename to src/2-js-to-native-conversion/object-template-demo/napi/package.json diff --git a/object-template-demo/napi/proxy-template.cc b/src/2-js-to-native-conversion/object-template-demo/napi/proxy-template.cc similarity index 100% rename from object-template-demo/napi/proxy-template.cc rename to src/2-js-to-native-conversion/object-template-demo/napi/proxy-template.cc diff --git a/object-template-demo/napi/proxy-template.h b/src/2-js-to-native-conversion/object-template-demo/napi/proxy-template.h similarity index 100% rename from object-template-demo/napi/proxy-template.h rename to src/2-js-to-native-conversion/object-template-demo/napi/proxy-template.h diff --git a/object-wrap-demo/node-addon-api/README.md b/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/README.md similarity index 100% rename from object-wrap-demo/node-addon-api/README.md rename to src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/README.md diff --git a/object-wrap-demo/node-addon-api/binding.gyp b/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/binding.gyp similarity index 100% rename from object-wrap-demo/node-addon-api/binding.gyp rename to src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/binding.gyp diff --git a/object-wrap-demo/node-addon-api/lib/binding.js b/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/lib/binding.js similarity index 100% rename from object-wrap-demo/node-addon-api/lib/binding.js rename to src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/lib/binding.js diff --git a/object-wrap-demo/node-addon-api/package.json b/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/package.json similarity index 100% rename from object-wrap-demo/node-addon-api/package.json rename to src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/package.json diff --git a/object-wrap-demo/node-addon-api/src/object_wrap_demo.cc b/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/src/object_wrap_demo.cc similarity index 100% rename from object-wrap-demo/node-addon-api/src/object_wrap_demo.cc rename to src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/src/object_wrap_demo.cc diff --git a/object-wrap-demo/node-addon-api/src/object_wrap_demo.h b/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/src/object_wrap_demo.h similarity index 100% rename from object-wrap-demo/node-addon-api/src/object_wrap_demo.h rename to src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/src/object_wrap_demo.h diff --git a/object-wrap-demo/node-addon-api/test/test_binding.js b/src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/test/test_binding.js similarity index 100% rename from object-wrap-demo/node-addon-api/test/test_binding.js rename to src/2-js-to-native-conversion/object-wrap-demo/node-addon-api/test/test_binding.js diff --git a/typed_array_to_native/node-addon-api/binding.gyp b/src/2-js-to-native-conversion/typed_array_to_native/node-addon-api/binding.gyp similarity index 100% rename from typed_array_to_native/node-addon-api/binding.gyp rename to src/2-js-to-native-conversion/typed_array_to_native/node-addon-api/binding.gyp diff --git a/typed_array_to_native/node-addon-api/index.js b/src/2-js-to-native-conversion/typed_array_to_native/node-addon-api/index.js similarity index 100% rename from typed_array_to_native/node-addon-api/index.js rename to src/2-js-to-native-conversion/typed_array_to_native/node-addon-api/index.js diff --git a/typed_array_to_native/node-addon-api/package.json b/src/2-js-to-native-conversion/typed_array_to_native/node-addon-api/package.json similarity index 100% rename from typed_array_to_native/node-addon-api/package.json rename to src/2-js-to-native-conversion/typed_array_to_native/node-addon-api/package.json diff --git a/typed_array_to_native/node-addon-api/typed_array_to_native.cc b/src/2-js-to-native-conversion/typed_array_to_native/node-addon-api/typed_array_to_native.cc similarity index 97% rename from typed_array_to_native/node-addon-api/typed_array_to_native.cc rename to src/2-js-to-native-conversion/typed_array_to_native/node-addon-api/typed_array_to_native.cc index d46cbf47..f82b5776 100644 --- a/typed_array_to_native/node-addon-api/typed_array_to_native.cc +++ b/src/2-js-to-native-conversion/typed_array_to_native/node-addon-api/typed_array_to_native.cc @@ -94,8 +94,9 @@ static Napi::Value CreateByteArray(const Napi::CallbackInfo& info) { // unique_ptr ownership. nativeArray.release(); - Napi::Uint8Array byteArray = Napi::Uint8Array::New(info.Env(), arrayLength, arrayBuffer, 0); - + Napi::Uint8Array byteArray = + Napi::Uint8Array::New(info.Env(), arrayLength, arrayBuffer, 0); + return byteArray; } diff --git a/multiple_load/napi/binding.gyp b/src/3-context-awareness/napi/binding.gyp similarity index 100% rename from multiple_load/napi/binding.gyp rename to src/3-context-awareness/napi/binding.gyp diff --git a/multiple_load/napi/index.js b/src/3-context-awareness/napi/index.js similarity index 100% rename from multiple_load/napi/index.js rename to src/3-context-awareness/napi/index.js diff --git a/multiple_load/napi/multiple_load.c b/src/3-context-awareness/napi/multiple_load.c similarity index 100% rename from multiple_load/napi/multiple_load.c rename to src/3-context-awareness/napi/multiple_load.c diff --git a/multiple_load/napi/package.json b/src/3-context-awareness/napi/package.json similarity index 100% rename from multiple_load/napi/package.json rename to src/3-context-awareness/napi/package.json diff --git a/multiple_load/node_10/binding.gyp b/src/3-context-awareness/node_10/binding.gyp similarity index 100% rename from multiple_load/node_10/binding.gyp rename to src/3-context-awareness/node_10/binding.gyp diff --git a/multiple_load/node_10/index.js b/src/3-context-awareness/node_10/index.js similarity index 100% rename from multiple_load/node_10/index.js rename to src/3-context-awareness/node_10/index.js diff --git a/multiple_load/node_10/multiple_load.cc b/src/3-context-awareness/node_10/multiple_load.cc similarity index 100% rename from multiple_load/node_10/multiple_load.cc rename to src/3-context-awareness/node_10/multiple_load.cc diff --git a/multiple_load/node_10/package.json b/src/3-context-awareness/node_10/package.json similarity index 100% rename from multiple_load/node_10/package.json rename to src/3-context-awareness/node_10/package.json diff --git a/function-reference-demo/node-addon-api/binding.gyp b/src/4-references-and-handle-scope/function-reference-demo/node-addon-api/binding.gyp similarity index 100% rename from function-reference-demo/node-addon-api/binding.gyp rename to src/4-references-and-handle-scope/function-reference-demo/node-addon-api/binding.gyp diff --git a/function-reference-demo/node-addon-api/index.js b/src/4-references-and-handle-scope/function-reference-demo/node-addon-api/index.js similarity index 100% rename from function-reference-demo/node-addon-api/index.js rename to src/4-references-and-handle-scope/function-reference-demo/node-addon-api/index.js diff --git a/function-reference-demo/node-addon-api/package.json b/src/4-references-and-handle-scope/function-reference-demo/node-addon-api/package.json similarity index 100% rename from function-reference-demo/node-addon-api/package.json rename to src/4-references-and-handle-scope/function-reference-demo/node-addon-api/package.json diff --git a/function-reference-demo/node-addon-api/src/binding.cc b/src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/binding.cc similarity index 100% rename from function-reference-demo/node-addon-api/src/binding.cc rename to src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/binding.cc diff --git a/function-reference-demo/node-addon-api/src/native-addon.cc b/src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/native-addon.cc similarity index 100% rename from function-reference-demo/node-addon-api/src/native-addon.cc rename to src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/native-addon.cc diff --git a/function-reference-demo/node-addon-api/src/native-addon.h b/src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/native-addon.h similarity index 100% rename from function-reference-demo/node-addon-api/src/native-addon.h rename to src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/native-addon.h diff --git a/async-iterator/node-addon-api/CMakeLists.txt b/src/5-async-work/async-iterator/node-addon-api/CMakeLists.txt similarity index 100% rename from async-iterator/node-addon-api/CMakeLists.txt rename to src/5-async-work/async-iterator/node-addon-api/CMakeLists.txt diff --git a/async-iterator/node-addon-api/example.cc b/src/5-async-work/async-iterator/node-addon-api/example.cc similarity index 100% rename from async-iterator/node-addon-api/example.cc rename to src/5-async-work/async-iterator/node-addon-api/example.cc diff --git a/async-iterator/node-addon-api/index.js b/src/5-async-work/async-iterator/node-addon-api/index.js similarity index 100% rename from async-iterator/node-addon-api/index.js rename to src/5-async-work/async-iterator/node-addon-api/index.js diff --git a/async-iterator/node-addon-api/package.json b/src/5-async-work/async-iterator/node-addon-api/package.json similarity index 100% rename from async-iterator/node-addon-api/package.json rename to src/5-async-work/async-iterator/node-addon-api/package.json diff --git a/async_pi_estimate/nan/README.md b/src/5-async-work/async_pi_estimate/nan/README.md similarity index 100% rename from async_pi_estimate/nan/README.md rename to src/5-async-work/async_pi_estimate/nan/README.md diff --git a/async_pi_estimate/nan/addon.cc b/src/5-async-work/async_pi_estimate/nan/addon.cc similarity index 100% rename from async_pi_estimate/nan/addon.cc rename to src/5-async-work/async_pi_estimate/nan/addon.cc diff --git a/async_pi_estimate/nan/addon.js b/src/5-async-work/async_pi_estimate/nan/addon.js similarity index 100% rename from async_pi_estimate/nan/addon.js rename to src/5-async-work/async_pi_estimate/nan/addon.js diff --git a/async_pi_estimate/nan/async.cc b/src/5-async-work/async_pi_estimate/nan/async.cc similarity index 100% rename from async_pi_estimate/nan/async.cc rename to src/5-async-work/async_pi_estimate/nan/async.cc diff --git a/async_pi_estimate/nan/async.h b/src/5-async-work/async_pi_estimate/nan/async.h similarity index 100% rename from async_pi_estimate/nan/async.h rename to src/5-async-work/async_pi_estimate/nan/async.h diff --git a/async_pi_estimate/nan/binding.gyp b/src/5-async-work/async_pi_estimate/nan/binding.gyp similarity index 100% rename from async_pi_estimate/nan/binding.gyp rename to src/5-async-work/async_pi_estimate/nan/binding.gyp diff --git a/async_pi_estimate/nan/package.json b/src/5-async-work/async_pi_estimate/nan/package.json similarity index 100% rename from async_pi_estimate/nan/package.json rename to src/5-async-work/async_pi_estimate/nan/package.json diff --git a/async_pi_estimate/nan/pi_est.cc b/src/5-async-work/async_pi_estimate/nan/pi_est.cc similarity index 100% rename from async_pi_estimate/nan/pi_est.cc rename to src/5-async-work/async_pi_estimate/nan/pi_est.cc diff --git a/async_pi_estimate/nan/pi_est.h b/src/5-async-work/async_pi_estimate/nan/pi_est.h similarity index 100% rename from async_pi_estimate/nan/pi_est.h rename to src/5-async-work/async_pi_estimate/nan/pi_est.h diff --git a/async_pi_estimate/nan/sync.cc b/src/5-async-work/async_pi_estimate/nan/sync.cc similarity index 100% rename from async_pi_estimate/nan/sync.cc rename to src/5-async-work/async_pi_estimate/nan/sync.cc diff --git a/async_pi_estimate/nan/sync.h b/src/5-async-work/async_pi_estimate/nan/sync.h similarity index 100% rename from async_pi_estimate/nan/sync.h rename to src/5-async-work/async_pi_estimate/nan/sync.h diff --git a/async_pi_estimate/node-addon-api/README.md b/src/5-async-work/async_pi_estimate/node-addon-api/README.md similarity index 100% rename from async_pi_estimate/node-addon-api/README.md rename to src/5-async-work/async_pi_estimate/node-addon-api/README.md diff --git a/async_pi_estimate/node-addon-api/addon.cc b/src/5-async-work/async_pi_estimate/node-addon-api/addon.cc similarity index 100% rename from async_pi_estimate/node-addon-api/addon.cc rename to src/5-async-work/async_pi_estimate/node-addon-api/addon.cc diff --git a/async_pi_estimate/node-addon-api/addon.js b/src/5-async-work/async_pi_estimate/node-addon-api/addon.js similarity index 100% rename from async_pi_estimate/node-addon-api/addon.js rename to src/5-async-work/async_pi_estimate/node-addon-api/addon.js diff --git a/async_pi_estimate/node-addon-api/async.cc b/src/5-async-work/async_pi_estimate/node-addon-api/async.cc similarity index 100% rename from async_pi_estimate/node-addon-api/async.cc rename to src/5-async-work/async_pi_estimate/node-addon-api/async.cc diff --git a/async_pi_estimate/node-addon-api/async.h b/src/5-async-work/async_pi_estimate/node-addon-api/async.h similarity index 100% rename from async_pi_estimate/node-addon-api/async.h rename to src/5-async-work/async_pi_estimate/node-addon-api/async.h diff --git a/async_pi_estimate/node-addon-api/binding.gyp b/src/5-async-work/async_pi_estimate/node-addon-api/binding.gyp similarity index 100% rename from async_pi_estimate/node-addon-api/binding.gyp rename to src/5-async-work/async_pi_estimate/node-addon-api/binding.gyp diff --git a/async_pi_estimate/node-addon-api/package.json b/src/5-async-work/async_pi_estimate/node-addon-api/package.json similarity index 100% rename from async_pi_estimate/node-addon-api/package.json rename to src/5-async-work/async_pi_estimate/node-addon-api/package.json diff --git a/async_pi_estimate/node-addon-api/pi_est.cc b/src/5-async-work/async_pi_estimate/node-addon-api/pi_est.cc similarity index 100% rename from async_pi_estimate/node-addon-api/pi_est.cc rename to src/5-async-work/async_pi_estimate/node-addon-api/pi_est.cc diff --git a/async_pi_estimate/node-addon-api/pi_est.h b/src/5-async-work/async_pi_estimate/node-addon-api/pi_est.h similarity index 100% rename from async_pi_estimate/node-addon-api/pi_est.h rename to src/5-async-work/async_pi_estimate/node-addon-api/pi_est.h diff --git a/async_pi_estimate/node-addon-api/sync.cc b/src/5-async-work/async_pi_estimate/node-addon-api/sync.cc similarity index 100% rename from async_pi_estimate/node-addon-api/sync.cc rename to src/5-async-work/async_pi_estimate/node-addon-api/sync.cc diff --git a/async_pi_estimate/node-addon-api/sync.h b/src/5-async-work/async_pi_estimate/node-addon-api/sync.h similarity index 100% rename from async_pi_estimate/node-addon-api/sync.h rename to src/5-async-work/async_pi_estimate/node-addon-api/sync.h diff --git a/async_work_promise/napi/binding.c b/src/5-async-work/async_work_promise/napi/binding.c similarity index 100% rename from async_work_promise/napi/binding.c rename to src/5-async-work/async_work_promise/napi/binding.c diff --git a/async_work_promise/napi/binding.gyp b/src/5-async-work/async_work_promise/napi/binding.gyp similarity index 100% rename from async_work_promise/napi/binding.gyp rename to src/5-async-work/async_work_promise/napi/binding.gyp diff --git a/async_work_promise/napi/index.js b/src/5-async-work/async_work_promise/napi/index.js similarity index 100% rename from async_work_promise/napi/index.js rename to src/5-async-work/async_work_promise/napi/index.js diff --git a/async_work_promise/napi/package.json b/src/5-async-work/async_work_promise/napi/package.json similarity index 100% rename from async_work_promise/napi/package.json rename to src/5-async-work/async_work_promise/napi/package.json diff --git a/async_work_promise/node-addon-api/addon.cc b/src/5-async-work/async_work_promise/node-addon-api/addon.cc similarity index 99% rename from async_work_promise/node-addon-api/addon.cc rename to src/5-async-work/async_work_promise/node-addon-api/addon.cc index 35abd245..ccd2d7a3 100644 --- a/async_work_promise/node-addon-api/addon.cc +++ b/src/5-async-work/async_work_promise/node-addon-api/addon.cc @@ -10,14 +10,14 @@ Napi::Value DoHeavyMath(const Napi::CallbackInfo& info) { return env.Undefined(); } uint32_t num_1 = info[0].As().Uint32Value(); - + if (!info[1].IsNumber()) { Napi::TypeError::New(env, "num2 must be a number") .ThrowAsJavaScriptException(); return env.Undefined(); } uint32_t num_2 = info[1].As().Uint32Value(); - + DoHeavyMathWorker* worker = new DoHeavyMathWorker(env, num_1, num_2); worker->Queue(); return worker->GetPromise(); diff --git a/async_work_promise/node-addon-api/binding.gyp b/src/5-async-work/async_work_promise/node-addon-api/binding.gyp similarity index 100% rename from async_work_promise/node-addon-api/binding.gyp rename to src/5-async-work/async_work_promise/node-addon-api/binding.gyp diff --git a/async_work_promise/node-addon-api/index.js b/src/5-async-work/async_work_promise/node-addon-api/index.js similarity index 100% rename from async_work_promise/node-addon-api/index.js rename to src/5-async-work/async_work_promise/node-addon-api/index.js diff --git a/async_work_promise/node-addon-api/package.json b/src/5-async-work/async_work_promise/node-addon-api/package.json similarity index 100% rename from async_work_promise/node-addon-api/package.json rename to src/5-async-work/async_work_promise/node-addon-api/package.json diff --git a/async_work_promise/node-addon-api/worker.h b/src/5-async-work/async_work_promise/node-addon-api/worker.h similarity index 100% rename from async_work_promise/node-addon-api/worker.h rename to src/5-async-work/async_work_promise/node-addon-api/worker.h diff --git a/async_work_thread_safe_function/napi/binding.c b/src/5-async-work/async_work_thread_safe_function/napi/binding.c similarity index 100% rename from async_work_thread_safe_function/napi/binding.c rename to src/5-async-work/async_work_thread_safe_function/napi/binding.c diff --git a/async_work_thread_safe_function/napi/binding.gyp b/src/5-async-work/async_work_thread_safe_function/napi/binding.gyp similarity index 100% rename from async_work_thread_safe_function/napi/binding.gyp rename to src/5-async-work/async_work_thread_safe_function/napi/binding.gyp diff --git a/async_work_thread_safe_function/napi/index.js b/src/5-async-work/async_work_thread_safe_function/napi/index.js similarity index 100% rename from async_work_thread_safe_function/napi/index.js rename to src/5-async-work/async_work_thread_safe_function/napi/index.js diff --git a/async_work_thread_safe_function/napi/package.json b/src/5-async-work/async_work_thread_safe_function/napi/package.json similarity index 100% rename from async_work_thread_safe_function/napi/package.json rename to src/5-async-work/async_work_thread_safe_function/napi/package.json diff --git a/call-js-from-async-worker-execute/node-addon-api/binding.gyp b/src/5-async-work/call-js-from-async-worker-execute/node-addon-api/binding.gyp similarity index 100% rename from call-js-from-async-worker-execute/node-addon-api/binding.gyp rename to src/5-async-work/call-js-from-async-worker-execute/node-addon-api/binding.gyp diff --git a/call-js-from-async-worker-execute/node-addon-api/index.js b/src/5-async-work/call-js-from-async-worker-execute/node-addon-api/index.js similarity index 100% rename from call-js-from-async-worker-execute/node-addon-api/index.js rename to src/5-async-work/call-js-from-async-worker-execute/node-addon-api/index.js diff --git a/call-js-from-async-worker-execute/node-addon-api/package.json b/src/5-async-work/call-js-from-async-worker-execute/node-addon-api/package.json similarity index 100% rename from call-js-from-async-worker-execute/node-addon-api/package.json rename to src/5-async-work/call-js-from-async-worker-execute/node-addon-api/package.json diff --git a/call-js-from-async-worker-execute/node-addon-api/src/binding.cc b/src/5-async-work/call-js-from-async-worker-execute/node-addon-api/src/binding.cc similarity index 100% rename from call-js-from-async-worker-execute/node-addon-api/src/binding.cc rename to src/5-async-work/call-js-from-async-worker-execute/node-addon-api/src/binding.cc diff --git a/napi-asyncworker-example/node-addon-api/README.md b/src/5-async-work/napi-asyncworker-example/node-addon-api/README.md similarity index 100% rename from napi-asyncworker-example/node-addon-api/README.md rename to src/5-async-work/napi-asyncworker-example/node-addon-api/README.md diff --git a/napi-asyncworker-example/node-addon-api/binding.gyp b/src/5-async-work/napi-asyncworker-example/node-addon-api/binding.gyp similarity index 100% rename from napi-asyncworker-example/node-addon-api/binding.gyp rename to src/5-async-work/napi-asyncworker-example/node-addon-api/binding.gyp diff --git a/napi-asyncworker-example/node-addon-api/package.json b/src/5-async-work/napi-asyncworker-example/node-addon-api/package.json similarity index 100% rename from napi-asyncworker-example/node-addon-api/package.json rename to src/5-async-work/napi-asyncworker-example/node-addon-api/package.json diff --git a/napi-asyncworker-example/node-addon-api/src/RunSimpleAsyncWorker.cc b/src/5-async-work/napi-asyncworker-example/node-addon-api/src/RunSimpleAsyncWorker.cc similarity index 100% rename from napi-asyncworker-example/node-addon-api/src/RunSimpleAsyncWorker.cc rename to src/5-async-work/napi-asyncworker-example/node-addon-api/src/RunSimpleAsyncWorker.cc diff --git a/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.cc b/src/5-async-work/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.cc similarity index 100% rename from napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.cc rename to src/5-async-work/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.cc diff --git a/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.h b/src/5-async-work/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.h similarity index 100% rename from napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.h rename to src/5-async-work/napi-asyncworker-example/node-addon-api/src/SimpleAsyncWorker.h diff --git a/napi-asyncworker-example/node-addon-api/test/Test.js b/src/5-async-work/napi-asyncworker-example/node-addon-api/test/Test.js similarity index 100% rename from napi-asyncworker-example/node-addon-api/test/Test.js rename to src/5-async-work/napi-asyncworker-example/node-addon-api/test/Test.js diff --git a/promise-callback-demo/node-addon-api/README.md b/src/6-threadsafe-function/promise-callback-demo/node-addon-api/README.md similarity index 100% rename from promise-callback-demo/node-addon-api/README.md rename to src/6-threadsafe-function/promise-callback-demo/node-addon-api/README.md diff --git a/promise-callback-demo/node-addon-api/binding.gyp b/src/6-threadsafe-function/promise-callback-demo/node-addon-api/binding.gyp similarity index 100% rename from promise-callback-demo/node-addon-api/binding.gyp rename to src/6-threadsafe-function/promise-callback-demo/node-addon-api/binding.gyp diff --git a/promise-callback-demo/node-addon-api/package.json b/src/6-threadsafe-function/promise-callback-demo/node-addon-api/package.json similarity index 100% rename from promise-callback-demo/node-addon-api/package.json rename to src/6-threadsafe-function/promise-callback-demo/node-addon-api/package.json diff --git a/promise-callback-demo/node-addon-api/src/promise_callback_demo.cc b/src/6-threadsafe-function/promise-callback-demo/node-addon-api/src/promise_callback_demo.cc similarity index 100% rename from promise-callback-demo/node-addon-api/src/promise_callback_demo.cc rename to src/6-threadsafe-function/promise-callback-demo/node-addon-api/src/promise_callback_demo.cc diff --git a/promise-callback-demo/node-addon-api/test/index.js b/src/6-threadsafe-function/promise-callback-demo/node-addon-api/test/index.js similarity index 100% rename from promise-callback-demo/node-addon-api/test/index.js rename to src/6-threadsafe-function/promise-callback-demo/node-addon-api/test/index.js diff --git a/thread_safe_function_counting/node-addon-api/addon.cc b/src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/addon.cc similarity index 100% rename from thread_safe_function_counting/node-addon-api/addon.cc rename to src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/addon.cc diff --git a/thread_safe_function_counting/node-addon-api/addon.js b/src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/addon.js similarity index 100% rename from thread_safe_function_counting/node-addon-api/addon.js rename to src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/addon.js diff --git a/thread_safe_function_counting/node-addon-api/binding.gyp b/src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/binding.gyp similarity index 100% rename from thread_safe_function_counting/node-addon-api/binding.gyp rename to src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/binding.gyp diff --git a/thread_safe_function_counting/node-addon-api/package.json b/src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/package.json similarity index 100% rename from thread_safe_function_counting/node-addon-api/package.json rename to src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/package.json diff --git a/thread_safe_function_round_trip/napi/binding.gyp b/src/6-threadsafe-function/thread_safe_function_round_trip/napi/binding.gyp similarity index 100% rename from thread_safe_function_round_trip/napi/binding.gyp rename to src/6-threadsafe-function/thread_safe_function_round_trip/napi/binding.gyp diff --git a/thread_safe_function_round_trip/napi/index.js b/src/6-threadsafe-function/thread_safe_function_round_trip/napi/index.js similarity index 100% rename from thread_safe_function_round_trip/napi/index.js rename to src/6-threadsafe-function/thread_safe_function_round_trip/napi/index.js diff --git a/thread_safe_function_round_trip/napi/package.json b/src/6-threadsafe-function/thread_safe_function_round_trip/napi/package.json similarity index 100% rename from thread_safe_function_round_trip/napi/package.json rename to src/6-threadsafe-function/thread_safe_function_round_trip/napi/package.json diff --git a/thread_safe_function_round_trip/napi/round_trip.c b/src/6-threadsafe-function/thread_safe_function_round_trip/napi/round_trip.c similarity index 100% rename from thread_safe_function_round_trip/napi/round_trip.c rename to src/6-threadsafe-function/thread_safe_function_round_trip/napi/round_trip.c diff --git a/thread_safe_function_with_object_wrap/node-addon-api/binding.gyp b/src/6-threadsafe-function/thread_safe_function_with_object_wrap/node-addon-api/binding.gyp similarity index 100% rename from thread_safe_function_with_object_wrap/node-addon-api/binding.gyp rename to src/6-threadsafe-function/thread_safe_function_with_object_wrap/node-addon-api/binding.gyp diff --git a/thread_safe_function_with_object_wrap/node-addon-api/package.json b/src/6-threadsafe-function/thread_safe_function_with_object_wrap/node-addon-api/package.json similarity index 70% rename from thread_safe_function_with_object_wrap/node-addon-api/package.json rename to src/6-threadsafe-function/thread_safe_function_with_object_wrap/node-addon-api/package.json index 070d1bf6..201cfdf9 100644 --- a/thread_safe_function_with_object_wrap/node-addon-api/package.json +++ b/src/6-threadsafe-function/thread_safe_function_with_object_wrap/node-addon-api/package.json @@ -3,9 +3,6 @@ "version": "1.0.0", "description": "", "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, "author": "", "dependencies": { "bindings": "*", diff --git a/thread_safe_function_with_object_wrap/node-addon-api/tsfn_object_wrap.cc b/src/6-threadsafe-function/thread_safe_function_with_object_wrap/node-addon-api/tsfn_object_wrap.cc similarity index 100% rename from thread_safe_function_with_object_wrap/node-addon-api/tsfn_object_wrap.cc rename to src/6-threadsafe-function/thread_safe_function_with_object_wrap/node-addon-api/tsfn_object_wrap.cc diff --git a/thread_safe_function_with_object_wrap/node-addon-api/tsfn_object_wrap.js b/src/6-threadsafe-function/thread_safe_function_with_object_wrap/node-addon-api/tsfn_object_wrap.js similarity index 100% rename from thread_safe_function_with_object_wrap/node-addon-api/tsfn_object_wrap.js rename to src/6-threadsafe-function/thread_safe_function_with_object_wrap/node-addon-api/tsfn_object_wrap.js diff --git a/threadsafe-async-iterator/node-addon-api/CMakeLists.txt b/src/6-threadsafe-function/threadsafe-async-iterator/node-addon-api/CMakeLists.txt similarity index 100% rename from threadsafe-async-iterator/node-addon-api/CMakeLists.txt rename to src/6-threadsafe-function/threadsafe-async-iterator/node-addon-api/CMakeLists.txt diff --git a/threadsafe-async-iterator/node-addon-api/example.cc b/src/6-threadsafe-function/threadsafe-async-iterator/node-addon-api/example.cc similarity index 100% rename from threadsafe-async-iterator/node-addon-api/example.cc rename to src/6-threadsafe-function/threadsafe-async-iterator/node-addon-api/example.cc diff --git a/threadsafe-async-iterator/node-addon-api/index.js b/src/6-threadsafe-function/threadsafe-async-iterator/node-addon-api/index.js similarity index 100% rename from threadsafe-async-iterator/node-addon-api/index.js rename to src/6-threadsafe-function/threadsafe-async-iterator/node-addon-api/index.js diff --git a/threadsafe-async-iterator/node-addon-api/package.json b/src/6-threadsafe-function/threadsafe-async-iterator/node-addon-api/package.json similarity index 100% rename from threadsafe-async-iterator/node-addon-api/package.json rename to src/6-threadsafe-function/threadsafe-async-iterator/node-addon-api/package.json diff --git a/typed_threadsafe_function/node-addon-api/CMakeLists.txt b/src/6-threadsafe-function/typed_threadsafe_function/node-addon-api/CMakeLists.txt similarity index 100% rename from typed_threadsafe_function/node-addon-api/CMakeLists.txt rename to src/6-threadsafe-function/typed_threadsafe_function/node-addon-api/CMakeLists.txt diff --git a/typed_threadsafe_function/node-addon-api/clock.cc b/src/6-threadsafe-function/typed_threadsafe_function/node-addon-api/clock.cc similarity index 72% rename from typed_threadsafe_function/node-addon-api/clock.cc rename to src/6-threadsafe-function/typed_threadsafe_function/node-addon-api/clock.cc index f2af5ee4..2055ea7b 100644 --- a/typed_threadsafe_function/node-addon-api/clock.cc +++ b/src/6-threadsafe-function/typed_threadsafe_function/node-addon-api/clock.cc @@ -1,19 +1,19 @@ -#include #include +#include #include using namespace Napi; using Context = Reference; using DataType = int; -void CallJs(Napi::Env env, Function callback, Context *context, DataType *data); +void CallJs(Napi::Env env, Function callback, Context* context, DataType* data); using TSFN = TypedThreadSafeFunction; using FinalizerDataType = void; std::thread nativeThread; TSFN tsfn; -Value Start(const CallbackInfo &info) { +Value Start(const CallbackInfo& info) { Napi::Env env = info.Env(); if (info.Length() < 2) { @@ -28,18 +28,19 @@ Value Start(const CallbackInfo &info) { // Create a new context set to the the receiver (ie, `this`) of the function // call - Context *context = new Reference(Persistent(info.This())); + Context* context = new Reference(Persistent(info.This())); // Create a ThreadSafeFunction tsfn = TSFN::New( env, - info[0].As(), // JavaScript function called asynchronously - "Resource Name", // Name - 0, // Unlimited queue - 1, // Only one thread will use this initially + info[0].As(), // JavaScript function called asynchronously + "Resource Name", // Name + 0, // Unlimited queue + 1, // Only one thread will use this initially context, - [](Napi::Env, FinalizerDataType *, - Context *ctx) { // Finalizer used to clean threads up + [](Napi::Env, + FinalizerDataType*, + Context* ctx) { // Finalizer used to clean threads up nativeThread.join(); delete ctx; }); @@ -48,7 +49,7 @@ Value Start(const CallbackInfo &info) { nativeThread = std::thread([count] { for (int i = 0; i < count; i++) { // Create new data - int *value = new int(clock()); + int* value = new int(clock()); // Perform a blocking call napi_status status = tsfn.BlockingCall(value); @@ -69,13 +70,15 @@ Value Start(const CallbackInfo &info) { // Transform native data into JS data, passing it to the provided // `callback` -- the TSFN's JavaScript function. -void CallJs(Napi::Env env, Function callback, Context *context, - DataType *data) { +void CallJs(Napi::Env env, + Function callback, + Context* context, + DataType* data) { // Is the JavaScript environment still available to call into, eg. the TSFN is // not aborted if (env != nullptr) { - // On Node-API 5+, the `callback` parameter is optional; however, this example - // does ensure a callback is provided. + // On Node-API 5+, the `callback` parameter is optional; however, this + // example does ensure a callback is provided. if (callback != nullptr) { callback.Call(context->Value(), {Number::New(env, *data)}); } diff --git a/typed_threadsafe_function/node-addon-api/index.js b/src/6-threadsafe-function/typed_threadsafe_function/node-addon-api/index.js similarity index 100% rename from typed_threadsafe_function/node-addon-api/index.js rename to src/6-threadsafe-function/typed_threadsafe_function/node-addon-api/index.js diff --git a/typed_threadsafe_function/node-addon-api/package.json b/src/6-threadsafe-function/typed_threadsafe_function/node-addon-api/package.json similarity index 100% rename from typed_threadsafe_function/node-addon-api/package.json rename to src/6-threadsafe-function/typed_threadsafe_function/node-addon-api/package.json diff --git a/emit_event_from_cpp/node-addon-api/binding.gyp b/src/7-events/emit_event_from_cpp/node-addon-api/binding.gyp similarity index 100% rename from emit_event_from_cpp/node-addon-api/binding.gyp rename to src/7-events/emit_event_from_cpp/node-addon-api/binding.gyp diff --git a/emit_event_from_cpp/node-addon-api/index.js b/src/7-events/emit_event_from_cpp/node-addon-api/index.js similarity index 100% rename from emit_event_from_cpp/node-addon-api/index.js rename to src/7-events/emit_event_from_cpp/node-addon-api/index.js diff --git a/emit_event_from_cpp/node-addon-api/package.json b/src/7-events/emit_event_from_cpp/node-addon-api/package.json similarity index 100% rename from emit_event_from_cpp/node-addon-api/package.json rename to src/7-events/emit_event_from_cpp/node-addon-api/package.json diff --git a/emit_event_from_cpp/node-addon-api/src/emit-from-cpp.cc b/src/7-events/emit_event_from_cpp/node-addon-api/src/emit-from-cpp.cc similarity index 100% rename from emit_event_from_cpp/node-addon-api/src/emit-from-cpp.cc rename to src/7-events/emit_event_from_cpp/node-addon-api/src/emit-from-cpp.cc diff --git a/inherits_from_event_emitter/node-addon-api/binding.gyp b/src/7-events/inherits_from_event_emitter/node-addon-api/binding.gyp similarity index 100% rename from inherits_from_event_emitter/node-addon-api/binding.gyp rename to src/7-events/inherits_from_event_emitter/node-addon-api/binding.gyp diff --git a/inherits_from_event_emitter/node-addon-api/index.js b/src/7-events/inherits_from_event_emitter/node-addon-api/index.js similarity index 100% rename from inherits_from_event_emitter/node-addon-api/index.js rename to src/7-events/inherits_from_event_emitter/node-addon-api/index.js diff --git a/inherits_from_event_emitter/node-addon-api/package.json b/src/7-events/inherits_from_event_emitter/node-addon-api/package.json similarity index 100% rename from inherits_from_event_emitter/node-addon-api/package.json rename to src/7-events/inherits_from_event_emitter/node-addon-api/package.json diff --git a/inherits_from_event_emitter/node-addon-api/src/binding.cc b/src/7-events/inherits_from_event_emitter/node-addon-api/src/binding.cc similarity index 100% rename from inherits_from_event_emitter/node-addon-api/src/binding.cc rename to src/7-events/inherits_from_event_emitter/node-addon-api/src/binding.cc diff --git a/inherits_from_event_emitter/node-addon-api/src/native-emitter.cc b/src/7-events/inherits_from_event_emitter/node-addon-api/src/native-emitter.cc similarity index 100% rename from inherits_from_event_emitter/node-addon-api/src/native-emitter.cc rename to src/7-events/inherits_from_event_emitter/node-addon-api/src/native-emitter.cc diff --git a/inherits_from_event_emitter/node-addon-api/src/native-emitter.h b/src/7-events/inherits_from_event_emitter/node-addon-api/src/native-emitter.h similarity index 100% rename from inherits_from_event_emitter/node-addon-api/src/native-emitter.h rename to src/7-events/inherits_from_event_emitter/node-addon-api/src/native-emitter.h diff --git a/build_with_cmake/README.md b/src/8-tooling/build_with_cmake/README.md similarity index 100% rename from build_with_cmake/README.md rename to src/8-tooling/build_with_cmake/README.md diff --git a/build_with_cmake/napi/CMakeLists.txt b/src/8-tooling/build_with_cmake/napi/CMakeLists.txt similarity index 100% rename from build_with_cmake/napi/CMakeLists.txt rename to src/8-tooling/build_with_cmake/napi/CMakeLists.txt diff --git a/build_with_cmake/napi/hello.c b/src/8-tooling/build_with_cmake/napi/hello.c similarity index 100% rename from build_with_cmake/napi/hello.c rename to src/8-tooling/build_with_cmake/napi/hello.c diff --git a/build_with_cmake/napi/hello.js b/src/8-tooling/build_with_cmake/napi/hello.js similarity index 100% rename from build_with_cmake/napi/hello.js rename to src/8-tooling/build_with_cmake/napi/hello.js diff --git a/build_with_cmake/napi/package.json b/src/8-tooling/build_with_cmake/napi/package.json similarity index 100% rename from build_with_cmake/napi/package.json rename to src/8-tooling/build_with_cmake/napi/package.json diff --git a/build_with_cmake/node-addon-api/CMakeLists.txt b/src/8-tooling/build_with_cmake/node-addon-api/CMakeLists.txt similarity index 100% rename from build_with_cmake/node-addon-api/CMakeLists.txt rename to src/8-tooling/build_with_cmake/node-addon-api/CMakeLists.txt diff --git a/build_with_cmake/node-addon-api/hello.cc b/src/8-tooling/build_with_cmake/node-addon-api/hello.cc similarity index 75% rename from build_with_cmake/node-addon-api/hello.cc rename to src/8-tooling/build_with_cmake/node-addon-api/hello.cc index ae0f75d1..1c422da3 100644 --- a/build_with_cmake/node-addon-api/hello.cc +++ b/src/8-tooling/build_with_cmake/node-addon-api/hello.cc @@ -1,15 +1,16 @@ #include - static Napi::String Method(const Napi::CallbackInfo& info) { - // Napi::Env is the opaque data structure containing the environment in which the request is being run. - // We will need this env when we want to create any new objects inside of the node.js environment + // Napi::Env is the opaque data structure containing the environment in which + // the request is being run. We will need this env when we want to create any + // new objects inside of the node.js environment Napi::Env env = info.Env(); - + // Create a C++ level variable std::string helloWorld = "Hello, world!"; - - // Return a new javascript string that we copy-construct inside of the node.js environment + + // Return a new javascript string that we copy-construct inside of the node.js + // environment return Napi::String::New(env, helloWorld); } diff --git a/build_with_cmake/node-addon-api/hello.js b/src/8-tooling/build_with_cmake/node-addon-api/hello.js similarity index 100% rename from build_with_cmake/node-addon-api/hello.js rename to src/8-tooling/build_with_cmake/node-addon-api/hello.js diff --git a/build_with_cmake/node-addon-api/package.json b/src/8-tooling/build_with_cmake/node-addon-api/package.json similarity index 100% rename from build_with_cmake/node-addon-api/package.json rename to src/8-tooling/build_with_cmake/node-addon-api/package.json diff --git a/typescript_with_addon/node-addon-api/CMakeLists.txt b/src/8-tooling/typescript_with_addon/node-addon-api/CMakeLists.txt similarity index 100% rename from typescript_with_addon/node-addon-api/CMakeLists.txt rename to src/8-tooling/typescript_with_addon/node-addon-api/CMakeLists.txt diff --git a/typescript_with_addon/node-addon-api/README.md b/src/8-tooling/typescript_with_addon/node-addon-api/README.md similarity index 100% rename from typescript_with_addon/node-addon-api/README.md rename to src/8-tooling/typescript_with_addon/node-addon-api/README.md diff --git a/typescript_with_addon/node-addon-api/cPart.c b/src/8-tooling/typescript_with_addon/node-addon-api/cPart.c similarity index 100% rename from typescript_with_addon/node-addon-api/cPart.c rename to src/8-tooling/typescript_with_addon/node-addon-api/cPart.c diff --git a/typescript_with_addon/node-addon-api/cPart.h b/src/8-tooling/typescript_with_addon/node-addon-api/cPart.h similarity index 100% rename from typescript_with_addon/node-addon-api/cPart.h rename to src/8-tooling/typescript_with_addon/node-addon-api/cPart.h diff --git a/typescript_with_addon/node-addon-api/cppPart.cpp b/src/8-tooling/typescript_with_addon/node-addon-api/cppPart.cpp similarity index 100% rename from typescript_with_addon/node-addon-api/cppPart.cpp rename to src/8-tooling/typescript_with_addon/node-addon-api/cppPart.cpp diff --git a/typescript_with_addon/node-addon-api/index.ts b/src/8-tooling/typescript_with_addon/node-addon-api/index.ts similarity index 100% rename from typescript_with_addon/node-addon-api/index.ts rename to src/8-tooling/typescript_with_addon/node-addon-api/index.ts diff --git a/typescript_with_addon/node-addon-api/jsPart.js b/src/8-tooling/typescript_with_addon/node-addon-api/jsPart.js similarity index 100% rename from typescript_with_addon/node-addon-api/jsPart.js rename to src/8-tooling/typescript_with_addon/node-addon-api/jsPart.js diff --git a/typescript_with_addon/node-addon-api/napiPart.cpp b/src/8-tooling/typescript_with_addon/node-addon-api/napiPart.cpp similarity index 100% rename from typescript_with_addon/node-addon-api/napiPart.cpp rename to src/8-tooling/typescript_with_addon/node-addon-api/napiPart.cpp diff --git a/typescript_with_addon/node-addon-api/package.json b/src/8-tooling/typescript_with_addon/node-addon-api/package.json similarity index 100% rename from typescript_with_addon/node-addon-api/package.json rename to src/8-tooling/typescript_with_addon/node-addon-api/package.json diff --git a/typescript_with_addon/node-addon-api/tsconfig.json b/src/8-tooling/typescript_with_addon/node-addon-api/tsconfig.json similarity index 100% rename from typescript_with_addon/node-addon-api/tsconfig.json rename to src/8-tooling/typescript_with_addon/node-addon-api/tsconfig.json diff --git a/test_all.js b/test_all.js index a74db3fd..2782a90d 100644 --- a/test_all.js +++ b/test_all.js @@ -1,49 +1,90 @@ -const fs = require('fs') -const path = require('path') -const { execSync } = require('child_process') -const chalk = require('chalk') -const semver = require('semver') - -const excludeFolder = ['node_modules', 'website'] - -function getAllTests() { - return fs - .readdirSync('./') - .filter(i => { - return ( - !i.startsWith('.') && - fs.statSync(i).isDirectory() && - !excludeFolder.includes(i) - ) - }) - .map(i => { - const p = path.join(__dirname, i) - const tests = fs - .readdirSync(p) - .filter(j => fs.statSync(path.join(p, j)).isDirectory()) - .map(j => path.join(p, j)) - return tests - }) +const fs = require("fs"); +const path = require("path"); +const { execSync } = require("child_process"); +const chalk = require("chalk"); +const semver = require("semver"); + +const examplesFolder = path.join(__dirname, "src"); + +function getAllExamples(pathToCheck) { + const directoriesToTest = []; + for (const fd of fs.readdirSync(pathToCheck)) { + const absPath = path.join(pathToCheck, fd); + if (fs.existsSync(path.join(absPath, "package.json"))) { + directoriesToTest.push(absPath); + continue; + } + if (fs.statSync(absPath).isDirectory()) { + directoriesToTest.push(...getAllExamples(absPath)); + } + } + return directoriesToTest; } -getAllTests().map(tests => { - tests.map(i => { - console.log(chalk.green(`testing: ${i}`)) - const p = require(path.join(i, 'package.json')) - if (p.engines && p.engines.node) { - const currentNodeVersion = process.versions.node - const range = p.engines.node - const engineOk = semver.satisfies(currentNodeVersion, range) - if (!engineOk) { - console.warn( - chalk.yellow(`${i} require Node.js ${range}, current is ${currentNodeVersion}, skipping`) +const passed = []; +const failedInstalls = []; +const noTest = []; +const failedTests = []; +for (directoryToTest of getAllExamples(examplesFolder)) { + console.log(chalk.green(`testing: ${directoryToTest}`)); + const pkgJson = require(path.join(directoryToTest, "package.json")); + if (pkgJson.engines && pkgJson.engines.node) { + const currentNodeVersion = process.versions.node; + const range = pkgJson.engines.node; + const engineOk = semver.satisfies(currentNodeVersion, range); + if (!engineOk) { + console.warn( + chalk.yellow( + `${directoryToTest} require Node.js ${range}, current is ${currentNodeVersion}, skipping` ) - return - } + ); + continue; } - const stdout = execSync('npm install', { - cwd: i - }) - console.log(stdout.toString()) - }) -}) + } + + try { + const stdout = execSync("npm install", { cwd: directoryToTest }); + console.log(stdout.toString()); + } catch (err) { + console.log(err); + failedInstalls.push(directoryToTest); + continue; + } + + let testCommand; + if ("scripts" in pkgJson && "start" in pkgJson.scripts) { + testCommand = "npm start"; + } else if ("scripts" in pkgJson && "test" in pkgJson.scripts) { + testCommand = "npm test"; + } else if ("main" in pkgJson) { + testCommand = `node ${pkgJson.main}` + } else { + noTest.push(directoryToTest); + continue; + } + + try { + const stdout = execSync(testCommand, { cwd: directoryToTest }); + console.log(stdout.toString()); + passed.push(directoryToTest); + } catch (err) { + console.log(err); + failedTests.push(directoryToTest); + } +} + +passed.map((dir) => console.log(chalk.green(`passed: ${dir}`))); + +if (noTest.length > 0) { + console.warn(chalk.yellow("no test found:")); + noTest.map((dir) => console.warn(chalk.yellow(` ${dir}`))); +} + +if (failedInstalls.length > 0) { + console.error(chalk.red("failed to install:")); + failedInstalls.map((dir) => console.warn(chalk.red(` ${dir}`))); +} +if (failedTests.length > 0) { + console.error(chalk.red("failed tests:")); + failedTests.map((dir) => console.warn(chalk.red(` ${dir}`))); +}