diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 765ba8b..0000000 --- a/.babelrc +++ /dev/null @@ -1,23 +0,0 @@ -{ - "env": { - "test": { - "presets": [ ["env", { "targets": { "node": "current" } }] ], - "plugins": [] - }, - - "v4": { - "presets": [ ["env", { "targets": { "node": 4.0 } }] ], - "plugins": ["babel-plugin-add-module-exports"] - }, - - "v6": { - "presets": [ ["env", { "targets": { "node": 6.0 } }] ], - "plugins": ["babel-plugin-add-module-exports"] - }, - - "v7": { - "presets": [ ["env", { "targets": { "node": 7.0 } }] ], - "plugins": ["babel-plugin-add-module-exports"] - } - } -} diff --git a/.codeclimate.yml b/.codeclimate.yml index faf3e94..e0b2dd1 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -13,5 +13,5 @@ engines: ratings: paths: - - src/** + - lib/** - test/** diff --git a/.gitignore b/.gitignore index 1bfd37a..2efb97a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ *.log -/lib /node_modules /.nyc_output diff --git a/.travis.yml b/.travis.yml index cc70a14..38bc1f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,9 @@ language: node_js node_js: - - 4 - - 6 - 7 - -env: - - BABEL_ENV=test + - 6 + - 4 matrix: fast_finish: true @@ -15,16 +12,20 @@ cache: directories: - node_modules -before_script: - - npm prune - after_success: - - npm run coverage - - npm run codeclimate - - BABEL_ENV=v4 npm run compile -- -d lib - - BABEL_ENV=v6 npm run compile -- -d lib/node6 - - BABEL_ENV=v7 npm run compile -- -d lib/node7 - - npm run semantic-release + - npm install --only=production codeclimate-test-reporter semantic-release + +before_deploy: + - npm run coverage -- --coverage-report=text-lcov | codeclimate-test-reporter + +deploy: + skip_cleanup: true + provider: script + script: semantic-release pre && npm publish && semantic-release post || true + + on: + branch: master + node: 7 branches: except: diff --git a/README.md b/README.md index fc21a71..1f98ea5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Metalsmith Imagemin [![version][npm-version]][npm-url] [![License][npm-license]][license-url] +# Metalsmith Imagemin [![version][npm-version]][npm-url] [![License][license-image]][license-url] > [Metalsmith](http://www.metalsmith.io/) plugin to minify images. @@ -15,37 +15,15 @@ npm install --only=production --save metalsmith-imagemin ``` -## Usage - -I recommend using an optimized build matching your Node.js environment version, otherwise, the standard `require` would work just fine with any version of Node `>= v4.0` . - -```js -/* - * Node 7 - */ -const metalsmith-imagemin = require('metalsmith-imagemin/lib/node7') - -/* - * Node 6 - */ -const metalsmith-imagemin = require('metalsmith-imagemin/lib/node6') - -/* - * Node 4 (Default) - * Note: additional ES2015 polyfills may be required - */ -var metalsmith-imagemin = require('metalsmith-imagemin') -``` - ## API Pass `options` to the imagemin plugin and pass it to Metalsmith with the `use` method: ```js -var Metalsmith = require('metalsmith') -var imagemin = require('metalsmith-imagemin'); +const Metalsmith = require('metalsmith') +const imagemin = require('metalsmith-imagemin'); -var metalsmith = new Metalsmith(__dirname) +const metalsmith = new Metalsmith(__dirname) .use(imagemin({ optimizationLevel: 3, svgoPlugins: [{ removeViewBox: false }] @@ -70,19 +48,19 @@ You can also use the plugin with the Metalsmith CLI by adding `metalsmith-imagem } ``` ----- +--- > :copyright: [ahmadnassri.com](https://www.ahmadnassri.com/)  ·  > License: [ISC][license-url]  ·  > Github: [@ahmadnassri](https://github.com/ahmadnassri)  ·  > Twitter: [@ahmadnassri](https://twitter.com/ahmadnassri) [license-url]: http://choosealicense.com/licenses/isc/ +[license-image]: https://img.shields.io/github/license/ahmadnassri/metalsmith-imagemin.svg?style=flat-square [travis-url]: https://travis-ci.org/ahmadnassri/metalsmith-imagemin [travis-image]: https://img.shields.io/travis/ahmadnassri/metalsmith-imagemin.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/metalsmith-imagemin -[npm-license]: https://img.shields.io/npm/l/metalsmith-imagemin.svg?style=flat-square [npm-version]: https://img.shields.io/npm/v/metalsmith-imagemin.svg?style=flat-square [npm-downloads]: https://img.shields.io/npm/dm/metalsmith-imagemin.svg?style=flat-square diff --git a/src/index.js b/lib/index.js similarity index 53% rename from src/index.js rename to lib/index.js index a3fee9a..dee9755 100644 --- a/src/index.js +++ b/lib/index.js @@ -1,21 +1,23 @@ -import imagemin from 'imagemin' -import path from 'path' +'use strict' -import advpng from 'imagemin-advpng' -import giflossy from 'imagemin-giflossy' -import gifsicle from 'imagemin-gifsicle' -import gm from 'imagemin-gm' -import jpegoptim from 'imagemin-jpegoptim' -import jpegrecompress from 'imagemin-jpeg-recompress' -import jpegtran from 'imagemin-jpegtran' -import mozjpeg from 'imagemin-mozjpeg' -import optipng from 'imagemin-optipng' -import pngcrush from 'imagemin-pngcrush' -import pngout from 'imagemin-pngout' -import pngquant from 'imagemin-pngquant' -import svgo from 'imagemin-svgo' -import webp from 'imagemin-webp' -import zopfli from 'imagemin-zopfli' +const imagemin = require('imagemin') +const path = require('path') + +const advpng = require('imagemin-advpng') +const giflossy = require('imagemin-giflossy') +const gifsicle = require('imagemin-gifsicle') +const gm = require('imagemin-gm') +const jpegoptim = require('imagemin-jpegoptim') +const jpegrecompress = require('imagemin-jpeg-recompress') +const jpegtran = require('imagemin-jpegtran') +const mozjpeg = require('imagemin-mozjpeg') +const optipng = require('imagemin-optipng') +const pngcrush = require('imagemin-pngcrush') +const pngout = require('imagemin-pngout') +const pngquant = require('imagemin-pngquant') +const svgo = require('imagemin-svgo') +const webp = require('imagemin-webp') +const zopfli = require('imagemin-zopfli') /** * Metalsmith plugin to minify images. @@ -31,7 +33,10 @@ const defaults = { svgo: {} } -export default function (options = defaults) { +module.exports = function (opts) { + let options = Object.assign({}, opts) + options = Object.assign(options, defaults) + return function (files, metalsmith, done) { var activePlugins = [] var availablePlugins = { @@ -70,7 +75,7 @@ export default function (options = defaults) { }) ) - .then((results) => done(null, results)) - .catch((err) => done(null, err)) + .then(results => done(null, results)) + .catch(err => done(null, err)) } } diff --git a/package.json b/package.json index b05865d..b3729e5 100644 --- a/package.json +++ b/package.json @@ -24,49 +24,28 @@ "node": ">=4" }, "files": [ - "lib", - "src" + "lib" ], "bugs": { "url": "https://github.com/ahmadnassri/metalsmith-imagemin/issues" }, "scripts": { - "compile": "babel -q src", - "test": "BABEL_ENV=test tap test/*.js --reporter spec --node-arg=--require --node-arg=babel-register", - "pretest": "snazzy && echint", - "coverage": "BABEL_ENV=test tap test/*.js --reporter silent --coverage --nyc-arg=--require --nyc-arg=babel-register", - "codeclimate": "BABEL_ENV=test tap --coverage-report=text-lcov | codeclimate-test-reporter", - "semantic-release": "semantic-release pre && npm publish && semantic-release post" - }, - "standard": { - "ignore": [ - "lib/**" - ] + "lint": "standard && echint", + "pretest": "npm run lint", + "test": "tap test", + "coverage": "tap test --reporter silent --coverage" }, "echint": { "ignore": [ - "test/**/*[.jpg,.png,.gif,.ico]", - "lib/**" + "test/fixtures/**" ] }, - "config": { - "commitizen": { - "path": "./node_modules/cz-conventional-changelog" - } - }, "devDependencies": { - "babel-cli": "^6.18.0", - "babel-plugin-add-module-exports": "^0.2.1", - "babel-preset-env": "0.0.9", - "babel-register": "^6.18.0", - "codeclimate-test-reporter": "^0.4.0", - "cz-conventional-changelog": "^1.2.0", - "echint": "^2.1.0", + "echint": "^4.0.1", "metalsmith": "^2.3.0", "rimraf": "^2.5.4", - "semantic-release": "^6.3.2", - "snazzy": "^5.0.0", - "tap": "^8.0.1" + "standard": "^9.0.2", + "tap": "^10.3.0" }, "dependencies": { "imagemin": "^5.2.2", diff --git a/test/index.js b/test/index.js index d3dbc0d..7834ddf 100644 --- a/test/index.js +++ b/test/index.js @@ -1,13 +1,15 @@ -import fs from 'fs' -import imagemin from '../src/index' -import Metalsmith from 'metalsmith' -import rimraf from 'rimraf' -import { test } from 'tap' +'use strict' + +const fs = require('fs') +const imagemin = require('..') +const Metalsmith = require('metalsmith') +const rimraf = require('rimraf') +const tap = require('tap') const extentions = ['gif', 'png', 'svg', 'jpg'] extentions.forEach(ext => { - test(`should minify ${ext}`, assert => { + tap.test(`should minify ${ext}`, assert => { assert.plan(2) let files = {} @@ -23,7 +25,7 @@ extentions.forEach(ext => { }) }) -test('should not compress corrupted file', assert => { +tap.test('should not compress corrupted file', assert => { assert.plan(2) let files = {} @@ -38,7 +40,7 @@ test('should not compress corrupted file', assert => { }) }) -test('should process a folder', assert => { +tap.test('should process a folder', assert => { assert.plan(5) let smith = new Metalsmith('test/fixtures')