Skip to content

Commit

Permalink
First release.
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-lau committed Oct 26, 2015
0 parents commit 780f898
Show file tree
Hide file tree
Showing 25 changed files with 887 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "eslint-config-airbnb"
}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.gobble/
.gobble-build/
coverage/
dist/
node_modules/
tmp/
.DS_Store
npm-debug.log
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.gobble/
.gobble-build/
coverage/
node_modules/
tmp/
npm-debug.log
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: node_js
node_js:
- "node"
- "iojs"
after_script:
- npm run coverage
- cat coverage/lcov.info | node_modules/.bin/coveralls
- codeclimate-test-reporter < coverage/lcov.info
addons:
code_climate:
repo_token: 191a895846ac9a5a25bb28e3620358918674565b9232f386d126dd6be4b3ad45
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2015 Justin Lau <justin@tclau.com>

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 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.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# gobble-html-minifer

[![Build Status](https://img.shields.io/travis/justin-lau/gobble-html-minifier/master.svg)](https://travis-ci.org/justin-lau/gobble-html-minifier)
[![Coverage Status](https://img.shields.io/coveralls/justin-lau/gobble-html-minifier/master.svg)](https://coveralls.io/github/justin-lau/gobble-html-minifier?branch=master)
[![Dependencies](https://david-dm.org/justin-lau/gobble-html-minifier/master.svg)](https://david-dm.org/justin-lau/gobble-html-minifier/master)

Simple wrapper to use [html-minifier](https://github.com/kangax/html-minifier) with [gobble](https://github.com/gobblejs/gobble).

## Installation

First, you need to have gobble installed - see the [gobble readme](https://github.com/gobblejs/gobble) for details. Then,

```bash
npm install --save-dev gobble-html-minifier
```

## Usage

**gobblefile.js**

```js
var gobble = require('gobble');

module.exports = gobble('src').transform('html-minifier', options);
```

The `options` argument, if specified, is passed to `html-minifier`. Please refer to the [original documentation](https://github.com/kangax/html-minifier#options-quick-reference).

There is one extra option `preset` in this plugin to try to make developer's life easier.

### preset
Type: `string|undefined`

The `preset` option accepts one of three string value: `"minimal"`, `"safe"`, and `"all"`. They correspond to the presets found on [html-minifier's Github page](https://kangax.github.io/html-minifier/). If left undefined or when set to unsupported value, it doesn't affect other options at all. Otherwise, the preset options act as the default and other options passed in overrides the preset.

#### Usage

```js
// to use the "minimal" preset alone
gobble('src').transform('html-minifier', { preset: 'minimal' });

// use the "minimal" preset but turn off "removeComments"
gobble('src').transform('html-minifier', {
preset: 'minimal',
removeComments: false,
});
```
30 changes: 30 additions & 0 deletions gobblefile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'babel/polyfill';
import gobble from 'gobble';
import { CLIEngine } from 'eslint';

const SRC_DIR = 'src';

/**
* Scripts
*/
const scriptNode = gobble(SRC_DIR)
.observe(function eslint(inputdir) {
return new Promise((resolve, reject) => {
const cli = new CLIEngine();
const formatter = cli.getFormatter();
const report = cli.executeOnFiles([inputdir]);
if (report.errorCount || report.warningCount) {
reject(formatter(report.results));
} else {
resolve();
}
});
})
.transform('babel')
.transform('uglifyjs', {
sourceMap: process.env.ENV !== 'production',
});

export default gobble([
scriptNode,
]);
55 changes: 55 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "gobble-html-minifier",
"version": "0.1.0",
"description": "Use html-minifier with gobble",
"main": "dist/index.js",
"scripts": {
"mocha": "mocha --compilers js:babel/register -- tests/*.spec.js",
"lint": "eslint src tests",
"test:watch": "chokidar 'src/**/.js' 'tests/**/*.js' -c 'npm run -s lint && npm run -s mocha'",
"coverage": "babel-node ./node_modules/.bin/isparta cover node_modules/.bin/_mocha -- --reporter dot tests/*.spec.js",
"start": "npm run -s test; npm run -s test:watch",
"test": "npm run -s lint && npm run -s mocha",
"build": "ENV=production babel-node ./node_modules/.bin/gobble build --force dist",
"prepublish": "npm run -s test && npm run -s build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/justin-lau/gobble-html-minifier.git"
},
"keywords": [
"gobble-plugin",
"html-minifier"
],
"author": "Justin Lau <justin@tclau.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/justin-lau/gobble-html-minifier/issues"
},
"homepage": "https://github.com/justin-lau/gobble-html-minifier#readme",
"dependencies": {
"html-minifier": "^1.0.0",
"lodash-node": "^3.10.1"
},
"devDependencies": {
"babel": "^5.8.29",
"babel-eslint": "^4.1.3",
"chai": "^3.4.0",
"chai-as-promised": "^5.1.0",
"chai-fs": "github:jenius/chai-fs#8822feb",
"chokidar": "^1.2.0",
"chokidar-cli": "^1.1.0",
"coveralls": "^2.11.4",
"eslint": "^1.7.3",
"eslint-config-airbnb": "^0.1.0",
"eslint-plugin-react": "^3.6.3",
"gobble": "^0.10.2",
"gobble-babel": "^5.5.8",
"gobble-cli": "^0.6.0",
"gobble-uglifyjs": "^0.2.1",
"isparta": "^3.1.0",
"mocha": "^2.3.3",
"parallelshell": "^2.0.0",
"sander": "^0.4.0"
}
}
75 changes: 75 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { minify } from 'html-minifier';
import lodash from 'lodash-node';

// Presets borrowed from https://kangax.github.io/html-minifier/
const presets = {
minimal: {
removeComments: true,
removeCommentsFromCDATA: true,
removeCDATASectionsFromCDATA: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
minifyJs: true,
minifyCss: true,
},
safe: {
removeComments: true,
removeCommentsFromCdata: true,
removeCdataSectionsFromCdata: true,
collapseWhitespace: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeEmptyElements: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
caseSensitive: true,
keepClosingSlash: true,
minifyJs: true,
minifyCss: true,
},
all: {
removeComments: true,
removeCommentsFromCDATA: true,
removeCDATASectionsFromCDATA: true,
collapseWhitespace: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeIgnored: true,
removeEmptyElements: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
caseSensitive: true,
keepClosingSlash: true,
minifyJs: true,
minifyCss: true,
},
};

export default function htmlminifier(inputFile, _options = {}) {
let options = {};

if (_options.preset && presets[_options.preset]) {
options = lodash.cloneDeep(presets[_options.preset]);
delete _options.preset;
}

lodash.merge(options, _options);

return minify(inputFile, options);
}

htmlminifier.defaults = { accept: ['.htm', '.html'] };
5 changes: 5 additions & 0 deletions tests/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"mocha": true
}
}
9 changes: 9 additions & 0 deletions tests/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import chaiFS from 'chai-fs';

chai.use(chaiAsPromised);
chai.use(chaiFS);
chai.should();

export default chai;

0 comments on commit 780f898

Please sign in to comment.