Update module structure

This commit is contained in:
Luis Blanco 2023-01-03 22:20:39 +04:00
parent b532ca47bf
commit fd165d935d
55 changed files with 1176 additions and 513 deletions

View File

@ -9,60 +9,69 @@ This is a part of [Node3D](https://github.com/node-3d) project.
npm i addon-tools-raub npm i addon-tools-raub
``` ```
This module contains numerous helpers for Node.js **NAPI** This module contains helpers for Node.js **NAPI** addons and dependency packages.
addons and dependency packages. On this page, helper scripts On this page, helper scripts are described. For details on **addon-tools.hpp** and some
are described. For details on **addon-tools.hpp** and some
additional snippets follow the links below. additional snippets follow the links below.
**Docs**:
* [include/addon-tools.hpp](doc/addon-tools.md) ## include/addon-tools.hpp
Macro shortcuts for C++ addons using **NAPI**. Macro shortcuts for C++ addons using **NAPI**.
* [Es5 Class Wrapping](doc/class-wrapping.md) See [docs inside the folder](/include).
An alternative, lightweight native class-defining mechanism for addons. Example of an addon method definition:
* [Snippets](doc/snippets.md)
Some repetitive bits of code for addons. ```
// hpp:
#include <addon-tools.hpp>
DBG_EXPORT JS_METHOD(doSomething);
// cpp:
DBG_EXPORT JS_METHOD(doSomething) { NAPI_ENV;
LET_INT32_ARG(0, param0);
std::cout << "param0: " << param0 << std::endl;
RET_UNDEFINED;
}
```
## index.js ## index.js
> NOTE: peer dependency `node-addon-api` is required for this helper.
Main exports for cross-platform addon configuration. Main exports for cross-platform addon configuration.
See [TypeScript definitions](/index.d.ts) with comments. See the [TypeScript definitions](/index.d.ts) with comments.
> NOTE: the peer dependency `node-addon-api` is used by this helper.
## download.js Example for an ADDON's **index.js**:
Downloads a file into the memory, **HTTP** or **HTTPS**. ```
See [TypeScript definitions](/download.d.ts) with comments. const { bin } = require('addon-tools-raub');
const core = require(`./${bin}/ADDON`); // uses the platform-specific ADDON.node
```
Example for **binding.gyp**:
## cpbin.js ```
'include_dirs': [
Downloads a file into the memory, **HTTP** or **HTTPS**. '<!@(node -p "require(\'addon-tools-raub\').include")',
See [TypeScript definitions](/cpbin.d.ts) with comments. ],
```
## install.js
> NOTE: peer dependency `adm-zip` is required for this helper.
Downloads and unzips the platform specific binary for the calling package.
See [TypeScript definitions](/install.d.ts) with comments.
## writable-buffer.js
A [Writable](https://nodejs.org/api/stream.html#stream_writable_streams)
stream buffer.
See [TypeScript definitions](/writable-buffer.d.ts) with comments.
## utils.js ## utils.js
Async `fs` based helpers for common addon-related file operations. JS utils for Node.js modules and addons.
See [TypeScript definitions](/utils.d.ts) with comments.
```
const utils = require('addon-tools-raub/utils');
```
Example of `cpbin` usage in **package.json :: scripts**:
```
"build-all": "cd src && node-gyp rebuild -j max --silent && node -e \"require('addon-tools-raub/utils').cpbin('segfault')\" && cd ..",
"build-only": "cd src && node-gyp build -j max --silent && node -e \"require('addon-tools-raub/utils').cpbin('segfault')\" && cd ..",
```
See the [TypeScript definitions](/utils.d.ts) with comments.

18
conf/jest.json Normal file
View File

@ -0,0 +1,18 @@
{
"moduleFileExtensions": [
"js"
],
"testMatch": [
"**/*.test.js"
],
"coverageDirectory": "doc/jest",
"coverageReporters": [
"lcov"
],
"collectCoverageFrom": [
"**/*.js",
"!**/*.test.js",
"!index.js",
"!utils.js"
]
}

19
cpbin.d.ts vendored
View File

@ -1,19 +0,0 @@
declare module "addon-tools-raub/cpbin" {
/**
* Copy binary
* Copies the addon binary from `src/build/Release` to the platform folder.
* ```
* declare const cpbin: (name: string) => Promise<void>;
* export default cpbin;
* ```
* It is useful for development builds. Use it in your **src/package.json**:
* ```
* "scripts": {
* * "build": "node-gyp rebuild && node -e \"require('addon-tools-raub/cpbin')('ADDON')\""
* },
* ```
* Here ADDON should be replaced with the name of your addon, without `.node` extension.
*/
const cpbin: (name: string) => Promise<void>;
export = cpbin;
}

19
download.d.ts vendored
View File

@ -1,19 +0,0 @@
declare module "addon-tools-raub/download" {
/**
* Download to memory
* Accepts an **URL**, and returns an in-memory file Buffer,
* when the file is loaded. Use for small files, as the whole
* file will be loaded into memory at once.
*
* ```
* download(srcUrl).then(data => useData(data), err => emit('error', err));
* ```
* or
* ```
* const data = await download(srcUrl);
* useData(data);
* ```
*/
const download: (url: string) => Promise<Buffer>;
export = download;
}

51
include/index.js Normal file
View File

@ -0,0 +1,51 @@
'use strict';
let napi = null;
try {
napi = require('node-addon-api');
} catch (ex) {
// do nothing
}
const nameWindows = 'windows';
const platformAndArch = `${process.platform}-${process.arch}`;
const platformNames = {
'win32-x64': nameWindows,
'linux-x64': 'linux',
'darwin-x64': 'osx',
'linux-arm64': 'aarch64',
};
const platformName = platformNames[platformAndArch] || platformAndArch;
const isWindows = platformName === nameWindows;
const rootPath = __dirname.replace(/\\/g, '/');
const napiInclude = napi ? napi.include_dir.replace(/\\/g, '/') : '';
const thisInclude = `${rootPath}/include`;
const includePath = `${napiInclude} ${thisInclude}`;
const paths = (dir) => {
dir = dir.replace(/\\/g, '/');
const bin = `${dir}/bin-${platformName}`;
const include = `${dir}/include`;
if (isWindows) {
process.env.path = `${bin};${process.env.path ? `${process.env.path}` : ''}`;
}
return { bin, include };
};
module.exports = {
paths,
bin: `bin-${platformName}`,
platform: platformName,
include: includePath,
};

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const tools = require('..'); const tools = require('.');
describe('index.js', () => { describe('index.js', () => {

View File

@ -1,51 +1,3 @@
'use strict'; 'use strict';
let napi = null; module.exports = require('./index');
try {
napi = require('node-addon-api');
} catch (ex) {
// do nothing
}
const nameWindows = 'windows';
const platformAndArch = `${process.platform}-${process.arch}`;
const platformNames = {
'win32-x64': nameWindows,
'linux-x64': 'linux',
'darwin-x64': 'osx',
'linux-arm64': 'aarch64',
};
const platformName = platformNames[platformAndArch] || platformAndArch;
const isWindows = platformName === nameWindows;
const rootPath = __dirname.replace(/\\/g, '/');
const napiInclude = napi ? napi.include_dir.replace(/\\/g, '/') : '';
const thisInclude = `${rootPath}/include`;
const includePath = `${napiInclude} ${thisInclude}`;
const paths = (dir) => {
dir = dir.replace(/\\/g, '/');
const bin = `${dir}/bin-${platformName}`;
const include = `${dir}/include`;
if (isWindows) {
process.env.path = `${bin};${process.env.path ? `${process.env.path}` : ''}`;
}
return { bin, include };
};
module.exports = {
paths,
bin: `bin-${platformName}`,
platform: platformName,
include: includePath,
};

24
install.d.ts vendored
View File

@ -1,24 +0,0 @@
declare module "addon-tools-raub/install" {
/**
* Install binaries
* Downloads and unzips the platform specific binary for the calling package.
* To use it, create a new script for your package, which may as well be named
* **install.js**, with the following content:
* ```
* 'use strict';
* const install = require('addon-tools-raub/install');
* const prefix = 'https://github.com/USER/ADDON-NAME/releases/download';
* const tag = 'v1.0.0';
* install(`${prefix}/${tag}`);
* ```
* * `prefix` - the constant base part of the download url.
* * `tag` - the version-dependent part of the url.
* ```
* "scripts": {
* "postinstall": "node install"
* },
* ```
*/
const install: (folder: string) => void;
export = install;
}

120
package-lock.json generated
View File

@ -1,17 +1,16 @@
{ {
"name": "addon-tools-raub", "name": "addon-tools-raub",
"version": "6.3.0", "version": "7.0.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "addon-tools-raub", "name": "addon-tools-raub",
"version": "6.3.0", "version": "7.0.0",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"adm-zip": "^0.5.10", "eslint": "^8.31.0",
"eslint": "^8.30.0", "eslint-plugin-jest": "^27.2.0",
"eslint-plugin-jest": "^27.1.7",
"eslint-plugin-node": "^11.1.0", "eslint-plugin-node": "^11.1.0",
"jest": "^29.3.1", "jest": "^29.3.1",
"node-addon-api": "^5.0.0", "node-addon-api": "^5.0.0",
@ -22,13 +21,9 @@
"npm": ">=8.19.2" "npm": ">=8.19.2"
}, },
"peerDependencies": { "peerDependencies": {
"adm-zip": "^0.5.10",
"node-addon-api": "^5.0.0" "node-addon-api": "^5.0.0"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
"adm-zip": {
"optional": true
},
"node-addon-api": { "node-addon-api": {
"optional": true "optional": true
} }
@ -1314,13 +1309,13 @@
"dev": true "dev": true
}, },
"node_modules/@typescript-eslint/scope-manager": { "node_modules/@typescript-eslint/scope-manager": {
"version": "5.47.1", "version": "5.48.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.47.1.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.48.0.tgz",
"integrity": "sha512-9hsFDsgUwrdOoW1D97Ewog7DYSHaq4WKuNs0LHF9RiCmqB0Z+XRR4Pf7u7u9z/8CciHuJ6yxNws1XznI3ddjEw==", "integrity": "sha512-0AA4LviDtVtZqlyUQnZMVHydDATpD9SAX/RC5qh6cBd3xmyWvmXYF+WT1oOmxkeMnWDlUVTwdODeucUnjz3gow==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.47.1", "@typescript-eslint/types": "5.48.0",
"@typescript-eslint/visitor-keys": "5.47.1" "@typescript-eslint/visitor-keys": "5.48.0"
}, },
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@ -1331,9 +1326,9 @@
} }
}, },
"node_modules/@typescript-eslint/types": { "node_modules/@typescript-eslint/types": {
"version": "5.47.1", "version": "5.48.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.47.1.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.48.0.tgz",
"integrity": "sha512-CmALY9YWXEpwuu6377ybJBZdtSAnzXLSQcxLSqSQSbC7VfpMu/HLVdrnVJj7ycI138EHqocW02LPJErE35cE9A==", "integrity": "sha512-UTe67B0Ypius0fnEE518NB2N8gGutIlTojeTg4nt0GQvikReVkurqxd2LvYa9q9M5MQ6rtpNyWTBxdscw40Xhw==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@ -1344,13 +1339,13 @@
} }
}, },
"node_modules/@typescript-eslint/typescript-estree": { "node_modules/@typescript-eslint/typescript-estree": {
"version": "5.47.1", "version": "5.48.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.47.1.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.48.0.tgz",
"integrity": "sha512-4+ZhFSuISAvRi2xUszEj0xXbNTHceV9GbH9S8oAD2a/F9SW57aJNQVOCxG8GPfSWH/X4eOPdMEU2jYVuWKEpWA==", "integrity": "sha512-7pjd94vvIjI1zTz6aq/5wwE/YrfIyEPLtGJmRfyNR9NYIW+rOvzzUv3Cmq2hRKpvt6e9vpvPUQ7puzX7VSmsEw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.47.1", "@typescript-eslint/types": "5.48.0",
"@typescript-eslint/visitor-keys": "5.47.1", "@typescript-eslint/visitor-keys": "5.48.0",
"debug": "^4.3.4", "debug": "^4.3.4",
"globby": "^11.1.0", "globby": "^11.1.0",
"is-glob": "^4.0.3", "is-glob": "^4.0.3",
@ -1371,16 +1366,16 @@
} }
}, },
"node_modules/@typescript-eslint/utils": { "node_modules/@typescript-eslint/utils": {
"version": "5.47.1", "version": "5.48.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.47.1.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.48.0.tgz",
"integrity": "sha512-l90SdwqfmkuIVaREZ2ykEfCezepCLxzWMo5gVfcJsJCaT4jHT+QjgSkYhs5BMQmWqE9k3AtIfk4g211z/sTMVw==", "integrity": "sha512-x2jrMcPaMfsHRRIkL+x96++xdzvrdBCnYRd5QiW5Wgo1OB4kDYPbC1XjWP/TNqlfK93K/lUL92erq5zPLgFScQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@types/json-schema": "^7.0.9", "@types/json-schema": "^7.0.9",
"@types/semver": "^7.3.12", "@types/semver": "^7.3.12",
"@typescript-eslint/scope-manager": "5.47.1", "@typescript-eslint/scope-manager": "5.48.0",
"@typescript-eslint/types": "5.47.1", "@typescript-eslint/types": "5.48.0",
"@typescript-eslint/typescript-estree": "5.47.1", "@typescript-eslint/typescript-estree": "5.48.0",
"eslint-scope": "^5.1.1", "eslint-scope": "^5.1.1",
"eslint-utils": "^3.0.0", "eslint-utils": "^3.0.0",
"semver": "^7.3.7" "semver": "^7.3.7"
@ -1419,12 +1414,12 @@
} }
}, },
"node_modules/@typescript-eslint/visitor-keys": { "node_modules/@typescript-eslint/visitor-keys": {
"version": "5.47.1", "version": "5.48.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.47.1.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.48.0.tgz",
"integrity": "sha512-rF3pmut2JCCjh6BLRhNKdYjULMb1brvoaiWDlHfLNVgmnZ0sBVJrs3SyaKE1XoDDnJuAx/hDQryHYmPUuNq0ig==", "integrity": "sha512-5motVPz5EgxQ0bHjut3chzBkJ3Z3sheYVcSwS5BpHZpLqSptSmELNtGixmgj65+rIfhvtQTz5i9OP2vtzdDH7Q==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.47.1", "@typescript-eslint/types": "5.48.0",
"eslint-visitor-keys": "^3.3.0" "eslint-visitor-keys": "^3.3.0"
}, },
"engines": { "engines": {
@ -1456,15 +1451,6 @@
"acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0"
} }
}, },
"node_modules/adm-zip": {
"version": "0.5.10",
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.10.tgz",
"integrity": "sha512-x0HvcHqVJNTPk/Bw8JbLWlWoo6Wwnsug0fnYYro1HBrjxZ3G7/AZk7Ahv8JwDe1uIcz8eBqvu86FuF1POiG7vQ==",
"dev": true,
"engines": {
"node": ">=6.0"
}
},
"node_modules/ajv": { "node_modules/ajv": {
"version": "6.12.6", "version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
@ -5698,29 +5684,29 @@
"dev": true "dev": true
}, },
"@typescript-eslint/scope-manager": { "@typescript-eslint/scope-manager": {
"version": "5.47.1", "version": "5.48.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.47.1.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.48.0.tgz",
"integrity": "sha512-9hsFDsgUwrdOoW1D97Ewog7DYSHaq4WKuNs0LHF9RiCmqB0Z+XRR4Pf7u7u9z/8CciHuJ6yxNws1XznI3ddjEw==", "integrity": "sha512-0AA4LviDtVtZqlyUQnZMVHydDATpD9SAX/RC5qh6cBd3xmyWvmXYF+WT1oOmxkeMnWDlUVTwdODeucUnjz3gow==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/types": "5.47.1", "@typescript-eslint/types": "5.48.0",
"@typescript-eslint/visitor-keys": "5.47.1" "@typescript-eslint/visitor-keys": "5.48.0"
} }
}, },
"@typescript-eslint/types": { "@typescript-eslint/types": {
"version": "5.47.1", "version": "5.48.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.47.1.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.48.0.tgz",
"integrity": "sha512-CmALY9YWXEpwuu6377ybJBZdtSAnzXLSQcxLSqSQSbC7VfpMu/HLVdrnVJj7ycI138EHqocW02LPJErE35cE9A==", "integrity": "sha512-UTe67B0Ypius0fnEE518NB2N8gGutIlTojeTg4nt0GQvikReVkurqxd2LvYa9q9M5MQ6rtpNyWTBxdscw40Xhw==",
"dev": true "dev": true
}, },
"@typescript-eslint/typescript-estree": { "@typescript-eslint/typescript-estree": {
"version": "5.47.1", "version": "5.48.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.47.1.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.48.0.tgz",
"integrity": "sha512-4+ZhFSuISAvRi2xUszEj0xXbNTHceV9GbH9S8oAD2a/F9SW57aJNQVOCxG8GPfSWH/X4eOPdMEU2jYVuWKEpWA==", "integrity": "sha512-7pjd94vvIjI1zTz6aq/5wwE/YrfIyEPLtGJmRfyNR9NYIW+rOvzzUv3Cmq2hRKpvt6e9vpvPUQ7puzX7VSmsEw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/types": "5.47.1", "@typescript-eslint/types": "5.48.0",
"@typescript-eslint/visitor-keys": "5.47.1", "@typescript-eslint/visitor-keys": "5.48.0",
"debug": "^4.3.4", "debug": "^4.3.4",
"globby": "^11.1.0", "globby": "^11.1.0",
"is-glob": "^4.0.3", "is-glob": "^4.0.3",
@ -5729,16 +5715,16 @@
} }
}, },
"@typescript-eslint/utils": { "@typescript-eslint/utils": {
"version": "5.47.1", "version": "5.48.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.47.1.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.48.0.tgz",
"integrity": "sha512-l90SdwqfmkuIVaREZ2ykEfCezepCLxzWMo5gVfcJsJCaT4jHT+QjgSkYhs5BMQmWqE9k3AtIfk4g211z/sTMVw==", "integrity": "sha512-x2jrMcPaMfsHRRIkL+x96++xdzvrdBCnYRd5QiW5Wgo1OB4kDYPbC1XjWP/TNqlfK93K/lUL92erq5zPLgFScQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/json-schema": "^7.0.9", "@types/json-schema": "^7.0.9",
"@types/semver": "^7.3.12", "@types/semver": "^7.3.12",
"@typescript-eslint/scope-manager": "5.47.1", "@typescript-eslint/scope-manager": "5.48.0",
"@typescript-eslint/types": "5.47.1", "@typescript-eslint/types": "5.48.0",
"@typescript-eslint/typescript-estree": "5.47.1", "@typescript-eslint/typescript-estree": "5.48.0",
"eslint-scope": "^5.1.1", "eslint-scope": "^5.1.1",
"eslint-utils": "^3.0.0", "eslint-utils": "^3.0.0",
"semver": "^7.3.7" "semver": "^7.3.7"
@ -5763,12 +5749,12 @@
} }
}, },
"@typescript-eslint/visitor-keys": { "@typescript-eslint/visitor-keys": {
"version": "5.47.1", "version": "5.48.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.47.1.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.48.0.tgz",
"integrity": "sha512-rF3pmut2JCCjh6BLRhNKdYjULMb1brvoaiWDlHfLNVgmnZ0sBVJrs3SyaKE1XoDDnJuAx/hDQryHYmPUuNq0ig==", "integrity": "sha512-5motVPz5EgxQ0bHjut3chzBkJ3Z3sheYVcSwS5BpHZpLqSptSmELNtGixmgj65+rIfhvtQTz5i9OP2vtzdDH7Q==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/types": "5.47.1", "@typescript-eslint/types": "5.48.0",
"eslint-visitor-keys": "^3.3.0" "eslint-visitor-keys": "^3.3.0"
} }
}, },
@ -5785,12 +5771,6 @@
"dev": true, "dev": true,
"requires": {} "requires": {}
}, },
"adm-zip": {
"version": "0.5.10",
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.10.tgz",
"integrity": "sha512-x0HvcHqVJNTPk/Bw8JbLWlWoo6Wwnsug0fnYYro1HBrjxZ3G7/AZk7Ahv8JwDe1uIcz8eBqvu86FuF1POiG7vQ==",
"dev": true
},
"ajv": { "ajv": {
"version": "6.12.6", "version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",

View File

@ -1,7 +1,7 @@
{ {
"author": "Luis Blanco <luisblanco1337@gmail.com>", "author": "Luis Blanco <luisblanco1337@gmail.com>",
"name": "addon-tools-raub", "name": "addon-tools-raub",
"version": "6.3.0", "version": "7.0.0",
"description": "Helpers for Node.js addons and dependency packages", "description": "Helpers for Node.js addons and dependency packages",
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "index.js",
@ -19,18 +19,11 @@
], ],
"files": [ "files": [
"include", "include",
"cpbin.js",
"cpbin.d.ts",
"download.js",
"download.d.ts",
"index.js",
"index.d.ts",
"install.js",
"install.d.ts",
"utils.js", "utils.js",
"utils.d.ts", "utils.d.ts",
"writable-buffer.js", "index.js",
"writable-buffer.d.ts", "index.d.ts",
"utils",
"LICENSE", "LICENSE",
"package.json", "package.json",
"README.md" "README.md"
@ -41,44 +34,25 @@
}, },
"scripts": { "scripts": {
"eslint": "eslint .", "eslint": "eslint .",
"test": "jest --coverage=false --watch", "test": "jest --coverage=false --watch --config=conf/jest.json",
"test-ci": "jest --ci --runInBand --coverage=false --forceExit --detectOpenHandles", "test-ci": "jest --ci --runInBand --coverage=false --forceExit --detectOpenHandles --config=conf/jest.json",
"test-coverage": "rm -rf doc/jest && jest --coverage --silent", "test-coverage": "rm -rf doc/jest && jest --coverage --silent --config=conf/jest.json",
"test-build": "cd test && node-gyp rebuild && cd .." "test-build": "cd test-addon && node-gyp rebuild -j max --silent && cd .."
},
"jest": {
"moduleFileExtensions": [
"js"
],
"testMatch": [
"**/*.test.js"
],
"coverageDirectory": "doc/jest",
"coverageReporters": [
"lcov"
],
"collectCoverageFrom": [
"**/*.js",
"!**/*.test.js"
]
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/node-3d/addon-tools-raub.git" "url": "https://github.com/node-3d/addon-tools-raub.git"
}, },
"peerDependencies": { "peerDependencies": {
"adm-zip": "^0.5.10",
"node-addon-api": "^5.0.0" "node-addon-api": "^5.0.0"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
"adm-zip": { "optional": true },
"node-addon-api": { "optional": true } "node-addon-api": { "optional": true }
}, },
"devDependencies": { "devDependencies": {
"adm-zip": "^0.5.10", "eslint-plugin-jest": "^27.2.0",
"eslint-plugin-jest": "^27.1.7",
"eslint-plugin-node": "^11.1.0", "eslint-plugin-node": "^11.1.0",
"eslint": "^8.30.0", "eslint": "^8.31.0",
"jest": "^29.3.1", "jest": "^29.3.1",
"node-addon-api": "^5.0.0", "node-addon-api": "^5.0.0",
"typescript": "^4.9.4" "typescript": "^4.9.4"

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\_projects\addon-tools-raub\test\build\Release\test.node</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

Binary file not shown.

View File

@ -0,0 +1,2 @@
PlatformToolSet=v142:VCToolArchitecture=Native64Bit:VCToolsVersion=14.28.29910:TargetPlatformVersion=10.0.19041.0:
Release|x64|C:\_projects\addon-tools-raub\test\build\|

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2015
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcxproj", "{CA6D0C46-51F8-CCC5-FA71-4D2E9A260624}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Release|x64 = Release|x64
Debug|x64 = Debug|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CA6D0C46-51F8-CCC5-FA71-4D2E9A260624}.Release|x64.ActiveCfg = Release|x64
{CA6D0C46-51F8-CCC5-FA71-4D2E9A260624}.Release|x64.Build.0 = Release|x64
{CA6D0C46-51F8-CCC5-FA71-4D2E9A260624}.Debug|x64.ActiveCfg = Debug|x64
{CA6D0C46-51F8-CCC5-FA71-4D2E9A260624}.Debug|x64.Build.0 = Debug|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,397 @@
# Do not edit. File was generated by node-gyp's "configure" step
{
"target_defaults": {
"cflags": [],
"default_configuration": "Release",
"defines": [],
"include_dirs": [],
"libraries": [],
"msbuild_toolset": "v142",
"msvs_windows_target_platform_version": "10.0.19041.0"
},
"variables": {
"asan": 0,
"coverage": "false",
"dcheck_always_on": 0,
"debug_nghttp2": "false",
"debug_node": "false",
"enable_lto": "false",
"enable_pgo_generate": "false",
"enable_pgo_use": "false",
"error_on_warn": "false",
"force_dynamic_crt": 0,
"host_arch": "x64",
"icu_data_in": "..\\..\\deps\\icu-tmp\\icudt71l.dat",
"icu_endianness": "l",
"icu_gyp_path": "tools/icu/icu-generic.gyp",
"icu_path": "deps/icu-small",
"icu_small": "false",
"icu_ver_major": "71",
"is_debug": 0,
"libdir": "lib",
"llvm_version": "0.0",
"napi_build_version": "8",
"nasm_version": "2.15",
"node_byteorder": "little",
"node_debug_lib": "false",
"node_enable_d8": "false",
"node_fipsinstall": "false",
"node_install_corepack": "true",
"node_install_npm": "true",
"node_library_files": [
"lib/_http_agent.js",
"lib/_http_client.js",
"lib/_http_common.js",
"lib/_http_incoming.js",
"lib/_http_outgoing.js",
"lib/_http_server.js",
"lib/_stream_duplex.js",
"lib/_stream_passthrough.js",
"lib/_stream_readable.js",
"lib/_stream_transform.js",
"lib/_stream_wrap.js",
"lib/_stream_writable.js",
"lib/_tls_common.js",
"lib/_tls_wrap.js",
"lib/assert.js",
"lib/assert/strict.js",
"lib/async_hooks.js",
"lib/buffer.js",
"lib/child_process.js",
"lib/cluster.js",
"lib/console.js",
"lib/constants.js",
"lib/crypto.js",
"lib/dgram.js",
"lib/diagnostics_channel.js",
"lib/dns.js",
"lib/dns/promises.js",
"lib/domain.js",
"lib/events.js",
"lib/fs.js",
"lib/fs/promises.js",
"lib/http.js",
"lib/http2.js",
"lib/https.js",
"lib/inspector.js",
"lib/internal/abort_controller.js",
"lib/internal/assert.js",
"lib/internal/assert/assertion_error.js",
"lib/internal/assert/calltracker.js",
"lib/internal/assert/snapshot.js",
"lib/internal/async_hooks.js",
"lib/internal/blob.js",
"lib/internal/blocklist.js",
"lib/internal/bootstrap/browser.js",
"lib/internal/bootstrap/loaders.js",
"lib/internal/bootstrap/node.js",
"lib/internal/bootstrap/switches/does_not_own_process_state.js",
"lib/internal/bootstrap/switches/does_own_process_state.js",
"lib/internal/bootstrap/switches/is_main_thread.js",
"lib/internal/bootstrap/switches/is_not_main_thread.js",
"lib/internal/buffer.js",
"lib/internal/child_process.js",
"lib/internal/child_process/serialization.js",
"lib/internal/cli_table.js",
"lib/internal/cluster/child.js",
"lib/internal/cluster/primary.js",
"lib/internal/cluster/round_robin_handle.js",
"lib/internal/cluster/shared_handle.js",
"lib/internal/cluster/utils.js",
"lib/internal/cluster/worker.js",
"lib/internal/console/constructor.js",
"lib/internal/console/global.js",
"lib/internal/constants.js",
"lib/internal/crypto/aes.js",
"lib/internal/crypto/certificate.js",
"lib/internal/crypto/cfrg.js",
"lib/internal/crypto/cipher.js",
"lib/internal/crypto/diffiehellman.js",
"lib/internal/crypto/ec.js",
"lib/internal/crypto/hash.js",
"lib/internal/crypto/hashnames.js",
"lib/internal/crypto/hkdf.js",
"lib/internal/crypto/keygen.js",
"lib/internal/crypto/keys.js",
"lib/internal/crypto/mac.js",
"lib/internal/crypto/pbkdf2.js",
"lib/internal/crypto/random.js",
"lib/internal/crypto/rsa.js",
"lib/internal/crypto/scrypt.js",
"lib/internal/crypto/sig.js",
"lib/internal/crypto/util.js",
"lib/internal/crypto/webcrypto.js",
"lib/internal/crypto/x509.js",
"lib/internal/debugger/inspect.js",
"lib/internal/debugger/inspect_client.js",
"lib/internal/debugger/inspect_repl.js",
"lib/internal/dgram.js",
"lib/internal/dns/callback_resolver.js",
"lib/internal/dns/promises.js",
"lib/internal/dns/utils.js",
"lib/internal/dtrace.js",
"lib/internal/encoding.js",
"lib/internal/error_serdes.js",
"lib/internal/errors.js",
"lib/internal/event_target.js",
"lib/internal/fixed_queue.js",
"lib/internal/freelist.js",
"lib/internal/freeze_intrinsics.js",
"lib/internal/fs/cp/cp-sync.js",
"lib/internal/fs/cp/cp.js",
"lib/internal/fs/dir.js",
"lib/internal/fs/promises.js",
"lib/internal/fs/read_file_context.js",
"lib/internal/fs/rimraf.js",
"lib/internal/fs/streams.js",
"lib/internal/fs/sync_write_stream.js",
"lib/internal/fs/utils.js",
"lib/internal/fs/watchers.js",
"lib/internal/heap_utils.js",
"lib/internal/histogram.js",
"lib/internal/http.js",
"lib/internal/http2/compat.js",
"lib/internal/http2/core.js",
"lib/internal/http2/util.js",
"lib/internal/idna.js",
"lib/internal/inspector_async_hook.js",
"lib/internal/js_stream_socket.js",
"lib/internal/legacy/processbinding.js",
"lib/internal/linkedlist.js",
"lib/internal/main/check_syntax.js",
"lib/internal/main/environment.js",
"lib/internal/main/eval_stdin.js",
"lib/internal/main/eval_string.js",
"lib/internal/main/inspect.js",
"lib/internal/main/mksnapshot.js",
"lib/internal/main/print_help.js",
"lib/internal/main/prof_process.js",
"lib/internal/main/repl.js",
"lib/internal/main/run_main_module.js",
"lib/internal/main/test_runner.js",
"lib/internal/main/watch_mode.js",
"lib/internal/main/worker_thread.js",
"lib/internal/modules/cjs/helpers.js",
"lib/internal/modules/cjs/loader.js",
"lib/internal/modules/esm/assert.js",
"lib/internal/modules/esm/create_dynamic_module.js",
"lib/internal/modules/esm/fetch_module.js",
"lib/internal/modules/esm/formats.js",
"lib/internal/modules/esm/get_format.js",
"lib/internal/modules/esm/handle_process_exit.js",
"lib/internal/modules/esm/initialize_import_meta.js",
"lib/internal/modules/esm/load.js",
"lib/internal/modules/esm/loader.js",
"lib/internal/modules/esm/module_job.js",
"lib/internal/modules/esm/module_map.js",
"lib/internal/modules/esm/package_config.js",
"lib/internal/modules/esm/resolve.js",
"lib/internal/modules/esm/translators.js",
"lib/internal/modules/package_json_reader.js",
"lib/internal/modules/run_main.js",
"lib/internal/net.js",
"lib/internal/options.js",
"lib/internal/per_context/domexception.js",
"lib/internal/per_context/messageport.js",
"lib/internal/per_context/primordials.js",
"lib/internal/perf/event_loop_delay.js",
"lib/internal/perf/event_loop_utilization.js",
"lib/internal/perf/nodetiming.js",
"lib/internal/perf/observe.js",
"lib/internal/perf/performance.js",
"lib/internal/perf/performance_entry.js",
"lib/internal/perf/resource_timing.js",
"lib/internal/perf/timerify.js",
"lib/internal/perf/usertiming.js",
"lib/internal/perf/utils.js",
"lib/internal/policy/manifest.js",
"lib/internal/policy/sri.js",
"lib/internal/priority_queue.js",
"lib/internal/process/esm_loader.js",
"lib/internal/process/execution.js",
"lib/internal/process/per_thread.js",
"lib/internal/process/policy.js",
"lib/internal/process/pre_execution.js",
"lib/internal/process/promises.js",
"lib/internal/process/report.js",
"lib/internal/process/signal.js",
"lib/internal/process/task_queues.js",
"lib/internal/process/warning.js",
"lib/internal/process/worker_thread_only.js",
"lib/internal/promise_hooks.js",
"lib/internal/querystring.js",
"lib/internal/readline/callbacks.js",
"lib/internal/readline/emitKeypressEvents.js",
"lib/internal/readline/interface.js",
"lib/internal/readline/promises.js",
"lib/internal/readline/utils.js",
"lib/internal/repl.js",
"lib/internal/repl/await.js",
"lib/internal/repl/history.js",
"lib/internal/repl/utils.js",
"lib/internal/socket_list.js",
"lib/internal/socketaddress.js",
"lib/internal/source_map/prepare_stack_trace.js",
"lib/internal/source_map/source_map.js",
"lib/internal/source_map/source_map_cache.js",
"lib/internal/stream_base_commons.js",
"lib/internal/streams/add-abort-signal.js",
"lib/internal/streams/buffer_list.js",
"lib/internal/streams/compose.js",
"lib/internal/streams/destroy.js",
"lib/internal/streams/duplex.js",
"lib/internal/streams/duplexify.js",
"lib/internal/streams/end-of-stream.js",
"lib/internal/streams/from.js",
"lib/internal/streams/lazy_transform.js",
"lib/internal/streams/legacy.js",
"lib/internal/streams/operators.js",
"lib/internal/streams/passthrough.js",
"lib/internal/streams/pipeline.js",
"lib/internal/streams/readable.js",
"lib/internal/streams/state.js",
"lib/internal/streams/transform.js",
"lib/internal/streams/utils.js",
"lib/internal/streams/writable.js",
"lib/internal/structured_clone.js",
"lib/internal/test/binding.js",
"lib/internal/test/transfer.js",
"lib/internal/test_runner/harness.js",
"lib/internal/test_runner/runner.js",
"lib/internal/test_runner/tap_stream.js",
"lib/internal/test_runner/test.js",
"lib/internal/test_runner/utils.js",
"lib/internal/timers.js",
"lib/internal/tls/secure-context.js",
"lib/internal/tls/secure-pair.js",
"lib/internal/trace_events_async_hooks.js",
"lib/internal/tty.js",
"lib/internal/url.js",
"lib/internal/util.js",
"lib/internal/util/colors.js",
"lib/internal/util/comparisons.js",
"lib/internal/util/debuglog.js",
"lib/internal/util/inspect.js",
"lib/internal/util/inspector.js",
"lib/internal/util/iterable_weak_map.js",
"lib/internal/util/parse_args/parse_args.js",
"lib/internal/util/parse_args/utils.js",
"lib/internal/util/types.js",
"lib/internal/v8/startup_snapshot.js",
"lib/internal/v8_prof_polyfill.js",
"lib/internal/v8_prof_processor.js",
"lib/internal/validators.js",
"lib/internal/vm/module.js",
"lib/internal/wasm_web_api.js",
"lib/internal/watch_mode/files_watcher.js",
"lib/internal/watchdog.js",
"lib/internal/webstreams/adapters.js",
"lib/internal/webstreams/compression.js",
"lib/internal/webstreams/encoding.js",
"lib/internal/webstreams/queuingstrategies.js",
"lib/internal/webstreams/readablestream.js",
"lib/internal/webstreams/transfer.js",
"lib/internal/webstreams/transformstream.js",
"lib/internal/webstreams/util.js",
"lib/internal/webstreams/writablestream.js",
"lib/internal/worker.js",
"lib/internal/worker/io.js",
"lib/internal/worker/js_transferable.js",
"lib/module.js",
"lib/net.js",
"lib/os.js",
"lib/path.js",
"lib/path/posix.js",
"lib/path/win32.js",
"lib/perf_hooks.js",
"lib/process.js",
"lib/punycode.js",
"lib/querystring.js",
"lib/readline.js",
"lib/readline/promises.js",
"lib/repl.js",
"lib/stream.js",
"lib/stream/consumers.js",
"lib/stream/promises.js",
"lib/stream/web.js",
"lib/string_decoder.js",
"lib/sys.js",
"lib/test.js",
"lib/timers.js",
"lib/timers/promises.js",
"lib/tls.js",
"lib/trace_events.js",
"lib/tty.js",
"lib/url.js",
"lib/util.js",
"lib/util/types.js",
"lib/v8.js",
"lib/vm.js",
"lib/wasi.js",
"lib/worker_threads.js",
"lib/zlib.js"
],
"node_module_version": 108,
"node_no_browser_globals": "false",
"node_prefix": "/usr/local",
"node_release_urlbase": "https://nodejs.org/download/release/",
"node_shared": "false",
"node_shared_brotli": "false",
"node_shared_cares": "false",
"node_shared_http_parser": "false",
"node_shared_libuv": "false",
"node_shared_nghttp2": "false",
"node_shared_nghttp3": "false",
"node_shared_ngtcp2": "false",
"node_shared_openssl": "false",
"node_shared_zlib": "false",
"node_tag": "",
"node_target_type": "executable",
"node_use_bundled_v8": "true",
"node_use_dtrace": "false",
"node_use_etw": "true",
"node_use_node_code_cache": "true",
"node_use_node_snapshot": "true",
"node_use_openssl": "true",
"node_use_v8_platform": "true",
"node_with_ltcg": "true",
"node_without_node_options": "false",
"openssl_is_fips": "false",
"openssl_quic": "true",
"ossfuzz": "false",
"shlib_suffix": "so.108",
"target_arch": "x64",
"v8_enable_31bit_smis_on_64bit_arch": 0,
"v8_enable_gdbjit": 0,
"v8_enable_hugepage": 0,
"v8_enable_i18n_support": 1,
"v8_enable_inspector": 1,
"v8_enable_javascript_promise_hooks": 1,
"v8_enable_lite_mode": 0,
"v8_enable_object_print": 1,
"v8_enable_pointer_compression": 0,
"v8_enable_shared_ro_heap": 1,
"v8_enable_short_builtin_calls": 1,
"v8_enable_webassembly": 1,
"v8_no_strict_aliasing": 1,
"v8_optimized_debug": 1,
"v8_promise_internal_field_count": 1,
"v8_random_seed": 0,
"v8_trace_maps": 0,
"v8_use_siphash": 1,
"want_separate_host_toolset": 0,
"nodedir": "C:\\Users\\Luis\\AppData\\Local\\node-gyp\\Cache\\18.12.1",
"standalone_static_library": 1,
"msbuild_path": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\Bin\\MSBuild.exe",
"cache": "C:\\Users\\Luis\\AppData\\Local\\npm-cache",
"globalconfig": "C:\\Program Files\\nodejs\\etc\\npmrc",
"global_prefix": "C:\\Program Files\\nodejs",
"init_module": "C:\\Users\\Luis\\.npm-init.js",
"local_prefix": "C:\\_projects\\addon-tools-raub",
"metrics_registry": "https://registry.npmjs.org/",
"node_gyp": "C:\\Users\\Luis\\AppData\\Roaming\\nvm\\v18.12.1\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js",
"prefix": "C:\\Program Files\\nodejs",
"userconfig": "C:\\Users\\Luis\\.npmrc",
"user_agent": "npm/8.19.2 node/v18.12.1 win32 x64 workspaces/false"
}
}

View File

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{CA6D0C46-51F8-CCC5-FA71-4D2E9A260624}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>test</RootNamespace>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<PreferredToolArchitecture>x64</PreferredToolArchitecture>
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props"/>
<PropertyGroup Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<PropertyGroup Label="Locals">
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props"/>
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props"/>
<ImportGroup Label="ExtensionSettings"/>
<ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"/>
</ImportGroup>
<PropertyGroup Label="UserMacros"/>
<PropertyGroup>
<ExecutablePath>$(ExecutablePath);$(MSBuildProjectDirectory)\..\bin\;$(MSBuildProjectDirectory)\..\bin\</ExecutablePath>
<IgnoreImportLibrary>true</IgnoreImportLibrary>
<IntDir>$(Configuration)\obj\$(ProjectName)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.node</TargetExt>
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.node</TargetExt>
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.node</TargetExt>
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.node</TargetExt>
<TargetName>$(ProjectName)</TargetName>
<TargetPath>$(OutDir)\$(ProjectName).node</TargetPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<AdditionalIncludeDirectories>C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\include\node;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\src;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\config;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\openssl\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\uv\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\zlib;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\v8\include;..\..\node_modules\node-addon-api;C:\_projects\addon-tools-raub\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/Zc:__cplusplus -std:c++17 /O2 /Oy /GL /GF /Gm- /std:c++17 /EHa-s-c- /MT /GS /Gy /GR- /Gd %(AdditionalOptions)</AdditionalOptions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<BufferSecurityCheck>true</BufferSecurityCheck>
<DebugInformationFormat>OldStyle</DebugInformationFormat>
<DisableSpecificWarnings>4351;4355;4800;4251;4275;4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<ExceptionHandling>false</ExceptionHandling>
<MinimalRebuild>false</MinimalRebuild>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<OmitFramePointers>false</OmitFramePointers>
<Optimization>Disabled</Optimization>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PreprocessorDefinitions>NODE_GYP_MODULE_NAME=test;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;UNICODE;_UNICODE;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;_WIN32;BUILDING_NODE_EXTENSION;HOST_BINARY=&quot;node.exe&quot;;DEBUG;_DEBUG;V8_ENABLE_CHECKS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<StringPooling>true</StringPooling>
<SuppressStartupBanner>true</SuppressStartupBanner>
<TreatWarningAsError>false</TreatWarningAsError>
<WarningLevel>Level3</WarningLevel>
<WholeProgramOptimization>true</WholeProgramOptimization>
</ClCompile>
<Lib>
<AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
</Lib>
<Link>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;DelayImp.lib;&quot;C:\\Users\\Luis\\AppData\\Local\\node-gyp\\Cache\\18.12.1\\x64\\node.lib&quot;</AdditionalDependencies>
<AdditionalOptions>/LTCG:INCREMENTAL /OPT:REF /OPT:ICF /LTCG /ignore:4199 %(AdditionalOptions)</AdditionalOptions>
<DelayLoadDLLs>node.exe;%(DelayLoadDLLs)</DelayLoadDLLs>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OptimizeReferences>true</OptimizeReferences>
<OutputFile>$(OutDir)$(ProjectName).node</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<TargetExt>.node</TargetExt>
<TargetMachine>MachineX64</TargetMachine>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\include\node;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\src;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\config;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\openssl\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\uv\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\zlib;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\v8\include;..\..\node_modules\node-addon-api;C:\_projects\addon-tools-raub\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NODE_GYP_MODULE_NAME=test;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;UNICODE;_UNICODE;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;_WIN32;BUILDING_NODE_EXTENSION;HOST_BINARY=&quot;node.exe&quot;;DEBUG;_DEBUG;V8_ENABLE_CHECKS;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<AdditionalIncludeDirectories>C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\include\node;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\src;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\config;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\openssl\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\uv\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\zlib;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\v8\include;..\..\node_modules\node-addon-api;C:\_projects\addon-tools-raub\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/Zc:__cplusplus -std:c++17 /O2 /Oy /GL /GF /Gm- /std:c++17 /EHa-s-c- /MT /GS /Gy /GR- /Gd %(AdditionalOptions)</AdditionalOptions>
<BufferSecurityCheck>true</BufferSecurityCheck>
<DebugInformationFormat>OldStyle</DebugInformationFormat>
<DisableSpecificWarnings>4351;4355;4800;4251;4275;4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<ExceptionHandling>false</ExceptionHandling>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<FunctionLevelLinking>true</FunctionLevelLinking>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<OmitFramePointers>true</OmitFramePointers>
<Optimization>Full</Optimization>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PreprocessorDefinitions>NODE_GYP_MODULE_NAME=test;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;UNICODE;_UNICODE;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;_WIN32;BUILDING_NODE_EXTENSION;HOST_BINARY=&quot;node.exe&quot;;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<StringPooling>true</StringPooling>
<SuppressStartupBanner>true</SuppressStartupBanner>
<TreatWarningAsError>false</TreatWarningAsError>
<WarningLevel>Level3</WarningLevel>
<WholeProgramOptimization>true</WholeProgramOptimization>
</ClCompile>
<Lib>
<AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
</Lib>
<Link>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;DelayImp.lib;&quot;C:\\Users\\Luis\\AppData\\Local\\node-gyp\\Cache\\18.12.1\\x64\\node.lib&quot;</AdditionalDependencies>
<AdditionalOptions>/LTCG:INCREMENTAL /OPT:REF /OPT:ICF /LTCG /ignore:4199 %(AdditionalOptions)</AdditionalOptions>
<DelayLoadDLLs>node.exe;%(DelayLoadDLLs)</DelayLoadDLLs>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OptimizeReferences>true</OptimizeReferences>
<OutputFile>$(OutDir)$(ProjectName).node</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<TargetExt>.node</TargetExt>
<TargetMachine>MachineX64</TargetMachine>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\include\node;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\src;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\config;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\openssl\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\uv\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\zlib;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\v8\include;..\..\node_modules\node-addon-api;C:\_projects\addon-tools-raub\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NODE_GYP_MODULE_NAME=test;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;UNICODE;_UNICODE;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;_WIN32;BUILDING_NODE_EXTENSION;HOST_BINARY=&quot;node.exe&quot;;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="..\binding.gyp"/>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\test.cpp">
<ObjectFileName>$(IntDir)\test.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="C:\Users\Luis\AppData\Roaming\nvm\v18.12.1\node_modules\npm\node_modules\node-gyp\src\win_delay_load_hook.cc"/>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/>
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets"/>
<ImportGroup Label="ExtensionTargets"/>
</Project>

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="..">
<UniqueIdentifier>{739DB09A-CC57-A953-A6CF-F64FA08E4FA7}</UniqueIdentifier>
</Filter>
<Filter Include="C:">
<UniqueIdentifier>{7B735499-E5DD-1C2B-6C26-70023832A1CF}</UniqueIdentifier>
</Filter>
<Filter Include="C:\Users">
<UniqueIdentifier>{E9F714C1-DA89-54E2-60CF-39FEB20BF756}</UniqueIdentifier>
</Filter>
<Filter Include="C:\Users\Luis">
<UniqueIdentifier>{5215B9C8-08C9-9B12-A4BC-6B55FF1672C0}</UniqueIdentifier>
</Filter>
<Filter Include="C:\Users\Luis\AppData">
<UniqueIdentifier>{F852EB63-437C-846A-220F-8D9ED6DAEC1D}</UniqueIdentifier>
</Filter>
<Filter Include="C:\Users\Luis\AppData\Roaming">
<UniqueIdentifier>{D51E5808-912B-5C70-4BB7-475D1DBFA067}</UniqueIdentifier>
</Filter>
<Filter Include="C:\Users\Luis\AppData\Roaming\nvm">
<UniqueIdentifier>{1B85D12A-9F9C-E0A8-F82E-74864675B527}</UniqueIdentifier>
</Filter>
<Filter Include="C:\Users\Luis\AppData\Roaming\nvm\v18.12.1">
<UniqueIdentifier>{68329104-0883-3C95-6BC9-C46F7BFC39D9}</UniqueIdentifier>
</Filter>
<Filter Include="C:\Users\Luis\AppData\Roaming\nvm\v18.12.1\node_modules">
<UniqueIdentifier>{56DF7A98-063D-FB9D-485C-089023B4C16A}</UniqueIdentifier>
</Filter>
<Filter Include="C:\Users\Luis\AppData\Roaming\nvm\v18.12.1\node_modules\npm">
<UniqueIdentifier>{741E0E76-39B2-B1AB-9FA1-F1A20B16F295}</UniqueIdentifier>
</Filter>
<Filter Include="C:\Users\Luis\AppData\Roaming\nvm\v18.12.1\node_modules\npm\node_modules">
<UniqueIdentifier>{56DF7A98-063D-FB9D-485C-089023B4C16A}</UniqueIdentifier>
</Filter>
<Filter Include="C:\Users\Luis\AppData\Roaming\nvm\v18.12.1\node_modules\npm\node_modules\node-gyp">
<UniqueIdentifier>{77348C0E-2034-7791-74D5-63C077DF5A3B}</UniqueIdentifier>
</Filter>
<Filter Include="C:\Users\Luis\AppData\Roaming\nvm\v18.12.1\node_modules\npm\node_modules\node-gyp\src">
<UniqueIdentifier>{8CDEE807-BC53-E450-C8B8-4DEBB66742D4}</UniqueIdentifier>
</Filter>
<Filter Include="..">
<UniqueIdentifier>{739DB09A-CC57-A953-A6CF-F64FA08E4FA7}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\test.cpp">
<Filter>..</Filter>
</ClCompile>
<ClCompile Include="C:\Users\Luis\AppData\Roaming\nvm\v18.12.1\node_modules\npm\node_modules\node-gyp\src\win_delay_load_hook.cc">
<Filter>C:\Users\Luis\AppData\Roaming\nvm\v18.12.1\node_modules\npm\node_modules\node-gyp\src</Filter>
</ClCompile>
<None Include="..\binding.gyp">
<Filter>..</Filter>
</None>
</ItemGroup>
</Project>

80
utils.d.ts vendored
View File

@ -1,10 +1,87 @@
import type { Stats } from 'fs'; import type { Writable } from 'stream';
declare module "addon-tools-raub/utils" { declare module "addon-tools-raub/utils" {
/**
* Install binaries
* Downloads and unzips the platform specific binary for the calling package.
* To use it, create a new script for your package, which may as well be named
* **install.js**, with the following content:
* ```
* 'use strict';
* const install = require('addon-tools-raub/install');
* const prefix = 'https://github.com/USER/ADDON-NAME/releases/download';
* const tag = 'v1.0.0';
* install(`${prefix}/${tag}`);
* ```
* * `prefix` - the constant base part of the download url.
* * `tag` - the version-dependent part of the url.
* ```
* "scripts": {
* "postinstall": "node install"
* },
* ```
*/
export const install: (folder: string) => void;
/**
* Copy binary
* Copies the addon binary from `src/build/Release` to the platform folder.
* ```
* declare const cpbin: (name: string) => Promise<void>;
* export default cpbin;
* ```
* It is useful for development builds. Use it in your **src/package.json**:
* ```
* "scripts": {
* * "build": "node-gyp rebuild && node -e \"require('addon-tools-raub/cpbin')('ADDON')\""
* },
* ```
* Here ADDON should be replaced with the name of your addon, without `.node` extension.
*/
export const cpbin: (name: string) => Promise<void>;
/**
* Download to memory
* Accepts an **URL**, and returns an in-memory file Buffer,
* when the file is loaded. Use for small files, as the whole
* file will be loaded into memory at once.
*
* ```
* download(srcUrl).then(data => useData(data), err => emit('error', err));
* ```
* or
* ```
* const data = await download(srcUrl);
* useData(data);
* ```
*/
export const download: (url: string) => Promise<Buffer>;
/** /**
* (async) Read a file * (async) Read a file
* Reads a whole file to string, NOT A Buffer * Reads a whole file to string, NOT A Buffer
*/ */
/**
* WritableBuffer
* A [Writable](https://nodejs.org/api/stream.html#stream_writable_streams)
* stream buffer, that is stored in-memory and can be fully
* obtained when writing was finished. It is equivalent to stream-writing
* a temporary file and then reading it into a `Buffer`.
*/
export class WritableBuffer extends Writable {
constructor();
/**
* Get the downloaded data
* Use `stream.get()` to obtain the data when writing was finished
*/
get(): Buffer;
}
export const read: (name: string) => Promise<string>; export const read: (name: string) => Promise<string>;
/** /**
@ -101,5 +178,4 @@ declare module "addon-tools-raub/utils" {
* Must be a file, not a folder. Just `fs.unlink`. * Must be a file, not a folder. Just `fs.unlink`.
*/ */
export const rm: (name: string) => Promise<void>; export const rm: (name: string) => Promise<void>;
} }

194
utils.js
View File

@ -1,195 +1,3 @@
'use strict'; 'use strict';
const fs = require('fs'); module.exports = require('./utils');
// (async) Reads a whole file to string, NOT A Buffer
const read = (name) => new Promise(
(res, rej) => fs.readFile(
name,
(err, data) => (err ? rej(err) : res(data.toString()))
)
);
// (async) Write a file
const write = (name, text) => new Promise(
(res, rej) => fs.writeFile(name, text, (err) => (err ? rej(err) : res()))
);
// (async) Copy a file
const copy = async (src, dest) => {
try {
await new Promise(
(res, rej) => fs.copyFile(src, dest, (err) => (err ? rej(err) : res()))
);
} catch (e) {
if (e.code !== 'EBUSY') {
console.warn('WARNING\n', e);
}
}
};
// (async) Check if a file/folder exists
const exists = (name) => new Promise(
(res) => fs.access(
name,
fs.constants.F_OK,
(err) => res(err ? false : true)
)
);
// (async) Create an empty folder
const mkdir = async (name) => {
if (await exists(name)) {
return;
}
return new Promise(
(res, rej) => fs.mkdir(name, (err) => (err ? rej(err) : res()))
);
};
// (async) Get status on a file
const stat = (name) => new Promise(
(res, rej) => fs.stat(name, (err, stats) => (err ? rej(err) : res(stats)))
);
// (async) Check if the path is a folder
const isDir = async (name) => (await stat(name)).isDirectory();
// (async) Check if the path is a file
const isFile = async (name) => (await stat(name)).isFile();
// Cut the path one folder up
const dirUp = (dir) => dir.replace(/\\/g, '/').split('/').slice(0, -1).join('/');
// (async) Like `mkdir -p`, makes sure a directory exists
const ensuredir = async (dir) => {
if (await exists(dir) && await isDir(dir)) {
return;
}
await ensuredir(dirUp(dir));
await mkdir(dir);
};
// (async) Copy a file, `dest` folder is created if needed
const copysafe = async (src, dest) => {
await ensuredir(dirUp(dest));
await copy(src, dest);
};
// (async) Get file/folder names of the 1st level
const readdir = (name) => new Promise(
(res, rej) => fs.readdir(
name,
(err, dirents) => (err ? rej(err) : res(dirents))
)
);
// (async) Get folder paths (concatenated with input) of the 1st level
const subdirs = async (name) => {
const all = await readdir(name);
const mapped = await Promise.all(all.map((d) => isDir(`${name}/${d}`)));
return all.filter((_, i) => mapped[i]);
};
// (async) Get file paths (concatenated with input) of the 1st level
const subfiles = async (name) => {
const all = await readdir(name);
const mapped = await Promise.all(all.map((d) => isFile(`${name}/${d}`)));
return all.filter((_, i) => mapped[i]).map((f) => `${name}/${f}`);
};
// (async) Get all nested files recursively
// Folder paths are omitted by default
// Order is: shallow-to-deep, each subdirectory lists dirs-then-files.
const traverse = async (name, showDirs = false) => {
const dirs = [];
const stack = [name];
while (stack.length) {
const dir = stack.pop();
dirs.push(dir);
(await subdirs(dir)).forEach((d) => stack.push(`${dir}/${d}`));
}
return (showDirs ? dirs : []).concat(
...(await Promise.all(dirs.map(subfiles)))
);
};
// (async) Copy a folder with all the contained files
const copyall = async (src, dest) => {
const files = (await traverse(src, true)).reverse();
while (files.length) {
const target = files.pop();
const dir = await isDir(target);
if (dir) {
await mkdir(target.replace(src, dest));
} else {
await copy(target, target.replace(src, dest));
}
}
};
// (async) Like `rm -rf`, removes everything recursively
const rmdir = async (name) => {
if (!await exists(name)) {
return;
}
const paths = await traverse(name, true);
while (paths.length) {
const target = paths.pop();
const dir = await isDir(target);
await new Promise(
(res, rej) => fs[dir ? 'rmdir' : 'unlink'](
target,
(err) => (err ? rej(err) : res())
)
);
}
};
// (async) Remove a file. Must be a file, not a folder. Just `fs.unlink`.
const rm = async (name) => {
if (!await exists(name)) {
return;
}
await new Promise(
(res, rej) => fs.unlink(name, (err) => (err ? rej(err) : res()))
);
};
module.exports = {
read,
write,
copy,
exists,
mkdir,
stat,
isDir,
isFile,
dirUp,
ensuredir,
copysafe,
readdir,
subdirs,
subfiles,
traverse,
copyall,
rmdir,
rm,
};

6
utils/action-version.js Normal file
View File

@ -0,0 +1,6 @@
'use strict';
module.exports = {
actionVersion: () => console.log(`version=${process.env.npm_package_version}`),
};

20
utils/action-zip.js Normal file
View File

@ -0,0 +1,20 @@
'use strict';
const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);
const { platform, bin } = require('..');
const actionZip = async () => {
try {
await exec(`cd ${bin} && tar -acf ../${platform}.zip *`);
console.log(`zip=${platform}.zip`);
} catch (error) {
console.error(error);
process.exit(-1);
}
};
module.exports = { actionZip };

View File

@ -1,10 +1,10 @@
'use strict'; 'use strict';
const { copy, exists, mkdir, rm } = require('./utils'); const { copy, exists, mkdir, rm } = require('./files');
const { bin } = require('.'); const { bin } = require('..');
module.exports = async (name) => { const cpbin = async (name) => {
const srcDir = process.cwd().replace(/\\/g, '/'); const srcDir = process.cwd().replace(/\\/g, '/');
if (!await exists(`${srcDir}/build/Release/${name}.node`) ) { if (!await exists(`${srcDir}/build/Release/${name}.node`) ) {
@ -27,3 +27,5 @@ module.exports = async (name) => {
console.log(`The binary "${name}.node" was copied to "${bin}".`); console.log(`The binary "${name}.node" was copied to "${bin}".`);
}; };
module.exports = { cpbin };

View File

@ -1,15 +1,15 @@
'use strict'; 'use strict';
const https = require('https'); const https = require('node:https');
const http = require('http'); const http = require('node:http');
const WritableBuffer = require('./writable-buffer'); const { WritableBuffer } = require('./writable-buffer');
const protocols = { http, https }; const protocols = { http, https };
const download = async (url, count = 1) => { const downloadRecursive = async (url, count = 1) => {
url = url.toLowerCase(); url = url.toLowerCase();
const stream = new WritableBuffer(); const stream = new WritableBuffer();
@ -23,7 +23,7 @@ const download = async (url, count = 1) => {
// Handle redirects // Handle redirects
if ([301, 302, 303, 307].includes(response.statusCode)) { if ([301, 302, 303, 307].includes(response.statusCode)) {
if (count < 5) { if (count < 5) {
return download(response.headers.location, count + 1); return downloadRecursive(response.headers.location, count + 1);
} }
console.log(url); console.log(url);
throw new Error('Error: Too many redirects.'); throw new Error('Error: Too many redirects.');
@ -43,4 +43,6 @@ const download = async (url, count = 1) => {
}); });
}; };
module.exports = (url) => download(url); const download = (url) => downloadRecursive(url);
module.exports = { download };

196
utils/files.js Normal file
View File

@ -0,0 +1,196 @@
'use strict';
const fs = require('node:fs');
// (async) Reads a whole file to string, NOT A Buffer
const read = (name) => new Promise(
(res, rej) => fs.readFile(
name,
(err, data) => (err ? rej(err) : res(data.toString()))
)
);
// (async) Write a file
const write = (name, text) => new Promise(
(res, rej) => fs.writeFile(name, text, (err) => (err ? rej(err) : res()))
);
// (async) Copy a file
const copy = async (src, dest) => {
try {
await new Promise(
(res, rej) => fs.copyFile(src, dest, (err) => (err ? rej(err) : res()))
);
} catch (e) {
if (e.code !== 'EBUSY') {
console.warn('WARNING\n', e);
}
}
};
// (async) Check if a file/folder exists
const exists = (name) => new Promise(
(res) => fs.access(
name,
fs.constants.F_OK,
(err) => res(err ? false : true)
)
);
// (async) Create an empty folder
const mkdir = async (name) => {
if (await exists(name)) {
return;
}
return new Promise(
(res, rej) => fs.mkdir(name, (err) => (err ? rej(err) : res()))
);
};
// (async) Get status on a file
const stat = (name) => new Promise(
(res, rej) => fs.stat(name, (err, stats) => (err ? rej(err) : res(stats)))
);
// (async) Check if the path is a folder
const isDir = async (name) => (await stat(name)).isDirectory();
// (async) Check if the path is a file
const isFile = async (name) => (await stat(name)).isFile();
// Cut the path one folder up
const dirUp = (dir) => dir.replace(/\\/g, '/').split('/').slice(0, -1).join('/');
// (async) Like `mkdir -p`, makes sure a directory exists
const ensuredir = async (dir) => {
if (await exists(dir) && await isDir(dir)) {
return;
}
await ensuredir(dirUp(dir));
await mkdir(dir);
};
// (async) Copy a file, `dest` folder is created if needed
const copysafe = async (src, dest) => {
await ensuredir(dirUp(dest));
await copy(src, dest);
};
// (async) Get file/folder names of the 1st level
const readdir = (name) => new Promise(
(res, rej) => fs.readdir(
name,
(err, dirents) => (err ? rej(err) : res(dirents))
)
);
// (async) Get folder paths (concatenated with input) of the 1st level
const subdirs = async (name) => {
const all = await readdir(name);
const mapped = await Promise.all(all.map((d) => isDir(`${name}/${d}`)));
return all.filter((_, i) => mapped[i]);
};
// (async) Get file paths (concatenated with input) of the 1st level
const subfiles = async (name) => {
const all = await readdir(name);
const mapped = await Promise.all(all.map((d) => isFile(`${name}/${d}`)));
return all.filter((_, i) => mapped[i]).map((f) => `${name}/${f}`);
};
// (async) Get all nested files recursively
// Folder paths are omitted by default
// Order is: shallow-to-deep, each subdirectory lists dirs-then-files.
const traverse = async (name, showDirs = false) => {
const dirs = [];
const stack = [name];
while (stack.length) {
const dir = stack.pop();
dirs.push(dir);
(await subdirs(dir)).forEach((d) => stack.push(`${dir}/${d}`));
}
return (showDirs ? dirs : []).concat(
...(await Promise.all(dirs.map(subfiles)))
);
};
// (async) Copy a folder with all the contained files
const copyall = async (src, dest) => {
const files = (await traverse(src, true)).reverse();
while (files.length) {
const target = files.pop();
const dir = await isDir(target);
if (dir) {
await mkdir(target.replace(src, dest));
} else {
await copy(target, target.replace(src, dest));
}
}
};
// (async) Like `rm -rf`, removes everything recursively
const rmdir = async (name) => {
if (!await exists(name)) {
return;
}
const paths = await traverse(name, true);
while (paths.length) {
const target = paths.pop();
const dir = await isDir(target);
await new Promise(
(res, rej) => fs[dir ? 'rmdir' : 'unlink'](
target,
(err) => (err ? rej(err) : res())
)
);
}
};
// (async) Remove a file. Must be a file, not a folder. Just `fs.unlink`.
const rm = async (name) => {
if (!await exists(name)) {
return;
}
await new Promise(
(res, rej) => fs.unlink(name, (err) => (err ? rej(err) : res()))
);
};
module.exports = {
read,
write,
copy,
exists,
mkdir,
stat,
isDir,
isFile,
dirUp,
ensuredir,
copysafe,
readdir,
subdirs,
subfiles,
traverse,
copyall,
rmdir,
rm,
};

12
utils/index.js Normal file
View File

@ -0,0 +1,12 @@
'use strict';
module.exports = {
...require('action-version'),
...require('action-zip'),
...require('cpbin'),
...require('download'),
...require('files'),
...require('install'),
...require('writable-buffer'),
};

View File

@ -1,19 +1,12 @@
'use strict'; 'use strict';
const https = require('https'); const https = require('node:https');
const http = require('http'); const http = require('node:http');
const fs = require('fs'); const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);
let AdmZip = null; const { bin, platform } = require('..');
try { const { mkdir, rmdir, rm } = require('./files');
AdmZip = require('adm-zip');
} catch (ex) {
console.error('The `install` script requires `adm-zip` module to be installed.');
process.exit(1);
}
const { bin, platform } = require('.');
const { mkdir, rm } = require('./utils');
const protocols = { http, https }; const protocols = { http, https };
@ -26,7 +19,7 @@ const onError = (msg) => {
const zipPath = `${bin}/${bin}.zip`; const zipPath = `${bin}/${bin}.zip`;
const install = async (url, count = 1) => { const installRecursive = async (url, count = 1) => {
try { try {
const proto = protocols[url.match(/^https?/)[0]]; const proto = protocols[url.match(/^https?/)[0]];
@ -39,7 +32,7 @@ const install = async (url, count = 1) => {
// Handle redirects // Handle redirects
if ([301, 302, 303, 307].includes(response.statusCode)) { if ([301, 302, 303, 307].includes(response.statusCode)) {
if (count < 5) { if (count < 5) {
return install(response.headers.location, count + 1); return installRecursive(response.headers.location, count + 1);
} }
console.log(url); console.log(url);
throw new Error('Error: Too many redirects.'); throw new Error('Error: Too many redirects.');
@ -51,27 +44,21 @@ const install = async (url, count = 1) => {
throw new Error(`Response status was ${response.statusCode}`); throw new Error(`Response status was ${response.statusCode}`);
} }
await rmdir(bin);
await mkdir(bin); await mkdir(bin);
await new Promise((res, rej) => { await exec(`tar -xzvf ${platform}.zip --directory ${bin}`);
const zipWriter = fs.createWriteStream(zipPath);
zipWriter.on('error', (err) => rej(err));
zipWriter.on('finish', () => res());
response.pipe(zipWriter);
});
const zip = new AdmZip(zipPath);
zip.extractAllTo(bin, true);
await rm(zipPath); await rm(zipPath);
} catch (ex) { } catch (ex) {
onError(ex.message); onError(ex.message);
} }
}; };
module.exports = (folder) => { const install = (folder) => {
const url = `${folder}/${platform}.zip`; const url = `${folder}/${platform}.zip`;
install(url).then(); installRecursive(url).then();
}; };
module.exports = { install };

19
utils/utils.test.js Normal file
View File

@ -0,0 +1,19 @@
'use strict';
const utils = require('.');
describe('utils.js', () => {
const methods = [
'install', 'cpbin', 'download', 'read', 'write', 'copy', 'exists',
'mkdir', 'stat', 'isDir', 'isFile', 'dirUp', 'ensuredir', 'copysafe',
'readdir', 'subdirs', 'subfiles', 'traverse', 'copyall',
'rmdir', 'rm', 'WritableBuffer',
];
methods.forEach((name) => {
it('is a function', () => {
expect(typeof utils[name]).toBe('function');
});
});
});

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const { Writable } = require('stream'); const { Writable } = require('node:stream');
const CHUNK_SIZE = 1024; const CHUNK_SIZE = 1024;
@ -53,4 +53,4 @@ class WritableBuffer extends Writable {
} }
} }
module.exports = WritableBuffer; module.exports = { WritableBuffer };

22
writable-buffer.d.ts vendored
View File

@ -1,22 +0,0 @@
import type { Writable } from 'stream';
declare module "addon-tools-raub/writable-buffer" {
/**
* WritableBuffer
* A [Writable](https://nodejs.org/api/stream.html#stream_writable_streams)
* stream buffer, that is stored in-memory and can be fully
* obtained when writing was finished. It is equivalent to stream-writing
* a temporary file and then reading it into a `Buffer`.
*/
export class WritableBuffer extends Writable {
constructor();
/**
* Get the downloaded data
* Use `stream.get()` to obtain the data when writing was finished
*/
get(): Buffer;
}
export = WritableBuffer;
}