Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline install as default #103

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
'use strict';
const path = require('path');
const log = require('logalot');
const binBuild = require('bin-build');
const BinWrapper = require('bin-wrapper');
const pkg = require('../package.json');

const url = `https://raw.githubusercontent.com/imagemin/pngquant-bin/v${pkg.version}/vendor/`;
const dest = path.resolve(__dirname, '../vendor');

module.exports = new BinWrapper()
.src(`${url}macos/pngquant`, 'darwin')
.src(`${url}linux/x86/pngquant`, 'linux', 'x86')
.src(`${url}linux/x64/pngquant`, 'linux', 'x64')
.src(`${url}freebsd/x64/pngquant`, 'freebsd', 'x64')
.src(`${url}win/pngquant.exe`, 'win32')
.dest(path.resolve(__dirname, '../vendor'))
.use(process.platform === 'win32' ? 'pngquant.exe' : 'pngquant');
module.exports = (() => {
const libpng = process.platform === 'darwin' ? 'libpng' : 'libpng-dev';

binBuild.file(path.resolve(__dirname, '../vendor/source/pngquant.tar.gz'), [
'rm ./INSTALL',
`./configure --prefix="${dest}"`,
`make install BINPREFIX="${dest}"`
]).then(() => {
log.success('pngquant built successfully');
}).catch(err => {
err.message = `pngquant failed to build, make sure that ${libpng} is installed`;
log.error(err.stack);
});

return new BinWrapper()
.src(`${url}macos/pngquant`, 'darwin')
.src(`${url}linux/x86/pngquant`, 'linux', 'x86')
.src(`${url}linux/x64/pngquant`, 'linux', 'x64')
.src(`${url}freebsd/x64/pngquant`, 'freebsd', 'x64')
.src(`${url}win/pngquant.exe`, 'win32')
.dest(dest)
.use(process.platform === 'win32' ? 'pngquant.exe' : 'pngquant');
})();
20 changes: 1 addition & 19 deletions lib/install.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';
const path = require('path');
const binBuild = require('bin-build');
const log = require('logalot');
const bin = require('.');

Expand All @@ -9,21 +7,5 @@ bin.run(['--version']).then(() => {
}).catch(err => {
log.warn(err.message);
log.warn('pngquant pre-build test failed');
log.info('compiling from source');

const libpng = process.platform === 'darwin' ? 'libpng' : 'libpng-dev';

binBuild.file(path.resolve(__dirname, '../vendor/source/pngquant.tar.gz'), [
'rm ./INSTALL',
`./configure --prefix="${bin.dest()}"`,
`make install BINPREFIX="${bin.dest()}"`
]).then(() => {
log.success('pngquant built successfully');
}).catch(err => {
err.message = `pngquant failed to build, make sure that ${libpng} is installed`;
log.error(err.stack);

// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
});
process.exit(1);
});