diff --git a/.gitignore b/.gitignore index 72f7a9d..12b0145 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ .lock-wscript .DS_Store .project -.DS_Store node_modules/ test-addon/build/ +bin-*/ *.log diff --git a/doc/README.md b/doc/README.md index 483a2cf..7a59276 100644 --- a/doc/README.md +++ b/doc/README.md @@ -21,10 +21,8 @@ For **GYP**, the include directory is accessible with: ], ``` -For more examples, see [code snippets here](snippets.md). - -### Logging +## Logging Console logging and "global" logging helpers for C++ side are available: @@ -48,13 +46,6 @@ See JS Utils section in [README](/README.md). ``` - -### ES5 Classes - -Addon Tools provides C++ macro helpers for ES5 Classes (`function`-based). -See the [class-wrapping doc here](class-wrapping.md). - - ### Function Helpers Most of the helpers work within functions, where `Napi::CallbackInfo info` is @@ -242,3 +233,9 @@ calls `getArrayData` or `getArrayData` on it. Otherwise, if `value.data` is a `TypedArray|Buffer`, calls `getArrayData` or `getArrayData` on it. Returns `nullptr` in other cases. + + +### ES5 Classes + +Addon Tools provides C++ macro helpers for ES5 Classes (`function`-based). +See the [class-wrapping doc here](class-wrapping.md). diff --git a/doc/class-wrapping.md b/doc/class-wrapping.md index 6e15b95..0a4f32b 100644 --- a/doc/class-wrapping.md +++ b/doc/class-wrapping.md @@ -14,7 +14,7 @@ and on C++ side there is `inheritEs5` function. ## Class Declaration -``` +```cpp class ClassName { DECLARE_ES5_CLASS(ClassName, JSClassName); @@ -48,7 +48,7 @@ the second is the name of the setter to be created. ## Class Implementation -``` +```cpp IMPLEMENT_ES5_CLASS(ClassName); // Fill the properties and export the class diff --git a/doc/snippets.md b/doc/snippets.md deleted file mode 100644 index 429da85..0000000 --- a/doc/snippets.md +++ /dev/null @@ -1,81 +0,0 @@ -# Snippets - -## C++ Addon building - -### Binary distribution - -In **package.json** use the `"postinstall"` script to download the libraries. -For example the following structure might work. Note that **Addon Tools** will -append any given URL with `/${getPlatform()}.gz` - -In **package.json**: - -``` - "scripts": { - "postinstall": "node install", - }, - "dependencies": { - "addon-tools-raub": "^7.0.0", - }, - "devDependencies": { - "node-addon-api": "^5.0.0" - } -``` - -Create the **install.js** file, see `install` in [index.d.ts](/index.d.ts). -**Addon Tools** will unpack (using **tar**) the downloaded file into the platform binary -directory. E.g. on Windows it will be **bin-windows**. - -* For a dependency package: - - Place the following piece of code into the `index.js` without changes. - - ``` - module.exports = require('addon-tools-raub').getPaths(__dirname); - ``` - -* For a compiled addon: - - Require the `ADDON.node` in your **index.js** from the platform-specific directory. - ``` - const { getBin } = require('addon-tools-raub'); - const core = require(`./${getBin()}/ADDON`); - ``` - - -Publishing binaries is done by attaching a GZIPped platform folder to a GitHub -release. Zip file must NOT contain platform folder as a subfolder, but rather -contain the final binaries. The tag of the release should be the same as in -**install.js**. - -> NOTE: You can publish your binaries to anywhere, not necessarily GitHub. -Just tweak **YOUR install.js** script as appropriate. The only limitation -from **Addon Tools** is that it should be a GZIPped set of files/folders. - - -### GYP Variables - -``` - 'variables': { - 'bin': '; type TGlobalLogger = TGlobalLoggerMethods & Readonly<{ + /** Replace a logger channel in an existing logger */ replace: (level: string, fn: TLoggerFn) => void, }>; /** * Create a named global logger - * - * Copy a folder with all the contained files + * + * It will be also available from + * `global.AddonTools.log(name, level, arg1, arg2, ...);` */ export const createLogger: (opts: TGlobalLoggerOpts) => TGlobalLogger; + + /** + * Set logger level or `null` to turn off + */ export const setLevel: (level: TGlobalLoggerLevel | null) => void; + + /** + * Get logger level + */ export const getLevel: () => (TGlobalLoggerLevel | null); + + /** + * Get an object containing all registered loggers + */ export const getLoggers: () => Readonly> + + /** + * Get a logger by name, returns null if not found + */ export const getLogger: () => (TGlobalLogger | null) } diff --git a/package.json b/package.json index 2bdb23d..ae4d73f 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,11 @@ ], "files": [ "include", - "utils.js", - "utils.d.ts", "index.js", "index.d.ts", "utils", "LICENSE", - "package.json", - "README.md" + "package.json" ], "engines": { "node": ">=22.9.0", diff --git a/tests/download.test.js b/tests/download.test.js new file mode 100644 index 0000000..66ff92f --- /dev/null +++ b/tests/download.test.js @@ -0,0 +1,22 @@ +'use strict'; + +const assert = require('node:assert').strict; +const { describe, it } = require('node:test'); + +const { download } = require('..'); + + +const url = 'https://raw.githubusercontent.com/node-3d/image-raub/refs/tags/4.3.0/test/freeimage.jpg'; + + +describe('AT / Download', async () => { + const data = await download(url); + + it('data is Buffer', () => { + assert.strictEqual(data.constructor, Buffer); + }); + + it('downloaded byte count is correct', async () => { + assert.strictEqual(data.length, 7972); + }); +}); diff --git a/include.test.js b/tests/include.test.js similarity index 93% rename from include.test.js rename to tests/include.test.js index 3d5a5d3..37a6aac 100644 --- a/include.test.js +++ b/tests/include.test.js @@ -3,10 +3,10 @@ const assert = require('node:assert').strict; const { describe, it } = require('node:test'); -const tools = require('.'); +const tools = require('..'); -describe('AT / include', () => { +describe('AT / Include', () => { const stringMethods = ['getBin', 'getPlatform', 'getInclude']; stringMethods.forEach((name) => { diff --git a/tests/install.test.js b/tests/install.test.js new file mode 100644 index 0000000..cd52d1a --- /dev/null +++ b/tests/install.test.js @@ -0,0 +1,29 @@ +'use strict'; + +const assert = require('node:assert').strict; +const { describe, it } = require('node:test'); + +const { install, exists, getBin } = require('..'); + + +const prefix = 'https://github.com/node-3d/segfault-raub/releases/download'; +const tag = '2.3.0'; + + +describe('AT / Install', async () => { + const status = await install(`${prefix}/${tag}`); + + it('status is true', () => { + assert.strictEqual(status, true); + }); + + it('platform folder exists', async () => { + const isFolderCreated = await exists(`${__dirname}/../${getBin()}`); + assert.strictEqual(isFolderCreated, true); + }); + + it('platform binary exists', async () => { + const isAddonAvailable = await exists(`${__dirname}/../${getBin()}/segfault.node`); + assert.strictEqual(isAddonAvailable, true); + }); +}); diff --git a/logger.test.js b/tests/logger.test.js similarity index 98% rename from logger.test.js rename to tests/logger.test.js index 2dc5f25..08ddbd1 100644 --- a/logger.test.js +++ b/tests/logger.test.js @@ -3,7 +3,7 @@ const assert = require('node:assert').strict; const { describe, it } = require('node:test'); -const utils = require('.'); +const utils = require('..'); describe('AT / Logger', () => { let logged = ''; diff --git a/utils.test.js b/tests/utils.test.js similarity index 95% rename from utils.test.js rename to tests/utils.test.js index 273fd2a..14ff5f1 100644 --- a/utils.test.js +++ b/tests/utils.test.js @@ -3,7 +3,7 @@ const assert = require('node:assert').strict; const { describe, it } = require('node:test'); -const utils = require('.'); +const utils = require('..'); describe('AT / Util Exports', () => {