Skip to content

Commit

Permalink
ES2015ify and require Node.js 4 (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shogo Sensui committed Mar 31, 2017
1 parent 8f7752a commit eb91536
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 100 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -1 +1,2 @@
* text=auto
*.js text eol=lf
6 changes: 3 additions & 3 deletions cli.js
@@ -1,9 +1,9 @@
#!/usr/bin/env node
'use strict';
var spawn = require('child_process').spawn;
var jpegtran = require('./');
const spawn = require('child_process').spawn;
const jpegtran = require('.');

var input = process.argv.slice(2);
const input = process.argv.slice(2);

spawn(jpegtran, input, {stdio: 'inherit'})
.on('exit', process.exit);
30 changes: 15 additions & 15 deletions lib/index.js
@@ -1,21 +1,21 @@
'use strict';
var path = require('path');
var BinWrapper = require('bin-wrapper');
var pkg = require('../package.json');
const path = require('path');
const BinWrapper = require('bin-wrapper');
const pkg = require('../package.json');

var url = 'https://raw.githubusercontent.com/imagemin/jpegtran-bin/v' + pkg.version + '/vendor/';
const url = `https://raw.githubusercontent.com/imagemin/jpegtran-bin/v${pkg.version}/vendor/`;

module.exports = new BinWrapper()
.src(url + 'macos/jpegtran', 'darwin')
.src(url + 'linux/x86/jpegtran', 'linux', 'x86')
.src(url + 'linux/x64/jpegtran', 'linux', 'x64')
.src(url + 'freebsd/x86/jpegtran', 'freebsd', 'x86')
.src(url + 'freebsd/x64/jpegtran', 'freebsd', 'x64')
.src(url + 'sunos/x86/jpegtran', 'sunos', 'x86')
.src(url + 'sunos/x64/jpegtran', 'sunos', 'x64')
.src(url + 'win/x86/jpegtran.exe', 'win32', 'x86')
.src(url + 'win/x64/jpegtran.exe', 'win32', 'x64')
.src(url + 'win/x86/libjpeg-62.dll', 'win32', 'x86')
.src(url + 'win/x64/libjpeg-62.dll', 'win32', 'x64')
.src(`${url}macos/jpegtran`, 'darwin')
.src(`${url}linux/x86/jpegtran`, 'linux', 'x86')
.src(`${url}linux/x64/jpegtran`, 'linux', 'x64')
.src(`${url}freebsd/x86/jpegtran`, 'freebsd', 'x86')
.src(`${url}freebsd/x64/jpegtran`, 'freebsd', 'x64')
.src(`${url}sunos/x86/jpegtran`, 'sunos', 'x86')
.src(`${url}sunos/x64/jpegtran`, 'sunos', 'x64')
.src(`${url}win/x86/jpegtran.exe`, 'win32', 'x86')
.src(`${url}win/x64/jpegtran.exe`, 'win32', 'x64')
.src(`${url}win/x86/libjpeg-62.dll`, 'win32', 'x86')
.src(`${url}win/x64/libjpeg-62.dll`, 'win32', 'x64')
.dest(path.join(__dirname, '../vendor'))
.use(process.platform === 'win32' ? 'jpegtran.exe' : 'jpegtran');
20 changes: 10 additions & 10 deletions lib/install.js
@@ -1,34 +1,34 @@
'use strict';
var path = require('path');
var BinBuild = require('bin-build');
var log = require('logalot');
var bin = require('./');
const path = require('path');
const BinBuild = require('bin-build');
const log = require('logalot');
const bin = require('.');

var args = [
const args = [
'-copy', 'none',
'-optimize',
'-outfile', path.join(__dirname, '../test/fixtures/test-optimized.jpg'),
path.join(__dirname, '../test/fixtures/test.jpg')
];

bin.run(args, function (err) {
bin.run(args, err => {
if (err) {
log.warn(err.message);
log.warn('jpegtran pre-build test failed');
log.info('compiling from source');

var cfg = [
const cfg = [
'./configure --disable-shared',
'--prefix="' + bin.dest() + '" --bindir="' + bin.dest() + '"'
`--prefix="${bin.dest()}" --bindir="${bin.dest()}"`
].join(' ');

var builder = new BinBuild()
const builder = new BinBuild()
.cmd('touch configure.ac aclocal.m4 configure Makefile.am Makefile.in')
.src('https://downloads.sourceforge.net/project/libjpeg-turbo/1.5.1/libjpeg-turbo-1.5.1.tar.gz')
.cmd(cfg)
.cmd('make install');

return builder.run(function (err) {
return builder.run(err => {
if (err) {
log.error(err.stack);
return;
Expand Down
2 changes: 1 addition & 1 deletion license
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) imagemin
Copyright (c) Imagemin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 13 additions & 11 deletions package.json
Expand Up @@ -20,15 +20,15 @@
"url": "github.com/shinnn"
}
],
"engines": {
"node": ">=0.10.0"
},
"bin": {
"jpegtran": "cli.js"
},
"engines": {
"node": ">=4"
},
"scripts": {
"postinstall": "node lib/install.js",
"test": "xo && mocha --timeout 100000"
"test": "xo && ava"
},
"files": [
"index.js",
Expand All @@ -37,25 +37,27 @@
"test"
],
"keywords": [
"imagemin",
"compress",
"image",
"img",
"jpeg",
"jpg",
"minify",
"optimize"
"optimize",
"jpegtran"
],
"dependencies": {
"bin-build": "^2.0.0",
"bin-build": "^2.2.0",
"bin-wrapper": "^3.0.0",
"logalot": "^2.0.0"
},
"devDependencies": {
"bin-check": "^3.0.0",
"compare-size": "^1.0.1",
"mkdirp": "^0.5.0",
"mocha": "^2.2.4",
"rimraf": "^2.3.2",
"ava": "*",
"bin-check": "^4.0.1",
"compare-size": "^3.0.0",
"execa": "^0.6.3",
"tempy": "^0.1.0",
"xo": "*"
}
}
6 changes: 4 additions & 2 deletions readme.md
@@ -1,6 +1,8 @@
# jpegtran-bin [![Build Status](https://travis-ci.org/imagemin/jpegtran-bin.svg?branch=master)](https://travis-ci.org/imagemin/jpegtran-bin)

> libjpeg-turbo is a derivative of libjpeg that uses SIMD instructions (MMX, SSE2, NEON) to accelerate baseline JPEG compression and decompression on x86, x86-64, and ARM systems. On such systems, libjpeg-turbo is generally 2-4x as fast as the unmodified version of libjpeg, all else being equal.
> [libjpeg-turbo](http://libjpeg-turbo.virtualgl.org/) is a derivative of libjpeg that uses SIMD instructions (MMX, SSE2, NEON) to accelerate baseline JPEG compression and decompression on x86, x86-64, and ARM systems. On such systems, libjpeg-turbo is generally 2-4x as fast as the unmodified version of libjpeg, all else being equal.
You probably want [`imagemin-jpegtran`](https://github.com/imagemin/imagemin-jpegtran) instead.


## Install
Expand Down Expand Up @@ -35,4 +37,4 @@ $ jpegtran --help

## License

MIT © [imagemin](https://github.com/imagemin)
MIT © [Imagemin](https://github.com/imagemin)
86 changes: 28 additions & 58 deletions test/test.js
@@ -1,77 +1,47 @@
'use strict';
/* eslint-env mocha */
var assert = require('assert');
var execFile = require('child_process').execFile;
var fs = require('fs');
var path = require('path');
var BinBuild = require('bin-build');
var binCheck = require('bin-check');
var compareSize = require('compare-size');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');

var tmp = path.join(__dirname, 'tmp');

beforeEach(function () {
mkdirp.sync(tmp);
});

afterEach(function () {
rimraf.sync(tmp);
});

it('rebuild the jpegtran binaries', function (cb) {
var cfg = [
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 jpegtran = require('..');

test.cb('rebuild the jpegtran binaries', t => {
const tmp = tempy.directory();
const cfg = [
'./configure --disable-shared',
'--prefix="' + tmp + '" --bindir="' + tmp + '"'
`--prefix="${tmp}" --bindir="${tmp}"`
].join(' ');

new BinBuild()
.src('https://downloads.sourceforge.net/project/libjpeg-turbo/1.5.1/libjpeg-turbo-1.5.1.tar.gz')
.cmd(cfg)
.cmd('make install')
.run(function (err) {
if (err) {
cb(err);
return;
}

assert(fs.statSync(path.join(tmp, 'jpegtran')).isFile());
cb();
.run(err => {
t.ifError(err);
t.true(fs.existsSync(path.join(tmp, 'jpegtran')));
t.end();
});
});

it('return path to binary and verify that it is working', function () {
var args = [
'-outfile', path.join(tmp, 'test.jpg'),
path.join(__dirname, 'fixtures/test.jpg')
];

return binCheck(require('../'), args).then(assert);
test('return path to binary and verify that it is working', async t => {
t.true(await binCheck(jpegtran, ['-version']));
});

it('minify a JPG', function (cb) {
var src = path.join(__dirname, 'fixtures/test.jpg');
var dest = path.join(tmp, 'test.jpg');
var args = [
test('minify a JPG', async t => {
const tmp = tempy.directory();
const src = path.join(__dirname, 'fixtures/test.jpg');
const dest = path.join(tmp, 'test.jpg');
const args = [
'-outfile', dest,
src
];

execFile(require('../'), args, function (err) {
if (err) {
cb(err);
return;
}
await execa(jpegtran, args);
const res = await compareSize(src, dest);

compareSize(src, dest, function (err, res) {
if (err) {
cb(err);
return;
}

assert(res[dest] < res[src]);
cb();
});
});
t.true(res[dest] < res[src]);
});

0 comments on commit eb91536

Please sign in to comment.