-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1000ch
committed
Mar 28, 2017
1 parent
7c17388
commit 4698a7a
Showing
7 changed files
with
67 additions
and
103 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,9 +1,10 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
var spawn = require('child_process').spawn; | ||
var mozjpeg = require('./'); | ||
|
||
var input = process.argv.slice(2); | ||
const spawn = require('child_process').spawn; | ||
const mozjpeg = require('.'); | ||
|
||
const input = process.argv.slice(2); | ||
|
||
spawn(mozjpeg, 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,2 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('./lib').path(); |
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,13 +1,14 @@ | ||
'use strict'; | ||
var path = require('path'); | ||
var BinWrapper = require('bin-wrapper'); | ||
var pkg = require('../package.json'); | ||
|
||
var url = 'https://raw.githubusercontent.com/imagemin/mozjpeg-bin/v' + pkg.version + '/vendor/'; | ||
const path = require('path'); | ||
const BinWrapper = require('bin-wrapper'); | ||
const pkg = require('../package.json'); | ||
|
||
const url = `https://raw.githubusercontent.com/imagemin/mozjpeg-bin/v${pkg.version}/vendor/`; | ||
|
||
module.exports = new BinWrapper() | ||
.src(url + 'macos/cjpeg', 'darwin') | ||
.src(url + 'linux/cjpeg', 'linux') | ||
.src(url + 'win/cjpeg.exe', 'win32') | ||
.src(`${url}macos/cjpeg`, 'darwin') | ||
.src(`${url}linux/cjpeg`, 'linux') | ||
.src(`${url}win/cjpeg.exe`, 'win32') | ||
.dest(path.join(__dirname, '../vendor')) | ||
.use(process.platform === 'win32' ? 'cjpeg.exe' : 'cjpeg'); |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,92 +1,53 @@ | ||
/* eslint-env mocha */ | ||
'use strict'; | ||
var assert = require('assert'); | ||
var execFile = require('child_process').execFile; | ||
var fs = require('fs'); | ||
var os = require('os'); | ||
var path = require('path'); | ||
var binCheck = require('bin-check'); | ||
var BinBuild = require('bin-build'); | ||
var compareSize = require('compare-size'); | ||
var mkdirp = require('mkdirp'); | ||
var rimraf = require('rimraf'); | ||
|
||
var tmp = path.join(__dirname, 'tmp'); | ||
var cpuNum = os.cpus().length; | ||
|
||
beforeEach(function (cb) { | ||
mkdirp(tmp, cb); | ||
}); | ||
|
||
afterEach(function (cb) { | ||
rimraf(tmp, {disableGlob: true}, cb); | ||
}); | ||
|
||
it('rebuild the mozjpeg binaries', function (cb) { | ||
this.timeout(150000); | ||
|
||
var cfg = [ | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
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 mozjpeg = require('..'); | ||
|
||
const cpuNum = os.cpus().length; | ||
|
||
test.cb('rebuild the mozjpeg binaries', t => { | ||
const tmp = tempy.directory(); | ||
const cfg = [ | ||
'./configure --disable-shared --disable-dependency-tracking --with-jpeg8', | ||
'--prefix="' + tmp + '" --bindir="' + tmp + '"', | ||
'--libdir="' + tmp + '"' | ||
`--prefix="${tmp}" --bindir="${tmp}" --libdir="${tmp}"` | ||
].join(' '); | ||
|
||
new BinBuild() | ||
.src('https://github.com/mozilla/mozjpeg/releases/download/v3.1/mozjpeg-3.1-release-source.tar.gz') | ||
.cmd('autoreconf -fiv') | ||
.cmd(cfg) | ||
.cmd('make --jobs=' + String(cpuNum)) | ||
.cmd('make install --jobs=' + String(cpuNum)) | ||
.run(function (err) { | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
|
||
assert(fs.statSync(path.join(tmp, 'cjpeg')).isFile()); | ||
cb(); | ||
.cmd(`make --jobs=${cpuNum}`) | ||
.cmd(`make install --jobs=${cpuNum}`) | ||
.run(err => { | ||
t.ifError(err); | ||
t.true(fs.existsSync(path.join(tmp, 'cjpeg'))); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
it('return path to binary and verify that it is working', function (cb) { | ||
var args = [ | ||
'-outfile', path.join(tmp, 'test.jpg'), | ||
path.join(__dirname, 'fixtures/test.jpg') | ||
]; | ||
|
||
binCheck(require('../'), args, function (err, works) { | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
|
||
assert(works); | ||
cb(); | ||
}); | ||
test('return path to binary and verify that it is working', async t => { | ||
t.true(await binCheck(mozjpeg, ['-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; | ||
} | ||
|
||
compareSize(src, dest, function (err, res) { | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
await execa(mozjpeg, args); | ||
const res = await compareSize(src, dest); | ||
|
||
assert(res[dest] < res[src]); | ||
cb(); | ||
}); | ||
}); | ||
t.true(res[dest] < res[src]); | ||
}); |