diff --git a/.gitattributes b/.gitattributes index 176a458..391f0a4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ * text=auto +*.js text eol=lf diff --git a/cli.js b/cli.js index 23e6857..206dfee 100755 --- a/cli.js +++ b/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); diff --git a/lib/index.js b/lib/index.js index b12ffe0..3d18329 100644 --- a/lib/index.js +++ b/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'); diff --git a/lib/install.js b/lib/install.js index 44ff538..d93e6c8 100644 --- a/lib/install.js +++ b/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; diff --git a/license b/license index 78e84a1..92dec7a 100644 --- a/license +++ b/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 diff --git a/package.json b/package.json index 19e00ac..b4464f4 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": "*" } } diff --git a/readme.md b/readme.md index ee25583..fc3b260 100644 --- a/readme.md +++ b/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 @@ -35,4 +37,4 @@ $ jpegtran --help ## License -MIT © [imagemin](https://github.com/imagemin) +MIT © [Imagemin](https://github.com/imagemin) diff --git a/test/test.js b/test/test.js index e48b2ac..8aa1cf9 100644 --- a/test/test.js +++ b/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]); });