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

Update .travis.yml to build jpeg-archive binary #24

Open
wants to merge 4 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
103 changes: 102 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,105 @@ os:
- windows
- osx
before_install:
- if [[ $TRAVIS_OS_NAME == 'osx' ]]; then brew install mozjpeg; fi
- |
case $TRAVIS_OS_NAME in
windows)
choco install -y nasm
echo "Compiling Zlib"
git clone https://github.com/madler/zlib.git $HOME/zlib
cd $HOME/zlib
cmake -G"MSYS Makefiles" -DCMAKE_MAKE_PROGRAM="/c/ProgramData/chocolatey/bin/mingw32-make.exe" -DCMAKE_C_COMPILER='/c/ProgramData/chocolatey/bin/x86_64-w64-mingw32-gcc.exe' -DCMAKE_AR="/c/ProgramData/chocolatey/bin/ar.exe" .
/c/ProgramData/chocolatey/bin/mingw32-make.exe
/c/ProgramData/chocolatey/bin/mingw32-make.exe test
cd ..
echo "Compiling Libpng"
git clone https://github.com/glennrp/libpng $HOME/libpng
cd $HOME/libpng
cmake -G"MSYS Makefiles" -DCMAKE_MAKE_PROGRAM="/c/ProgramData/chocolatey/bin/mingw32-make.exe" -DCMAKE_C_COMPILER='/c/ProgramData/chocolatey/bin/x86_64-w64-mingw32-gcc.exe' -DCMAKE_AR="/c/ProgramData/chocolatey/bin/ar.exe" -DZLIB_LIBRARY="$HOME/zlib/libzlib.dll.a" -DZLIB_INCLUDE_DIR="$HOME/zlib" .
/c/ProgramData/chocolatey/bin/mingw32-make.exe
cp scripts/pnglibconf.h.prebuilt pnglibconf.h
cp scripts/makefile.msys makefile
/c/ProgramData/chocolatey/bin/mingw32-make.exe test
cd ..
echo "Compiling Mozjpeg"
git clone https://github.com/mozilla/mozjpeg.git $HOME/mozjpeg
cd $HOME/mozjpeg
cmake -G"MSYS Makefiles" -DCMAKE_MAKE_PROGRAM="/c/ProgramData/chocolatey/bin/mingw32-make.exe" -DCMAKE_C_COMPILER='/c/ProgramData/chocolatey/bin/x86_64-w64-mingw32-gcc.exe' -DZLIB_LIBRARY="$HOME/zlib/libzlib.dll.a" -DZLIB_INCLUDE_DIR="$HOME/zlib" -DPNG_LIBRARY="$HOME/libpng/libpng16.a" -DPNG_PNG_INCLUDE_DIR="$HOME/libpng" -DCMAKE_AR="/c/ProgramData/chocolatey/bin/ar.exe" -DWITH_JPEG8=1 .
/c/ProgramData/chocolatey/bin/mingw32-make.exe
echo "Compiling Jpeg Archive"
git clone https://github.com/danielgtaylor/jpeg-archive.git $HOME/jpeg-archive
cd $HOME/jpeg-archive
CC='/c/ProgramData/chocolatey/bin/x86_64-w64-mingw32-gcc.exe' /c/ProgramData/chocolatey/bin/mingw32-make.exe
./jpeg-recompress.exe --version
cp jpeg-recompress.exe $HOME/build/imagemin/jpeg-recompress-bin/vendor/jpeg-recompress.exe
;;
osx)
brew install mozjpeg
echo "Compiling Jpeg Archive"
git clone https://github.com/danielgtaylor/jpeg-archive.git $HOME/jpeg-archive
cd $HOME/jpeg-archive
CC=gcc make
CC=gcc make test
./jpeg-recompress --version
cp jpeg-recompress darwin-jpeg-recompress
cp jpeg-recompress $HOME/build/imagemin/jpeg-recompress-bin/vendor/darwin-jpeg-recompress
;;
linux)
echo "Building for Linux"
sudo apt-get install -y cmake git nasm
echo "Compiling Zlib"
git clone https://github.com/madler/zlib.git $HOME/zlib
cd $HOME/zlib
cmake -G"Unix Makefiles"
make
make test
sudo make install
cd ..
echo "Compiling Libpng"
git clone https://github.com/glennrp/libpng $HOME/libpng
cd $HOME/libpng
./configure
cmake -G"Unix Makefiles" .
make
cp scripts/pnglibconf.h.prebuilt pnglibconf.h
cp scripts/makefile.linux makefile
make test
sudo make install
echo "Compiling Mozjpeg"
git clone https://github.com/mozilla/mozjpeg.git $HOME/mozjpeg
cd $HOME/mozjpeg
mkdir build
cd build
cmake -G"Unix Makefiles" -DPNG_SUPPORTED=TRUE -DWITH_JPEG8=1 ../
make SHARED=0 CC='gcc -static'
sudo make install
echo "Compiling Jpeg Archive"
git clone https://github.com/danielgtaylor/jpeg-archive.git $HOME/jpeg-archive
cd $HOME/jpeg-archive
CC=gcc make
CC=gcc make test
./jpeg-recompress --version
cp jpeg-recompress linux-jpeg-recompress
cp jpeg-recompress $HOME/build/imagemin/jpeg-recompress-bin/vendor/linux-jpeg-recompress
;;
esac
- cd $HOME/build/imagemin/jpeg-recompress-bin
compiler:
- gcc
install:
- npm install
deploy:
provider: releases
tag_name: $TRAVIS_TAG
target_commitish: $TRAVIS_COMMIT
name: $TRAVIS_TAG
overwrite: true
skip_cleanup: true
api_key: $github_token
file_glob: true
file:
- $HOME/jpeg-archive/linux-jpeg-recompress
- $HOME/jpeg-archive/darwin-jpeg-recompress
- $HOME/jpeg-archive/jpeg-recompress.exe
on:
tags: true
11 changes: 5 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';
const path = require('path');
const BinWrapper = require('bin-wrapper');
const pkg = require('../package.json');

const url = `https://raw.github.com/imagemin/jpeg-recompress-bin/v${pkg.version}/vendor/`;
const url = 'https://github.com/imagemin/jpeg-recompress-bin/releases/latest/download/';

module.exports = new BinWrapper()
.src(`${url}osx/jpeg-recompress`, 'darwin')
.src(`${url}linux/jpeg-recompress`, 'linux')
.src(`${url}win/jpeg-recompress.exe`, 'win32')
.src(`${url}darwin-jpeg-recompress`, 'darwin')
.src(`${url}linux-jpeg-recompress`, 'linux')
.src(`${url}jpeg-recompress.exe`, 'win32')
.dest(path.resolve(__dirname, '../vendor'))
.use(process.platform === 'win32' ? 'jpeg-recompress.exe' : 'jpeg-recompress');
.use(process.platform === 'win32' ? 'jpeg-recompress.exe' : `${process.platform}-jpeg-recompress`);
23 changes: 0 additions & 23 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,25 +7,4 @@ bin.run(['--version']).then(() => {
}).catch(async error => {
log.warn(error.message);
log.warn('jpeg-recompress pre-build test failed');

if (process.platform === 'win32' || process.platform === 'linux') {
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}

log.info('compiling from source');

try {
await binBuild.file(path.resolve(__dirname, '../vendor/source/jpeg-archive-2.2.0.tar.gz'), [
`mkdir -p ${bin.dest()}`,
`make && mv ${bin.use()} ${bin.path()}`
]);

log.success('jpeg-recompress built successfully');
} catch (error) {
log.error(error.stack);

// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jpeg-recompress-bin",
"version": "5.1.1",
"version": "5.1.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't bump version in a PR. Applies in general.

"description": "jpeg-recompress wrapper that makes it seamlessly available as a local dependency",
"license": "MIT",
"repository": "imagemin/jpeg-recompress-bin",
Expand Down
18 changes: 0 additions & 18 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
'use strict';
const fs = require('fs');
const path = require('path');
const test = require('ava');
const execa = require('execa');
const tempy = require('tempy');
const binCheck = require('bin-check');
const binBuild = require('bin-build');
const compareSize = require('compare-size');
const jpegRecompress = require('..');

test('rebuild the jpeg-recompress binaries', async t => {
if (process.platform === 'win32' || process.platform === 'linux') {
t.pass('Build for win32 and linux is not supported');
return;
}

const temporary = tempy.directory();

await binBuild.file(path.resolve(__dirname, '../vendor/source/jpeg-archive-2.2.0.tar.gz'), [
`mkdir -p ${temporary}`,
`make && mv jpeg-recompress ${path.join(temporary, 'jpeg-recompress')}`
]);

t.true(fs.existsSync(path.join(temporary, 'jpeg-recompress')));
});

test('return path to binary and verify that it is working', async t => {
t.true(await binCheck(jpegRecompress, ['--version']));
});
Expand Down
2 changes: 2 additions & 0 deletions vendor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!.gitignore
*
Binary file removed vendor/linux/jpeg-recompress
Binary file not shown.
Binary file removed vendor/osx/jpeg-recompress
Binary file not shown.
Binary file removed vendor/source/jpeg-archive-2.2.0.tar.gz
Binary file not shown.
Binary file removed vendor/win/jpeg-recompress.exe
Binary file not shown.