This commit is contained in:
Luis Blanco 2023-01-04 17:10:00 +04:00
parent 9852e1e789
commit f9f3ac2a23
7 changed files with 31 additions and 27 deletions

View File

@ -38,7 +38,7 @@ JavaScript helpers for Node.js addon development. The short list of helpers:
'install', 'cpbin', 'download', 'read', 'write', 'copy', 'exists',
'mkdir', 'stat', 'isDir', 'isFile', 'dirUp', 'ensuredir', 'copysafe',
'readdir', 'subdirs', 'subfiles', 'traverse', 'copyall',
'rmdir', 'rm', 'WritableBuffer', 'actionZip',
'rmdir', 'rm', 'WritableBuffer', 'actionPack',
```

View File

@ -6,7 +6,7 @@
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()}.zip`
append any given URL with `/${getPlatform()}.gzip`
In **package.json**:
@ -23,7 +23,7 @@ In **package.json**:
```
Create the **install.js** file, see `install` in [index.d.ts](/index.d.ts).
**Addon Tools** will unzip (using **tar**) the downloaded file into the platform binary
**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:
@ -43,14 +43,14 @@ directory. E.g. on Windows it will be **bin-windows**.
```
Publishing binaries is done by attaching a zipped platform folder to a GitHub
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 zipped set of files/folders.
from **Addon Tools** is that it should be a GZIPped set of files/folders.
### GYP Variables

20
index.d.ts vendored
View File

@ -1,3 +1,7 @@
import type { Stats } from 'node:fs';
import type { Writable } from 'node:stream';
declare module "addon-tools-raub" {
/**
* Get the internal paths for an addon
@ -38,7 +42,7 @@ declare module "addon-tools-raub" {
/**
* Install binaries
* Downloads and unzips the platform specific binary for the calling package.
* Downloads and unpacks 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:
*
@ -78,20 +82,20 @@ declare module "addon-tools-raub" {
/**
* Package version for GitHub Actions
* Example of `actionZip` usage in **Github Actions**:
* Packs binaries into GZIP
* Example of `actionPack` usage in **Github Actions**:
*
* ```
* - name: Zip Files
* id: zip-files
* run: node -p "require('addon-tools-raub').actionZip()" >> $GITHUB_OUTPUT
* - name: Pack Files
* id: pack-files
* run: node -p "require('addon-tools-raub').actionPack()" >> $GITHUB_OUTPUT
* - name: Store Binaries
* uses: softprops/action-gh-release@v1
* with:
* files: ${{ steps.zip-files.outputs.zip }}
* files: ${{ steps.pack-files.outputs.pack }}
* ```
*/
export const actionZip: () => void;
export const actionPack: () => void;
/**

View File

@ -6,10 +6,10 @@ const exec = util.promisify(require('node:child_process').exec);
const { getPlatform, getBin } = require('../include');
const actionZip = async () => {
const actionPack = async () => {
try {
await exec(`cd ${getBin()} && tar -acf ../${getPlatform()}.zip *`);
console.log(`zip=${getPlatform()}.zip`);
await exec(`cd ${getBin()} && tar -acf ../${getPlatform()}.gzip *`);
console.log(`pack=${getPlatform()}.gzip`);
} catch (error) {
console.error(error);
process.exit(-1);
@ -17,4 +17,4 @@ const actionZip = async () => {
};
module.exports = { actionZip };
module.exports = { actionPack };

View File

@ -3,7 +3,7 @@
module.exports = Object.assign(
{},
require('./action-zip'),
require('./action-pack'),
require('./cpbin'),
require('./download'),
require('./files'),

View File

@ -47,18 +47,18 @@ const installRecursive = async (url, count = 1) => {
await rmdir(getBin());
await mkdir(getBin());
const zipPath = `${getBin()}/${getPlatform()}.zip`;
const packPath = `${getBin()}/${getPlatform()}.gzip`;
await new Promise((res, rej) => {
const zipWriter = fs.createWriteStream(zipPath);
zipWriter.on('error', (err) => rej(err));
zipWriter.on('finish', () => res());
response.pipe(zipWriter);
const packWriter = fs.createWriteStream(packPath);
packWriter.on('error', (err) => rej(err));
packWriter.on('finish', () => res());
response.pipe(packWriter);
});
await exec(`tar -xzvf ${zipPath} --directory ${getBin()}`);
await exec(`tar -xzf ${packPath} --directory ${getBin()}`);
await rm(zipPath);
await rm(packPath);
} catch (ex) {
onError(ex.message);
}
@ -66,7 +66,7 @@ const installRecursive = async (url, count = 1) => {
const install = (folder) => {
const url = `${folder}/${getPlatform()}.zip`;
const url = `${folder}/${getPlatform()}.gzip`;
installRecursive(url).then();
};

View File

@ -8,7 +8,7 @@ describe('AT / utils', () => {
'install', 'cpbin', 'download', 'read', 'write', 'copy', 'exists',
'mkdir', 'stat', 'isDir', 'isFile', 'dirUp', 'ensuredir', 'copysafe',
'readdir', 'subdirs', 'subfiles', 'traverse', 'copyall',
'rmdir', 'rm', 'WritableBuffer', 'actionZip',
'rmdir', 'rm', 'WritableBuffer', 'actionPack',
];
methods.forEach((name) => {