diff --git a/README.md b/README.md index cb2e08a..11309b6 100644 --- a/README.md +++ b/README.md @@ -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', ``` diff --git a/include/snippets.md b/include/snippets.md index 7090f33..79ee638 100644 --- a/include/snippets.md +++ b/include/snippets.md @@ -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 diff --git a/index.d.ts b/index.d.ts index 578b062..c2abcae 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; /** diff --git a/utils/action-zip.js b/utils/action-pack.js similarity index 57% rename from utils/action-zip.js rename to utils/action-pack.js index 80012f0..294fc56 100644 --- a/utils/action-zip.js +++ b/utils/action-pack.js @@ -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 }; diff --git a/utils/index.js b/utils/index.js index 8d00f0f..72d5296 100644 --- a/utils/index.js +++ b/utils/index.js @@ -3,7 +3,7 @@ module.exports = Object.assign( {}, - require('./action-zip'), + require('./action-pack'), require('./cpbin'), require('./download'), require('./files'), diff --git a/utils/install.js b/utils/install.js index 458ac2c..25d6ce9 100644 --- a/utils/install.js +++ b/utils/install.js @@ -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(); }; diff --git a/utils/utils.test.js b/utils/utils.test.js index 14159dc..9923c7c 100644 --- a/utils/utils.test.js +++ b/utils/utils.test.js @@ -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) => {