Use GZIP
This commit is contained in:
parent
9852e1e789
commit
f9f3ac2a23
|
@ -38,7 +38,7 @@ JavaScript helpers for Node.js addon development. The short list of helpers:
|
||||||
'install', 'cpbin', 'download', 'read', 'write', 'copy', 'exists',
|
'install', 'cpbin', 'download', 'read', 'write', 'copy', 'exists',
|
||||||
'mkdir', 'stat', 'isDir', 'isFile', 'dirUp', 'ensuredir', 'copysafe',
|
'mkdir', 'stat', 'isDir', 'isFile', 'dirUp', 'ensuredir', 'copysafe',
|
||||||
'readdir', 'subdirs', 'subfiles', 'traverse', 'copyall',
|
'readdir', 'subdirs', 'subfiles', 'traverse', 'copyall',
|
||||||
'rmdir', 'rm', 'WritableBuffer', 'actionZip',
|
'rmdir', 'rm', 'WritableBuffer', 'actionPack',
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
In **package.json** use the `"postinstall"` script to download the libraries.
|
In **package.json** use the `"postinstall"` script to download the libraries.
|
||||||
For example the following structure might work. Note that **Addon Tools** will
|
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**:
|
In **package.json**:
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ In **package.json**:
|
||||||
```
|
```
|
||||||
|
|
||||||
Create the **install.js** file, see `install` in [index.d.ts](/index.d.ts).
|
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**.
|
directory. E.g. on Windows it will be **bin-windows**.
|
||||||
|
|
||||||
* For a dependency package:
|
* 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
|
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
|
contain the final binaries. The tag of the release should be the same as in
|
||||||
**install.js**.
|
**install.js**.
|
||||||
|
|
||||||
> NOTE: You can publish your binaries to anywhere, not necessarily GitHub.
|
> NOTE: You can publish your binaries to anywhere, not necessarily GitHub.
|
||||||
Just tweak **YOUR install.js** script as appropriate. The only limitation
|
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
|
### GYP Variables
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
import type { Stats } from 'node:fs';
|
||||||
|
import type { Writable } from 'node:stream';
|
||||||
|
|
||||||
|
|
||||||
declare module "addon-tools-raub" {
|
declare module "addon-tools-raub" {
|
||||||
/**
|
/**
|
||||||
* Get the internal paths for an addon
|
* Get the internal paths for an addon
|
||||||
|
@ -38,7 +42,7 @@ declare module "addon-tools-raub" {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install binaries
|
* 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
|
* To use it, create a new script for your package, which may as well be named
|
||||||
* **install.js**, with the following content:
|
* **install.js**, with the following content:
|
||||||
*
|
*
|
||||||
|
@ -78,20 +82,20 @@ declare module "addon-tools-raub" {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Package version for GitHub Actions
|
* Packs binaries into GZIP
|
||||||
* Example of `actionZip` usage in **Github Actions**:
|
* Example of `actionPack` usage in **Github Actions**:
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* - name: Zip Files
|
* - name: Pack Files
|
||||||
* id: zip-files
|
* id: pack-files
|
||||||
* run: node -p "require('addon-tools-raub').actionZip()" >> $GITHUB_OUTPUT
|
* run: node -p "require('addon-tools-raub').actionPack()" >> $GITHUB_OUTPUT
|
||||||
* - name: Store Binaries
|
* - name: Store Binaries
|
||||||
* uses: softprops/action-gh-release@v1
|
* uses: softprops/action-gh-release@v1
|
||||||
* with:
|
* with:
|
||||||
* files: ${{ steps.zip-files.outputs.zip }}
|
* files: ${{ steps.pack-files.outputs.pack }}
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export const actionZip: () => void;
|
export const actionPack: () => void;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,10 +6,10 @@ const exec = util.promisify(require('node:child_process').exec);
|
||||||
const { getPlatform, getBin } = require('../include');
|
const { getPlatform, getBin } = require('../include');
|
||||||
|
|
||||||
|
|
||||||
const actionZip = async () => {
|
const actionPack = async () => {
|
||||||
try {
|
try {
|
||||||
await exec(`cd ${getBin()} && tar -acf ../${getPlatform()}.zip *`);
|
await exec(`cd ${getBin()} && tar -acf ../${getPlatform()}.gzip *`);
|
||||||
console.log(`zip=${getPlatform()}.zip`);
|
console.log(`pack=${getPlatform()}.gzip`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
|
@ -17,4 +17,4 @@ const actionZip = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = { actionZip };
|
module.exports = { actionPack };
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
module.exports = Object.assign(
|
module.exports = Object.assign(
|
||||||
{},
|
{},
|
||||||
require('./action-zip'),
|
require('./action-pack'),
|
||||||
require('./cpbin'),
|
require('./cpbin'),
|
||||||
require('./download'),
|
require('./download'),
|
||||||
require('./files'),
|
require('./files'),
|
||||||
|
|
|
@ -47,18 +47,18 @@ const installRecursive = async (url, count = 1) => {
|
||||||
await rmdir(getBin());
|
await rmdir(getBin());
|
||||||
await mkdir(getBin());
|
await mkdir(getBin());
|
||||||
|
|
||||||
const zipPath = `${getBin()}/${getPlatform()}.zip`;
|
const packPath = `${getBin()}/${getPlatform()}.gzip`;
|
||||||
|
|
||||||
await new Promise((res, rej) => {
|
await new Promise((res, rej) => {
|
||||||
const zipWriter = fs.createWriteStream(zipPath);
|
const packWriter = fs.createWriteStream(packPath);
|
||||||
zipWriter.on('error', (err) => rej(err));
|
packWriter.on('error', (err) => rej(err));
|
||||||
zipWriter.on('finish', () => res());
|
packWriter.on('finish', () => res());
|
||||||
response.pipe(zipWriter);
|
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) {
|
} catch (ex) {
|
||||||
onError(ex.message);
|
onError(ex.message);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ const installRecursive = async (url, count = 1) => {
|
||||||
|
|
||||||
|
|
||||||
const install = (folder) => {
|
const install = (folder) => {
|
||||||
const url = `${folder}/${getPlatform()}.zip`;
|
const url = `${folder}/${getPlatform()}.gzip`;
|
||||||
installRecursive(url).then();
|
installRecursive(url).then();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe('AT / utils', () => {
|
||||||
'install', 'cpbin', 'download', 'read', 'write', 'copy', 'exists',
|
'install', 'cpbin', 'download', 'read', 'write', 'copy', 'exists',
|
||||||
'mkdir', 'stat', 'isDir', 'isFile', 'dirUp', 'ensuredir', 'copysafe',
|
'mkdir', 'stat', 'isDir', 'isFile', 'dirUp', 'ensuredir', 'copysafe',
|
||||||
'readdir', 'subdirs', 'subfiles', 'traverse', 'copyall',
|
'readdir', 'subdirs', 'subfiles', 'traverse', 'copyall',
|
||||||
'rmdir', 'rm', 'WritableBuffer', 'actionZip',
|
'rmdir', 'rm', 'WritableBuffer', 'actionPack',
|
||||||
];
|
];
|
||||||
|
|
||||||
methods.forEach((name) => {
|
methods.forEach((name) => {
|
||||||
|
|
Loading…
Reference in New Issue