Skip to content

Commit

Permalink
feat(build): remove babel dependency
Browse files Browse the repository at this point in the history
BREAKING CHANGE: build targets now consolidated into './lib'
  • Loading branch information
Ahmad Nassri committed Mar 19, 2017
1 parent f560ac1 commit 947243b
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 125 deletions.
23 changes: 0 additions & 23 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ engines:

ratings:
paths:
- src/**
- lib/**
- test/**
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*.log
/lib
/node_modules
/.nyc_output
29 changes: 15 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
language: node_js

node_js:
- 4
- 6
- 7

env:
- BABEL_ENV=test
- 6
- 4

matrix:
fast_finish: true
Expand All @@ -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:
Expand Down
34 changes: 6 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 }]
Expand All @@ -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

Expand Down
45 changes: 25 additions & 20 deletions src/index.js → lib/index.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 = {
Expand Down Expand Up @@ -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))
}
}
39 changes: 9 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 10 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand All @@ -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 = {}
Expand All @@ -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')
Expand Down

0 comments on commit 947243b

Please sign in to comment.