Skip to content

Commit

Permalink
ES2015ify and require Node.js 4
Browse files Browse the repository at this point in the history
  • Loading branch information
1000ch committed Mar 28, 2017
1 parent c13d748 commit 37e41b3
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 74 deletions.
12 changes: 0 additions & 12 deletions .jshintrc

This file was deleted.

5 changes: 2 additions & 3 deletions .travis.yml
@@ -1,6 +1,5 @@
sudo: false
language: node_js
node_js:
- 'iojs'
- '0.12'
- '0.10'
- 6
- 4
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -7,7 +7,7 @@ skip_tags: true

environment:
matrix:
- nodejs_version: '0.12'
- nodejs_version: 4

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
7 changes: 4 additions & 3 deletions cli.js
@@ -1,9 +1,10 @@
#!/usr/bin/env node
'use strict';

var spawn = require('child_process').spawn;
var jpegRecompress = require('./');
var input = process.argv.slice(2);
const spawn = require('child_process').spawn;
const jpegRecompress = require('.');

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

spawn(jpegRecompress, input, {stdio: 'inherit'})
.on('exit', process.exit);
1 change: 1 addition & 0 deletions index.js
@@ -1,2 +1,3 @@
'use strict';

module.exports = require('./lib').path();
15 changes: 8 additions & 7 deletions lib/index.js
@@ -1,13 +1,14 @@
'use strict';

var path = require('path');
var BinWrapper = require('bin-wrapper');
var pkg = require('../package.json');
var url = 'https://raw.github.com/imagemin/jpeg-recompress-bin/v' + pkg.version + '/vendor/';
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/`;

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}osx/jpeg-recompress`, 'darwin')
.src(`${url}linux/jpeg-recompress`, 'linux')
.src(`${url}win/jpeg-recompress.exe`, 'win32')
.dest(path.join(__dirname, '../vendor'))
.use(process.platform === 'win32' ? 'jpeg-recompress.exe' : 'jpeg-recompress');
6 changes: 3 additions & 3 deletions lib/install.js
@@ -1,9 +1,9 @@
'use strict';

var log = require('logalot');
var bin = require('./');
const log = require('logalot');
const bin = require('.');

bin.run(['--version'], function (err) {
bin.run(['--version'], err => {
if (err) {
log.error(err.stack);
return;
Expand Down
16 changes: 9 additions & 7 deletions package.json
Expand Up @@ -26,14 +26,14 @@
}
],
"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"bin": {
"jpeg-recompress": "cli.js"
},
"scripts": {
"postinstall": "node lib/install.js",
"test": "mocha --timeout 20000"
"test": "xo && ava"
},
"files": [
"cli.js",
Expand All @@ -54,10 +54,12 @@
"logalot": "^2.0.0"
},
"devDependencies": {
"bin-check": "^1.0.0",
"compare-size": "^1.0.1",
"mkdirp": "^0.5.0",
"mocha": "^2.2.4",
"rimraf": "^2.2.8"
"ava": "*",
"bin-check": "^4.0.1",
"compare-size": "^3.0.0",
"execa": "^0.6.3",
"rimraf": "^2.2.8",
"tempy": "^0.1.0",
"xo": "*"
}
}
6 changes: 3 additions & 3 deletions readme.md
Expand Up @@ -13,10 +13,10 @@ $ npm install --save jpeg-recompress-bin
## Usage

```js
var execFile = require('child_process').execFile;
var jpegRecompress = require('jpeg-recompress-bin');
const execFile = require('child_process').execFile;
const jpegRecompress = require('jpeg-recompress-bin');

execFile(jpegRecompress, ['--quality high', '--min 60', 'input.jpg', 'output.jpg'], function (err) {
execFile(jpegRecompress, ['--quality high', '--min 60', 'input.jpg', 'output.jpg'], err => {
console.log('Image minified');
});
```
Expand Down
54 changes: 19 additions & 35 deletions test/test.js
@@ -1,48 +1,32 @@
/*global afterEach,beforeEach,it*/
'use strict';

var assert = require('assert');
var execFile = require('child_process').execFile;
var path = require('path');
var binCheck = require('bin-check');
var compareSize = require('compare-size');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');
var tmp = path.join(__dirname, 'tmp');
const path = require('path');
const test = require('ava');
const execa = require('execa');
const tempy = require('tempy');
const binCheck = require('bin-check');
const compareSize = require('compare-size');
const rimraf = require('rimraf');
const jpegRecompress = require('..');

beforeEach(function () {
mkdirp.sync(tmp);
test('return path to binary and verify that it is working', async t => {
t.true(await binCheck(jpegRecompress, ['--version']));
});

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

it('return path to binary and verify that it is working', function (cb) {
binCheck(require('../'), ['--version'], function (err, works) {
assert(!err);
assert(works);
cb();
});
});

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 = [
'--quality', 'high',
'--min', '60',
src,
dest
];

execFile(require('../'), args, function (err) {
assert(!err);
await execa(jpegRecompress, args);
const res = await compareSize(src, dest);

compareSize(src, dest, function (err, res) {
assert(!err);
assert(res[dest] < res[src]);
cb();
});
});
t.true(res[dest] < res[src]);
rimraf.sync(tmp);
});

0 comments on commit 37e41b3

Please sign in to comment.