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 29, 2017
1 parent c13d748 commit 29c027d
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 82 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -1 +1,2 @@
* text=auto
*.js text eol=lf
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
6 changes: 3 additions & 3 deletions cli.js
@@ -1,9 +1,9 @@
#!/usr/bin/env node
'use strict';
const spawn = require('child_process').spawn;
const jpegRecompress = require('.');

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

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

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

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

bin.run(['--version'], function (err) {
bin.run(['--version'], 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
23 changes: 13 additions & 10 deletions package.json
Expand Up @@ -25,39 +25,42 @@
"url": "github.com/shinnn"
}
],
"engines": {
"node": ">=0.10.0"
},
"bin": {
"jpeg-recompress": "cli.js"
},
"engines": {
"node": ">=4"
},
"scripts": {
"postinstall": "node lib/install.js",
"test": "mocha --timeout 20000"
"test": "xo && ava"
},
"files": [
"cli.js",
"index.js",
"lib"
],
"keywords": [
"imagemin",
"compress",
"image",
"img",
"jpeg",
"jpg",
"minify",
"optimize"
"optimize",
"jpeg-recompress"
],
"dependencies": {
"bin-wrapper": "^3.0.0",
"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",
"tempy": "^0.1.0",
"xo": "*"
}
}
10 changes: 6 additions & 4 deletions readme.md
Expand Up @@ -2,6 +2,8 @@

> Compress JPEGs by re-encoding to the smallest JPEG quality while keeping perceived visual quality the same and by making sure huffman tables are optimized
You probably want [`imagemin-jpeg-recompress`](https://github.com/imagemin/imagemin-jpeg-recompress) instead.


## Install

Expand All @@ -13,10 +15,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 All @@ -35,4 +37,4 @@ $ jpeg-recompress --help

## License

MIT © [imagemin](https://github.com/imagemin)
MIT © [Imagemin](https://github.com/imagemin)
53 changes: 17 additions & 36 deletions test/test.js
@@ -1,48 +1,29 @@
/*global afterEach,beforeEach,it*/
'use strict';
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 jpegRecompress = require('..');

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');

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

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();
});
test('return path to binary and verify that it is working', async t => {
t.true(await binCheck(jpegRecompress, ['--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 = [
'--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]);
});

0 comments on commit 29c027d

Please sign in to comment.