Fix TS
This commit is contained in:
parent
4b98f5f435
commit
cca802d932
152
README.md
152
README.md
|
@ -33,171 +33,35 @@ additional snippets follow the links below.
|
||||||
## index.js
|
## index.js
|
||||||
|
|
||||||
Main exports for cross-platform addon configuration.
|
Main exports for cross-platform addon configuration.
|
||||||
|
See [TypeScript definitions](/index.d.ts).
|
||||||
```
|
|
||||||
export const paths: (dir: string) => Readonly<{
|
|
||||||
bin: string;
|
|
||||||
include: string;
|
|
||||||
}>;
|
|
||||||
export const bin: string;
|
|
||||||
export const platform: string;
|
|
||||||
export const include: string;
|
|
||||||
```
|
|
||||||
|
|
||||||
* `paths` - Returns a set of platform dependent paths depending on
|
|
||||||
input `dir`.
|
|
||||||
* `bin` - platform binary directory absolute path.
|
|
||||||
* `include` - include directory for this `dir`.
|
|
||||||
* `bin` - platform-dependent binary directory name.
|
|
||||||
* `platform` - platform name: `'windows', 'linux', 'osx'`.
|
|
||||||
* `include` - both `'addon-tools-raub'` and `'node-addon-api'` include paths.
|
|
||||||
Use with `node -p` through list context command expansion `<!@(...)`.
|
|
||||||
|
|
||||||
|
|
||||||
## download.js
|
## download.js
|
||||||
|
|
||||||
Downloads a file into the memory, **HTTP** or **HTTPS**.
|
Downloads a file into the memory, **HTTP** or **HTTPS**.
|
||||||
|
See [TypeScript definitions](/downloads.d.ts).
|
||||||
```
|
|
||||||
declare const download: (url: string) => Promise<Buffer>;
|
|
||||||
export default download;
|
|
||||||
```
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
```
|
|
||||||
download(srcUrl).then(
|
|
||||||
data => useData(data),
|
|
||||||
err => emit('error', err)
|
|
||||||
);
|
|
||||||
// or
|
|
||||||
const data = await download(srcUrl);
|
|
||||||
useData(data);
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## cpbin.js
|
## cpbin.js
|
||||||
|
|
||||||
Copies the addon binary from `src/build/Release` to the platform folder.
|
Downloads a file into the memory, **HTTP** or **HTTPS**.
|
||||||
|
See [TypeScript definitions](/cpbin.d.ts).
|
||||||
```
|
|
||||||
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.
|
|
||||||
|
|
||||||
|
|
||||||
## install.js
|
## install.js
|
||||||
|
|
||||||
Downloads and unzips the platform specific binary for the calling package.
|
Downloads and unzips the platform specific binary for the calling package.
|
||||||
|
See [TypeScript definitions](/install.d.ts).
|
||||||
```
|
|
||||||
declare const install: (folder: string) => void;
|
|
||||||
export default install;
|
|
||||||
```
|
|
||||||
|
|
||||||
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,
|
|
||||||
here `process.env.npm_package_config_install` is taken
|
|
||||||
([automatically](https://docs.npmjs.com/misc/config#per-package-config-settings))
|
|
||||||
from **package.json**:
|
|
||||||
|
|
||||||
```
|
|
||||||
"config": {
|
|
||||||
"install": "v2.0.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"postinstall": "node install"
|
|
||||||
},
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## writable-buffer.js
|
## writable-buffer.js
|
||||||
|
|
||||||
A [Writable](https://nodejs.org/api/stream.html#stream_writable_streams)
|
A [Writable](https://nodejs.org/api/stream.html#stream_writable_streams)
|
||||||
stream buffer, that is stored in-memory and can be fully
|
stream buffer.
|
||||||
obtained when writing was finished. It is equivalent to stream-writing
|
See [TypeScript definitions](/writable-buffer.d.ts).
|
||||||
a temporary file and then reading it into a `Buffer`.
|
|
||||||
|
|
||||||
```
|
|
||||||
import type { Writable } from 'stream';
|
|
||||||
export class WritableBuffer extends Writable {
|
|
||||||
constructor();
|
|
||||||
get(): Buffer;
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
Use `stream.get()` to obtain the data when writing was finished:
|
|
||||||
```
|
|
||||||
const stream = new WritableBuffer();
|
|
||||||
// ...
|
|
||||||
sourceStream.pipe(stream);
|
|
||||||
sourceStream.on('end', () => useData(stream.get()));
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## utils.js
|
## utils.js
|
||||||
|
|
||||||
Async `fs` based helpers for common addon-related file operations.
|
Async `fs` based helpers for common addon-related file operations.
|
||||||
|
See [TypeScript definitions](/writable-buffer.d.ts).
|
||||||
```
|
|
||||||
import type { Stats } from 'fs';
|
|
||||||
export const read: (name: string) => Promise<string>;
|
|
||||||
export const write: (name: string, text: string) => Promise<void>;
|
|
||||||
export const copy: (src: string, dest: string) => Promise<void>;
|
|
||||||
export const exists: (name: string) => Promise<boolean>;
|
|
||||||
export const mkdir: (name: string) => Promise<void>;
|
|
||||||
export const stat: (name: string) => Promise<Stats>;
|
|
||||||
export const isDir: (name: string) => Promise<boolean>;
|
|
||||||
export const isFile: (name: string) => Promise<boolean>;
|
|
||||||
export const dirUp: (dir: string) => string;
|
|
||||||
export const ensuredir: (dir: string) => Promise<void>;
|
|
||||||
export const copysafe: (src: string, dest: string) => Promise<void>;
|
|
||||||
export const readdir: (src: string, dest: string) => Promise<ReadonlyArray<string>>;
|
|
||||||
export const subdirs: (name: string) => Promise<ReadonlyArray<string>>;
|
|
||||||
export const subfiles: (name: string) => Promise<ReadonlyArray<string>>;
|
|
||||||
export const traverse: (name: string, showDirs?: boolean) => Promise<ReadonlyArray<string>>;
|
|
||||||
export const copyall: (src: string, dest: string) => Promise<void>;
|
|
||||||
export const rmdir: (name: string) => Promise<void>;
|
|
||||||
export const rm: (name: string) => Promise<void>;
|
|
||||||
```
|
|
||||||
|
|
||||||
* `read` - (async) Reads a whole file to string, NOT a Buffer.
|
|
||||||
* `write` - (async) Write a file.
|
|
||||||
* `copy` - (async) Copy a file.
|
|
||||||
* `exists` - (async) Check if a file/folder exists.
|
|
||||||
* `mkdir` - (async) Create an empty folder.
|
|
||||||
* `stat` - (async) Get status on a file.
|
|
||||||
* `isDir` - (async) Check if the path is a folder.
|
|
||||||
* `isFile` - (async) Check if the path is a file.
|
|
||||||
* `dirUp` - Cut the path one folder up.
|
|
||||||
* `ensuredir` - (async) Like `mkdir -p`, makes sure a directory exists.
|
|
||||||
* `copysafe` - (async) Copy a file, `dest` folder is created if needed.
|
|
||||||
* `readdir` - (async) Get file/folder names of the 1st level.
|
|
||||||
* `subdirs` - (async) Get folder paths (concatenated with input) of the 1st level.
|
|
||||||
* `subfiles` - (async) Get file paths (concatenated with input) of the 1st level.
|
|
||||||
* `traverse` - (async) Get all nested files recursively.
|
|
||||||
* `copyall` - (async) Copy a folder with all the contained files.
|
|
||||||
* `rmdir` - (async) Like `rm -rf`, removes everything recursively.
|
|
||||||
* `rm` - (async) Remove a file. Must be a file, not a folder. Just `fs.unlink`.
|
|
||||||
|
|
|
@ -1,2 +1,19 @@
|
||||||
declare const cpbin: (name: string) => Promise<void>;
|
declare module "addon-tools-raub/cpbin" {
|
||||||
export default 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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,2 +1,19 @@
|
||||||
declare const download: (url: string) => Promise<Buffer>;
|
declare module "addon-tools-raub/download" {
|
||||||
export default 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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,34 @@
|
||||||
export const paths: (dir: string) => Readonly<{
|
declare module "addon-tools-raub" {
|
||||||
bin: string;
|
/**
|
||||||
include: string;
|
* Addon paths
|
||||||
}>;
|
* Returns a set of platform dependent paths depending on input dir
|
||||||
export const bin: string;
|
*/
|
||||||
export const platform: string;
|
export const paths: (dir: string) => Readonly<{
|
||||||
export const include: string;
|
/**
|
||||||
|
* Path to binaries
|
||||||
|
* Platform binary directory absolute path
|
||||||
|
*/
|
||||||
|
bin: string;
|
||||||
|
/**
|
||||||
|
* Path to include
|
||||||
|
* Include directory for this dir
|
||||||
|
*/
|
||||||
|
include: string;
|
||||||
|
}>;
|
||||||
|
/**
|
||||||
|
* Binary folder name
|
||||||
|
* Platform-dependent binary directory name
|
||||||
|
*/
|
||||||
|
export const bin: string;
|
||||||
|
/**
|
||||||
|
* Platform name
|
||||||
|
* One of: 'windows', 'linux', 'osx'
|
||||||
|
*/
|
||||||
|
export const platform: string;
|
||||||
|
/**
|
||||||
|
* Main include directories
|
||||||
|
* Both 'addon-tools-raub' and 'node-addon-api' include paths.
|
||||||
|
* Use with node -p through list context command expansion <!@(...).
|
||||||
|
*/
|
||||||
|
export const include: string;
|
||||||
|
}
|
||||||
|
|
|
@ -1,2 +1,24 @@
|
||||||
declare const install: (folder: string) => void;
|
declare module "addon-tools-raub/install" {
|
||||||
export default 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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "addon-tools-raub",
|
"name": "addon-tools-raub",
|
||||||
"version": "5.3.0",
|
"version": "5.3.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -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": "5.3.0",
|
"version": "5.3.2",
|
||||||
"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",
|
||||||
|
|
|
@ -1,75 +1,105 @@
|
||||||
import type { Stats } from 'fs';
|
import type { Stats } from 'fs';
|
||||||
|
|
||||||
|
declare module "addon-tools-raub/utils" {
|
||||||
// (async) Reads a whole file to string, NOT A Buffer
|
/**
|
||||||
export const read: (name: string) => Promise<string>;
|
* (async) Read a file
|
||||||
|
* Reads a whole file to string, NOT A Buffer
|
||||||
|
*/
|
||||||
// (async) Write a file
|
export const read: (name: string) => Promise<string>;
|
||||||
export const write: (name: string, text: string) => Promise<void>;
|
|
||||||
|
/**
|
||||||
|
* (async) Write a file
|
||||||
// (async) Copy a file
|
*/
|
||||||
export const copy: (src: string, dest: string) => Promise<void>;
|
export const write: (name: string, text: string) => Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
// (async) Check if a file/folder exists
|
* (async) Copy a file
|
||||||
export const exists: (name: string) => Promise<boolean>;
|
*/
|
||||||
|
export const copy: (src: string, dest: string) => Promise<void>;
|
||||||
|
|
||||||
// (async) Create an empty folder
|
/**
|
||||||
export const mkdir: (name: string) => Promise<void>;
|
* (async) Check if a file/folder exists
|
||||||
|
*/
|
||||||
|
export const exists: (name: string) => Promise<boolean>;
|
||||||
// (async) Get status on a file
|
|
||||||
export const stat: (name: string) => Promise<Stats>;
|
/**
|
||||||
|
* (async) Create an empty folder
|
||||||
|
*/
|
||||||
// (async) Check if the path is a folder
|
export const mkdir: (name: string) => Promise<void>;
|
||||||
export const isDir: (name: string) => Promise<boolean>;
|
|
||||||
|
/**
|
||||||
|
* (async) Get status on a file
|
||||||
// (async) Check if the path is a file
|
*/
|
||||||
export const isFile: (name: string) => Promise<boolean>;
|
export const stat: (name: string) => Promise<Stats>;
|
||||||
|
|
||||||
|
/**
|
||||||
// Cut the path one folder up
|
* (async) Check if the path is a folder
|
||||||
export const dirUp: (dir: string) => string;
|
*/
|
||||||
|
export const isDir: (name: string) => Promise<boolean>;
|
||||||
|
|
||||||
// (async) Like `mkdir -p`, makes sure a directory exists
|
/**
|
||||||
export const ensuredir: (dir: string) => Promise<void>;
|
* (async) Check if the path is a file
|
||||||
|
*/
|
||||||
|
export const isFile: (name: string) => Promise<boolean>;
|
||||||
// (async) Copy a file, `dest` folder is created if needed
|
|
||||||
export const copysafe: (src: string, dest: string) => Promise<void>;
|
/**
|
||||||
|
* Cut the path one folder up
|
||||||
|
*/
|
||||||
// (async) Get file/folder names of the 1st level
|
export const dirUp: (dir: string) => string;
|
||||||
export const readdir: (src: string, dest: string) => Promise<ReadonlyArray<string>>;
|
|
||||||
|
/**
|
||||||
|
* (async) Create a directory
|
||||||
// (async) Get folder paths (concatenated with input) of the 1st level
|
* Like `mkdir -p`, makes sure a directory exists
|
||||||
export const subdirs: (name: string) => Promise<ReadonlyArray<string>>;
|
*/
|
||||||
|
export const ensuredir: (dir: string) => Promise<void>;
|
||||||
|
|
||||||
// (async) Get file paths (concatenated with input) of the 1st level
|
/**
|
||||||
export const subfiles: (name: string) => Promise<ReadonlyArray<string>>;
|
* (async) Copy a file
|
||||||
|
* Copy a file, `dest` folder is created if needed
|
||||||
|
*/
|
||||||
// (async) Get all nested files recursively
|
export const copysafe: (src: string, dest: string) => Promise<void>;
|
||||||
// Folder paths are omitted by default
|
|
||||||
// Order is: shallow-to-deep, each subdirectory lists dirs-then-files.
|
/**
|
||||||
export const traverse: (name: string, showDirs?: boolean) => Promise<ReadonlyArray<string>>;
|
* (async) Read a directory
|
||||||
|
* Get file/folder names of the 1st level
|
||||||
|
*/
|
||||||
// (async) Copy a folder with all the contained files
|
export const readdir: (src: string, dest: string) => Promise<ReadonlyArray<string>>;
|
||||||
export const copyall: (src: string, dest: string) => Promise<void>;
|
|
||||||
|
/**
|
||||||
|
* (async) List subdirectories
|
||||||
// (async) Like `rm -rf`, removes everything recursively
|
* Get folder paths (concatenated with input) of the 1st level
|
||||||
export const rmdir: (name: string) => Promise<void>;
|
*/
|
||||||
|
export const subdirs: (name: string) => Promise<ReadonlyArray<string>>;
|
||||||
|
|
||||||
// (async) Remove a file. Must be a file, not a folder. Just `fs.unlink`.
|
/**
|
||||||
export const rm: (name: string) => Promise<void>;
|
* (async) List nested files
|
||||||
|
* Get file paths (concatenated with input) of the 1st level
|
||||||
|
*/
|
||||||
|
export const subfiles: (name: string) => Promise<ReadonlyArray<string>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (async) Get all nested files recursively
|
||||||
|
* Folder paths are omitted by default.
|
||||||
|
* Order is: shallow-to-deep, each subdirectory lists dirs-then-files.
|
||||||
|
*/
|
||||||
|
export const traverse: (name: string, showDirs?: boolean) => Promise<ReadonlyArray<string>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (async) Copy a directory
|
||||||
|
* Copy a folder with all the contained files
|
||||||
|
*/
|
||||||
|
export const copyall: (src: string, dest: string) => Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (async) Remove a directory
|
||||||
|
* Like `rm -rf`, removes everything recursively
|
||||||
|
*/
|
||||||
|
export const rmdir: (name: string) => Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (async) Remove a file
|
||||||
|
* Must be a file, not a folder. Just `fs.unlink`.
|
||||||
|
*/
|
||||||
|
export const rm: (name: string) => Promise<void>;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
import type { Writable } from 'stream';
|
import type { Writable } from 'stream';
|
||||||
|
|
||||||
export class WritableBuffer extends Writable {
|
|
||||||
constructor();
|
declare module "addon-tools-raub/writable-buffer" {
|
||||||
get(): 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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue