Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ES2015ify and require Node.js 4 (#80)
- Loading branch information
Shogo Sensui
committed
Mar 31, 2017
1 parent
8f7752a
commit eb91536
Showing
8 changed files
with
75 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
* text=auto | ||
*.js text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]); | ||
}); |