{"id":22427265,"url":"https://github.com/node-3d/addon-tools-raub","last_synced_at":"2025-08-01T10:31:58.071Z","repository":{"id":32332196,"uuid":"115880637","full_name":"node-3d/addon-tools-raub","owner":"node-3d","description":"Helpers for Node.js addons and dependency packages","archived":false,"fork":false,"pushed_at":"2024-11-02T05:24:48.000Z","size":2310,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-14T21:36:54.604Z","etag":null,"topics":["addon","addons","cross-platform","fs","gyp","header","header-files","helpers","hpp","logger","macros","napi","node","node-3d","node-addon","node-addon-api","node-js","nodejs","ts","utils"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/node-3d.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-31T18:59:35.000Z","updated_at":"2024-11-02T04:53:26.000Z","dependencies_parsed_at":"2024-05-30T18:11:34.327Z","dependency_job_id":"a1e95dea-4f55-4149-bdd7-00aa644ce900","html_url":"https://github.com/node-3d/addon-tools-raub","commit_stats":{"total_commits":267,"total_committers":4,"mean_commits":66.75,"dds":"0.42322097378277157","last_synced_commit":"105964614f00b939bb8af8f239e78fabc136c2d8"},"previous_names":["raub/node-addon-tools"],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-3d%2Faddon-tools-raub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-3d%2Faddon-tools-raub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-3d%2Faddon-tools-raub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-3d%2Faddon-tools-raub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-3d","download_url":"https://codeload.github.com/node-3d/addon-tools-raub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228061490,"owners_count":17863367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["addon","addons","cross-platform","fs","gyp","header","header-files","helpers","hpp","logger","macros","napi","node","node-3d","node-addon","node-addon-api","node-js","nodejs","ts","utils"],"created_at":"2024-12-05T20:11:19.830Z","updated_at":"2025-08-01T10:31:58.053Z","avatar_url":"https://github.com/node-3d.png","language":"JavaScript","readme":"# Addon Tools\n\nThis is a part of [Node3D](https://github.com/node-3d) project.\n\n[![NPM](https://badge.fury.io/js/addon-tools-raub.svg)](https://badge.fury.io/js/addon-tools-raub)\n[![ESLint](https://github.com/node-3d/addon-tools-raub/actions/workflows/eslint.yml/badge.svg)](https://github.com/node-3d/addon-tools-raub/actions/workflows/eslint.yml)\n[![Test](https://github.com/node-3d/addon-tools-raub/actions/workflows/test.yml/badge.svg)](https://github.com/node-3d/addon-tools-raub/actions/workflows/test.yml)\n[![Cpplint](https://github.com/node-3d/addon-tools-raub/actions/workflows/cpplint.yml/badge.svg)](https://github.com/node-3d/addon-tools-raub/actions/workflows/cpplint.yml)\n\n```console\nnpm i -s addon-tools-raub\n```\n\nAddon Tools provide build-time and run-time helpers for Node.js C++ addons.\n- C++ shortcuts to replace repetitive code in method/class\ndeclaration and commonly used calls (such as `console.log`).\n- JS helpers to deliver the precompiled addons to end-users during NPM install.\n- Common Logger for both C++ and JS sides with additional control,\ncompared to native (`printf/cout`) and console logging.\n\n## include/addon-tools.hpp\n\nMacros and helpers for C++ addons using **NAPI**.\nSee more detailed [docs here](/doc).\n\nExample of a C++ method definition using Addon Tools:\n\n```c++\n// hpp:\n#include \u003caddon-tools.hpp\u003e\nDBG_EXPORT JS_METHOD(doSomething);\n// cpp:\nDBG_EXPORT JS_METHOD(doSomething) { NAPI_ENV;\n\tLET_INT32_ARG(0, param0);\n\tNapi::Value args[2] = { JS_STR(\"param0:\"), JS_NUM(param0) };\n\tconsoleLog(env, 2, \u0026args[0]);\n\tRET_UNDEFINED;\n}\n```\n\nAlso, ES5 class helpers allow exporting a JS class directly from C++:\n\n```cpp\n// hpp:\n#include \u003caddon-tools.hpp\u003e\nclass MyClass {\nDECLARE_ES5_CLASS(MyClass, MyClass);\npublic:\n\tstatic void init(Napi::Env env, Napi::Object exports);\n\texplicit MyClass(const Napi::CallbackInfo\u0026 info);\n\t~MyClass();\nprivate:\n\tJS_DECLARE_GETTER(MyClass, a);\n\tJS_DECLARE_GETTER(MyClass, b);\n\tJS_DECLARE_METHOD(MyClass, test);\n};\n\n// cpp:\nIMPLEMENT_ES5_CLASS(MyClass);\n\nvoid MyClass::init(Napi::Env env, Napi::Object exports) {\n\tNapi::Function ctor = wrap(env);\n\tJS_ASSIGN_GETTER(a);\n\tJS_ASSIGN_GETTER(b);\n\tJS_ASSIGN_METHOD(test);\n\texports.Set(\"MyClass\", ctor);\n}\n\nMyClass::MyClass(const Napi::CallbackInfo \u0026info) {\n\tsuper(info);\n}\n\nMyClass::~MyClass() {}\n\nJS_IMPLEMENT_GETTER(MyClass, a) { NAPI_ENV;\n\tRET_NUM(10);\n}\n\nJS_IMPLEMENT_GETTER(MyClass, b) { NAPI_ENV;\n\tRET_NUM(20);\n}\n\nJS_IMPLEMENT_METHOD(MyClass, test) { NAPI_ENV;\n\tconsoleLog(\"test\");\n\tRET_STR(\"test\");\n}\n\nNapi::Object init(Napi::Env env, Napi::Object exports) {\n\tMyClass::init(env, exports);\n\treturn exports;\n}\n\nNODE_API_MODULE(myaddon, init)\n```\n\n## JS Addon Helpers\n\n### Example for an ADDON's **index.js**:\n\nGet the platform-specific directory name to import the `ADDON.node` file.\n\n```js\n\tconst { getBin } = require('addon-tools-raub');\n\tconst core = require(`./${getBin()}/ADDON`);\n```\n\n\n### Example for **binding.gyp**:\n\nUsing the include directories for both Addon Tools header\nand Addon API header:\n\n```gyp\n\t'include_dirs': [\n\t\t'\u003c!@(node -p \"require(\\'addon-tools-raub\\').getInclude()\")',\n\t],\n```\n\n\u003e NOTE: the optional `node-addon-api` dependency is used by the `getInclude()`\nhelper. If not found,\n\tthe **napi.h** include path won't be a part of the returned string.\n\nUsing helpers for paths to dependency libs and own binaries:\n\n```gyp\n\t'variables': {\n\t\t'bin': '\u003c!(node -p \"require(\\'addon-tools-raub\\').getBin()\")',\n\t\t'gl_include': '\u003c!(node -p \"require(\\'deps-opengl-raub\\').include\")',\n\t\t'gl_bin': '\u003c!(node -p \"require(\\'deps-opengl-raub\\').bin\")',\n\t},\n```\n\n\n### Example of `cpbin` in **package.json :: scripts**:\n\nCopy the addon file, for example, from `./src/build/Release/glfw.node`\nto `./bin-windows/glfw.node`, but each platform uses a different folder.\n\n```json\n\"build\": \"cd src \u0026\u0026 node-gyp rebuild -j max --silent \u0026\u0026 node -e \\\"require('addon-tools-raub').cpbin('glfw')\\\"\",\n\"build-only\": \"cd src \u0026\u0026 node-gyp build -j max --silent \u0026\u0026 node -e \\\"require('addon-tools-raub').cpbin('glfw')\\\"\",\n```\n\n### Example of `cpcpplint` in **cpplint.yml**:\n\nSince all my addons use the same codestyle, I don't keep\ncopies of the [CPPLINT config](/utils/CPPLINT.cfg) in\nevery addon. If that same config fits for you,\nhere's how it can be used:\n\n```yml\n- name: Run Cpplint\n  run: |\n    node -e \"require('addon-tools-raub').cpcpplint()\"\n    cpplint --recursive ./src/cpp\n```\n\n### Example of `install` in **install.js**:\n\nDownloads the addon (for example, from GitHub releases) and places\nit into a platform-specific folder.\n\n```js\nconst { install } = require('addon-tools-raub');\nconst prefix = 'https://github.com/node-3d/glfw-raub/releases/download';\nconst tag = '5.5.0';\ninstall(`${prefix}/${tag}`);\n```\n\n## JS Utils\n\nJavaScript helpers for Node.js addon development. The short list of helpers:\n\n```js\n\t'getBin', 'getPlatform', 'getInclude', 'getPaths',\n\t'install', 'cpbin', 'download', 'read', 'write', 'copy', 'exists',\n\t'mkdir', 'stat', 'isDir', 'isFile', 'dirUp', 'ensuredir', 'copysafe',\n\t'readdir', 'subdirs', 'subfiles', 'traverse', 'copyall',\n\t'rmdir', 'rm', 'WritableBuffer', 'actionPack',\n\t'createLogger', 'setLevel', 'getLevel', 'getLoggers',\n```\n\nSee the [TypeScript declarations](/index.d.ts) with comments.\n\n### Logger:\n\nThis helper provides simple logging interface, for both JS and C++, that may be used\nlocally or globally.\n\n```js\n\t// to `console` by default\n\tconst logger = utils.createLogger({ name: 'my-logger' });\n```\n\nNow the following JS calls are equal:\n\n```js\n\tlogger.warn(1, 2, '3');\n\tglobal.AddonTools.log('my-logger', 'warn', 1, 2, '3');\n\trequire('addon-tools-raub').getLogger('my-logger').warn(1, 2, '3');\n```\n\nAnd the C++ calls are:\n\n```cpp\n\tglobalLog(env, \"my-logger\", \"warn\", \"string log message\");\n\t// or\n\tNapi::Value args[3] = { JS_NUM(1), JS_NUM(2), JS_STR(\"3\") };\n\tglobalLog(env, \"cpp\", \"warn\", 3, \u0026args[0]);\n```\n\nSee the [TS declarations](/index.d.ts) with comments.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-3d%2Faddon-tools-raub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-3d%2Faddon-tools-raub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-3d%2Faddon-tools-raub/lists"}