-
-
Notifications
You must be signed in to change notification settings - Fork 36
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 29, 2017
1 parent
9232d28
commit 6df6b97
Showing
9 changed files
with
77 additions
and
101 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,7 +1,5 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '5' | ||
- '4' | ||
- '0.12' | ||
- '0.10' | ||
- 6 | ||
- 4 |
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,8 +1,7 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
var binPath = require('./'); | ||
var spawn = require('child_process').spawn; | ||
const spawn = require('child_process').spawn; | ||
const binPath = require('.'); | ||
|
||
spawn(binPath, process.argv.slice(2), {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,15 +1,15 @@ | ||
'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.githubusercontent.com/imagemin/cwebp-bin/v' + pkg.version + '/vendor/'; | ||
const url = `https://raw.githubusercontent.com/imagemin/cwebp-bin/v${pkg.version}/vendor/`; | ||
|
||
module.exports = new BinWrapper() | ||
.src(url + 'osx/cwebp', 'darwin') | ||
.src(url + 'linux/x86/cwebp', 'linux', 'x86') | ||
.src(url + 'linux/x64/cwebp', 'linux', 'x64') | ||
.src(url + 'win/x86/cwebp.exe', 'win32', 'x86') | ||
.src(url + 'win/x64/cwebp.exe', 'win32', 'x64') | ||
.src(`${url}osx/cwebp`, 'darwin') | ||
.src(`${url}linux/x86/cwebp`, 'linux', 'x86') | ||
.src(`${url}linux/x64/cwebp`, 'linux', 'x64') | ||
.src(`${url}win/x86/cwebp.exe`, 'win32', 'x86') | ||
.src(`${url}win/x64/cwebp.exe`, 'win32', 'x64') | ||
.dest(path.join(__dirname, '../vendor')) | ||
.use(process.platform === 'win32' ? 'cwebp.exe' : 'cwebp'); |
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,78 +1,58 @@ | ||
'use strict'; | ||
|
||
var execFile = require('child_process').execFile; | ||
var path = require('path'); | ||
var binCheck = require('bin-check'); | ||
var BinBuild = require('bin-build'); | ||
var compareSize = require('compare-size'); | ||
var pathExists = require('path-exists'); | ||
var cwebp = require('../'); | ||
var test = require('ava'); | ||
var tmp = path.join(__dirname, 'tmp'); | ||
|
||
test('rebuild the cwebp binaries', function (t) { | ||
t.plan(3); | ||
|
||
var builder = new BinBuild() | ||
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 cwebp = require('..'); | ||
|
||
test.cb('rebuild the cwebp binaries', t => { | ||
const tmp = tempy.directory(); | ||
const builder = new BinBuild() | ||
.src('http://downloads.webmproject.org/releases/webp/libwebp-0.5.1.tar.gz') | ||
.cmd('./configure --disable-shared --prefix="' + tmp + '" --bindir="' + tmp + '"') | ||
.cmd(`./configure --disable-shared --prefix="${tmp}" --bindir="${tmp}"`) | ||
.cmd('make && make install'); | ||
|
||
builder.run(function (err) { | ||
t.assert(!err, err); | ||
|
||
pathExists(path.join(tmp, 'cwebp'), function (err, exists) { | ||
t.assert(!err, err); | ||
t.assert(exists); | ||
}); | ||
builder.run(err => { | ||
t.ifError(err); | ||
t.true(fs.existsSync(path.join(tmp, 'cwebp'))); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('return path to binary and verify that it is working', function (t) { | ||
t.plan(2); | ||
|
||
binCheck(cwebp, ['-version'], function (err, works) { | ||
t.assert(!err, err); | ||
t.assert(works); | ||
}); | ||
test('return path to binary and verify that it is working', async t => { | ||
t.true(await binCheck(cwebp, ['-version'])); | ||
}); | ||
|
||
test('minify and convert a PNG to WebP', function (t) { | ||
t.plan(3); | ||
|
||
var src = path.join(__dirname, 'fixtures/test.png'); | ||
var dest = path.join(tmp, 'test-png.webp'); | ||
var args = [ | ||
test('minify and convert a PNG to WebP', async t => { | ||
const tmp = tempy.directory(); | ||
const src = path.join(__dirname, 'fixtures/test.png'); | ||
const dest = path.join(tmp, 'test-png.webp'); | ||
const args = [ | ||
src, | ||
'-o', dest | ||
]; | ||
|
||
execFile(cwebp, args, function (err) { | ||
t.assert(!err, err); | ||
await execa(cwebp, args); | ||
const res = await compareSize(src, dest); | ||
|
||
compareSize(src, dest, function (err, res) { | ||
t.assert(!err, err); | ||
t.assert(res[dest] < res[src]); | ||
}); | ||
}); | ||
t.true(res[dest] < res[src]); | ||
}); | ||
|
||
test('minify and convert a JPG to WebP', function (t) { | ||
t.plan(3); | ||
|
||
var src = path.join(__dirname, 'fixtures/test.jpg'); | ||
var dest = path.join(tmp, 'test-jpg.webp'); | ||
var args = [ | ||
test('minify and convert a JPG to WebP', async t => { | ||
const tmp = tempy.directory(); | ||
const src = path.join(__dirname, 'fixtures/test.jpg'); | ||
const dest = path.join(tmp, 'test-jpg.webp'); | ||
const args = [ | ||
src, | ||
'-o', dest | ||
]; | ||
|
||
execFile(cwebp, args, function (err) { | ||
t.assert(!err); | ||
await execa(cwebp, args); | ||
const res = await compareSize(src, dest); | ||
|
||
compareSize(src, dest, function (err, res) { | ||
t.assert(!err, err); | ||
t.assert(res[dest] < res[src]); | ||
}); | ||
}); | ||
t.true(res[dest] < res[src]); | ||
}); |