diff --git a/lib/index.js b/lib/index.js index 3d18329..f81fa04 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,7 +3,15 @@ const path = require('path'); const BinWrapper = require('bin-wrapper'); const pkg = require('../package.json'); -const url = `https://raw.githubusercontent.com/imagemin/jpegtran-bin/v${pkg.version}/vendor/`; +// The default location that missing binaries are fetched from +const defaultDownloadUrl = 'https://raw.githubusercontent.com/imagemin/jpegtran-bin/'; +const defaultDownloadDir = 'vendor/'; + +// If we detect that a different download location has been set in the environment shall use it over the default +const downloadUrl = process.env.IMAGEMIN__JPEGTRAN_BIN__MIRROR_URL ? process.env.IMAGEMIN__JPEGTRAN_BIN__MIRROR_URL : defaultDownloadUrl; +const downloadDir = process.env.IMAGEMIN__JPEGTRAN_BIN__CUSTOM_DIR ? process.env.IMAGEMIN__JPEGTRAN_BIN__CUSTOM_DIR : defaultDownloadDir; + +const url = `${downloadUrl}v${pkg.version}/${downloadDir}`; module.exports = new BinWrapper() .src(`${url}macos/jpegtran`, 'darwin') diff --git a/readme.md b/readme.md index fc3b260..ff355ea 100644 --- a/readme.md +++ b/readme.md @@ -11,6 +11,31 @@ You probably want [`imagemin-jpegtran`](https://github.com/imagemin/imagemin-jpe $ npm install --save jpegtran-bin ``` +### Customizing the Download Mirror + +By default this package will fetch the libjpeg-turbo binary from this repository during install, if you need to customise this behavour it can be overridden using enviroment variables. + +The following options are available: + +Environment Variable | Description | Default +-----------------------------------| -------------------------------------| -------------------------------------------------------- +IMAGEMIN__JPEGTRAN_BIN__MIRROR_URL | Specifies the location of the mirror | https://raw.githubusercontent.com/imagemin/jpegtran-bin/ +IMAGEMIN__JPEGTRAN_BIN__CUSTOM_DIR | Specifies a custom folder if needed | vendor/ + +The resulting mirror location is composed as follows: + +```js +url = IMAGEMIN__JPEGTRAN_BIN__MIRROR_URL + {library version} + IMAGEMIN__JPEGTRAN_BIN__CUSTOM_DIR + {platform information} +``` + +For instance with the below set: + +``` +IMAGEMIN__JPEGTRAN_BIN__MIRROR_URL = 'https://www.example.com/private/mirror/' +IMAGEMIN__JPEGTRAN_BIN__CUSTOM_DIR = 'binaries/' +``` + +Would result in `https://www.example.com/private/mirror/v4.0.0/binaries/win/x64/jpegtran.exe` on 64 bit Windows. ## Usage