Skip to content

Commit

Permalink
Use babel and ava instead of mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
komachi committed Apr 8, 2016
1 parent 1bb4a2e commit 65234e3
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 152 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ jspm_packages
# Optional REPL history
.node_repl_history

lib

38 changes: 38 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

.babelrc
.gitignore
.travis.yml
node_modules
src
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changlelog

## [1.0.1] - 2016-04-08
- Use babel and ava instead of mocha

## [1.0.0] - 2016-04-07
- Initial version
35 changes: 29 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "usedcss",
"version": "1.0.0",
"version": "1.0.1",
"description": "Extract only styles presented in your html files.",
"main": "index.js",
"main": "lib/index.js",
"scripts": {
"test": "./node_modules/.bin/eslint *.js tests/*.js && ./node_modules/jscs/bin/jscs *.js tests/*.js && ./node_modules/mocha/bin/mocha tests/*.tests.js"
"build": "./node_modules/.bin/babel src -d lib",
"prepublish": "npm build",
"test": "./node_modules/.bin/eslint src/*js tests/*.js && ./node_modules/.bin/ava && ./node_modules/.bin/jscs src/*.js tests/*.js"
},
"repository": {
"type": "git",
Expand All @@ -31,6 +33,16 @@
"node": true,
"es6": true,
"mocha": true
},
"parserOptions": {
"sourceType": "module"
},
"rules": {
"quotes": [
2,
"single",
"avoid-escape"
]
}
},
"jscsConfig": {
Expand All @@ -40,6 +52,15 @@
"requireTrailingComma": null,
"requireCapitalizedComments": null
},
"ava": {
"require": [ "babel-register" ],
"failFast": true,
"verbose": true,
"babel": "inherit",
"files": [
"tests/*.tests.js"
]
},
"dependencies": {
"angular-expressions": "^0.3.0",
"bluebird": "^3.3.4",
Expand All @@ -50,10 +71,12 @@
"postcss": "^5.0.19"
},
"devDependencies": {
"ava": "^0.14.0",
"babel-cli": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"babel-register": "^6.7.2",
"eslint": "^2.7.0",
"eslint-config-defaults": "^9.0.0",
"expect": "^1.16.0",
"jscs": "^2.11.0",
"mocha": "^2.4.5"
"jscs": "^2.11.0"
}
}
36 changes: 18 additions & 18 deletions index.js → src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';
const Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs'));
const glob = Promise.promisify(require('multi-glob').glob);
const postcss = require('postcss');
const noop = require('node-noop').noop;
const cheerio = require('cheerio');
const expressions = require('angular-expressions');
const isRegex = require('is-regex');
import Promise from 'bluebird';
import {readFile} from 'fs';
import {glob as glob} from 'multi-glob';
import postcss from 'postcss';
import {noop} from 'node-noop';
import cheerio from 'cheerio';
import expressions from 'angular-expressions';
import isRegex from 'is-regex';

module.exports = postcss.plugin('usedcss', (options) => {
var htmls = [];
return function(css) {
return (css) => {
return new Promise((resolve, reject) => {
if (!options.html) {
reject('No html files specified.');
Expand All @@ -28,11 +28,11 @@ module.exports = postcss.plugin('usedcss', (options) => {
reject('ignoreRegexp option should contain regular expressions.');
return;
}
if (options.ngclass && typeof options.ngclass != 'boolean') {
if (options.ngclass && typeof options.ngclass !== 'boolean') {
reject('ngclass option should be boolean.');
return;
}
if (options.ignoreNesting && typeof options.ignoreNesting != 'boolean') {
if (options.ignoreNesting && typeof options.ignoreNesting !== 'boolean') {
reject('ignoreNesting option should be boolean.');
return;
}
Expand All @@ -45,10 +45,10 @@ module.exports = postcss.plugin('usedcss', (options) => {
promise = Promise.resolve();
}
promise.then(() => {
return glob(options.html)
return Promise.promisify(glob)(options.html)
.then((files) => {
return Promise.map(files, (file) => {
return fs.readFileAsync(file).then((content) => {
return Promise.promisify(readFile)(file).then((content) => {
htmls.push(cheerio.load(content.toString()));
return Promise.resolve();
});
Expand Down Expand Up @@ -97,21 +97,21 @@ module.exports = postcss.plugin('usedcss', (options) => {
// sounds hacky, but it works
promises.push(
Promise.map(rule.selectors, (selector) => {
var promise;
var pr;
if (options.ignoreRegexp) {
promise = Promise.map(options.ignoreRegexp, (item) => {
pr = Promise.map(options.ignoreRegexp, (item) => {
if (item.test(selector)) {
return Promise.reject();
}
});
} else {
promise = Promise.resolve();
pr = Promise.resolve();
}
return promise.then(() => {
return pr.then(() => {
// remove pseudo-classes from selectors
selector = selector.replace(/::?[a-zA-Z-]*$/g, '');
if (options.ignoreNesting) {
selector = selector.replace(/^.*( |>|<)/g, '')
selector = selector.replace(/^.*( |>|<)/g, '');
}
return Promise.map(htmls, (html) => {
if (
Expand Down
38 changes: 38 additions & 0 deletions tests/error.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import test from 'ava';
import {runTest} from './runTest.helper.js';

test('Should retun error if there is no html files specified', t => {
return runTest({html: null}).catch(err => {
t.is(err, 'No html files specified.');
});
});

test('Should retun error if ignore is not an array', t => {
return runTest({ignore: 'test'}).catch(err => {
t.is(err, 'ignore option should be an array.');
});
});

test('Should return error if ignoreRegexp is not an array', t => {
return runTest({ignoreRegexp: 'test'}).catch(err => {
t.is(err, 'ignoreRegexp option should be an array.');
});
});

test('Should retun error if ignoreRegexp contains not a regexp', t => {
return runTest({ignoreRegexp: ['test']}).catch(err => {
t.is(err, 'ignoreRegexp option should contain regular expressions.');
});
});

test('Should retun error if ngclass is not boolean', t => {
return runTest({ngclass: 'test'}).catch(err => {
t.is(err, 'ngclass option should be boolean.');
});
});

test('Should retun error if ignoreNesting is not boolean', t => {
return runTest({ignoreNesting: 'test'}).catch(err => {
t.is(err, 'ignoreNesting option should be boolean.');
});
});
48 changes: 0 additions & 48 deletions tests/errors.tests.js

This file was deleted.

Loading

0 comments on commit 65234e3

Please sign in to comment.