Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 25, 2019
1 parent 6bb7f1c commit 064d12c
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 116 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{json,yml}]
indent_size = 2
[*.yml]
indent_style = space
indent_size = 2
3 changes: 1 addition & 2 deletions .gitattributes
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
node_modules
yarn.lock
vendor/optipng*
vendor/man
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,7 +1,7 @@
language: node_js
node_js:
- '12'
- '10'
- '8'
- '6'
before_install:
- 'sudo chown $USER /usr/local'
4 changes: 2 additions & 2 deletions lib/index.js
@@ -1,9 +1,9 @@
'use strict';
const path = require('path');
const BinWrapper = require('bin-wrapper');
const pkg = require('../package.json');
const packageJson = require('../package.json');

const url = `https://raw.githubusercontent.com/imagemin/optipng-bin/v${pkg.version}/vendor/`;
const url = `https://raw.githubusercontent.com/imagemin/optipng-bin/v${packageJson.version}/vendor/`;

module.exports = new BinWrapper()
.src(`${url}macos/optipng`, 'darwin')
Expand Down
41 changes: 23 additions & 18 deletions lib/install.js
Expand Up @@ -4,23 +4,28 @@ const binBuild = require('bin-build');
const log = require('logalot');
const bin = require('.');

bin.run(['--version']).then(() => {
log.success('optipng pre-build test passed successfully');
}).catch(error => {
log.warn(error.message);
log.warn('optipng pre-build test failed');
log.info('compiling from source');
(async () => {
try {
await bin.run(['--version']);
log.success('optipng pre-build test passed successfully');
} catch (error) {
log.warn(error.message);
log.warn('optipng pre-build test failed');
log.info('compiling from source');

// From https://sourceforge.net/projects/optipng/files/OptiPNG/
binBuild.file(path.resolve(__dirname, '../vendor/source/optipng.tar.gz'), [
`./configure --with-system-zlib --prefix="${bin.dest()}" --bindir="${bin.dest()}"`,
'make install'
]).then(() => {
log.success('optipng built successfully');
}).catch(error => {
log.error(error.stack);
try {
// From https://sourceforge.net/projects/optipng/files/OptiPNG/
await binBuild.file(path.resolve(__dirname, '../vendor/source/optipng.tar.gz'), [
`./configure --with-system-zlib --prefix="${bin.dest()}" --bindir="${bin.dest()}"`,
'make install'
]);

// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
});
});
log.success('optipng built successfully');
} catch (error) {
log.error(error.stack);

// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}
}
})();
20 changes: 4 additions & 16 deletions license
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
103 changes: 43 additions & 60 deletions package.json
@@ -1,62 +1,45 @@
{
"name": "optipng-bin",
"version": "5.1.0",
"description": "OptiPNG wrapper that makes it seamlessly available as a local dependency",
"license": "MIT",
"repository": "imagemin/optipng-bin",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"maintainers": [
{
"name": "Kevin Mårtensson",
"email": "kevinmartensson@gmail.com",
"url": "github.com/kevva"
},
{
"name": "Shinnosuke Watanabe",
"url": "github.com/shinnn"
}
],
"bin": {
"optipng": "cli.js"
},
"engines": {
"node": ">=6"
},
"scripts": {
"postinstall": "node lib/install.js",
"test": "xo && ava"
},
"files": [
"index.js",
"cli.js",
"lib",
"vendor/source"
],
"keywords": [
"imagemin",
"compress",
"image",
"img",
"minify",
"optimize",
"png",
"optipng"
],
"dependencies": {
"bin-build": "^3.0.0",
"bin-wrapper": "^4.0.0",
"logalot": "^2.0.0"
},
"devDependencies": {
"ava": "*",
"bin-check": "^4.0.1",
"compare-size": "^3.0.0",
"execa": "^1.0.0",
"tempy": "^0.2.1",
"xo": "*"
}
"name": "optipng-bin",
"version": "5.1.0",
"description": "OptiPNG wrapper that makes it seamlessly available as a local dependency",
"license": "MIT",
"repository": "imagemin/optipng-bin",
"bin": {
"optipng": "cli.js"
},
"engines": {
"node": ">=8"
},
"scripts": {
"postinstall": "node lib/install.js",
"test": "xo && ava"
},
"files": [
"index.js",
"cli.js",
"lib",
"vendor/source"
],
"keywords": [
"imagemin",
"compress",
"image",
"minify",
"optimize",
"png",
"optipng"
],
"dependencies": {
"bin-build": "^3.0.0",
"bin-wrapper": "^4.0.0",
"logalot": "^2.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"bin-check": "^4.0.1",
"compare-size": "^3.0.0",
"execa": "^1.0.0",
"tempy": "^0.3.0",
"xo": "^0.24.0"
}
}
13 changes: 6 additions & 7 deletions readme.md
Expand Up @@ -15,12 +15,16 @@ $ npm install --save optipng-bin
## Usage

```js
const {promisify} = require('util');
const {execFile} = require('child_process');
const optipng = require('optipng-bin');

execFile(optipng, ['-out', 'output.png', 'input.png'], err => {
const execFileP = promsify(execFile);

(async () => {
await execFile(optipng, ['-out', 'output.png', 'input.png']);
console.log('Image minified!');
});
})();
```


Expand All @@ -33,8 +37,3 @@ $ npm install --global optipng-bin
```
$ optipng --help
```


## License

MIT © [Imagemin](https://github.com/imagemin)
16 changes: 8 additions & 8 deletions test/test.js
Expand Up @@ -32,19 +32,19 @@ test('return path to binary and verify that it is working', async t => {

test('minify a PNG', async t => {
const tmp = tempy.directory();
const src = path.join(__dirname, 'fixtures/test.png');
const dest = path.join(tmp, 'test.png');
const args = [
const sourcePath = path.join(__dirname, 'fixtures/test.png');
const destinationPath = path.join(tmp, 'test.png');
const arguments_ = [
'-strip',
'all',
'-clobber',
'-out',
dest,
src
destinationPath,
sourcePath
];

await execa(optipng, args);
const res = await compareSize(src, dest);
await execa(optipng, arguments_);
const result = await compareSize(sourcePath, destinationPath);

t.true(res[dest] < res[src]);
t.true(result[destinationPath] < result[sourcePath]);
});

0 comments on commit 064d12c

Please sign in to comment.