Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update v7.0 #155

Merged
merged 42 commits into from
Dec 31, 2016
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5ec6794
Update dependencies
t32k Oct 28, 2016
c72cb65
Use eslint instead of jshint
t32k Oct 28, 2016
c1d98b1
ES6fy lib/template.js
t32k Oct 28, 2016
a3c9028
ES6fy lib/util.js
t32k Nov 9, 2016
af3df75
ES6fy lib/stylestats.js
t32k Nov 9, 2016
51b8b6f
ES6fy bin/cli.js
t32k Nov 9, 2016
aef23ee
lib/prettify.js
t32k Nov 9, 2016
f7d6e13
ES6fy lib/parser.js
t32k Nov 9, 2016
710d2e0
lib/analyzer.js
t32k Nov 9, 2016
6ed9e73
Update README.md
t32k Nov 9, 2016
9426836
Use eslint
t32k Nov 9, 2016
2a0e7b2
Add istanbul
t32k Nov 9, 2016
8478c3f
Update travisyml
t32k Nov 9, 2016
12562e5
Add README.md
t32k Nov 9, 2016
0b56a92
Fix test
t32k Dec 27, 2016
747e596
Change number formats
t32k Dec 28, 2016
3306b53
Update UA
t32k Dec 28, 2016
fcf4357
Remove class method of Template
t32k Dec 28, 2016
37228c9
Change some methods name
t32k Dec 28, 2016
12f1077
Remove Template library
t32k Dec 28, 2016
f25acbf
Covert callback func to promise func
t32k Dec 28, 2016
b3208bc
Change css parser module
t32k Dec 28, 2016
3d5f42c
Covert callback func to promise func
t32k Dec 28, 2016
0549674
Covert callback func to promise func on stylestats.js
t32k Dec 28, 2016
29e9c56
Fix a util func
t32k Dec 28, 2016
62bb836
Update README.md
t32k Dec 28, 2016
67bdeaf
Update README.md
t32k Dec 28, 2016
8d7ba00
Use xo, drop eslintrc
t32k Dec 29, 2016
4d3f5b7
Update Readme.md
t32k Dec 29, 2016
3be4591
Fix regexp
t32k Dec 29, 2016
805042c
Fix xo commnents in cli.js
t32k Dec 29, 2016
60ee756
Fix xo commnents in parser and specs.js
t32k Dec 29, 2016
c6fff56
Use ava insted of mocha
t32k Dec 29, 2016
0eb5246
Drop test specs feature
t32k Dec 29, 2016
2477c7d
Update travisyml
t32k Dec 29, 2016
e19aa0b
Add nyc for code coverage
t32k Dec 29, 2016
8526032
# This is a combination of 3 commits.
t32k Dec 29, 2016
591f15d
Drop handlebars
t32k Dec 29, 2016
3bc4e8f
# This is a combination of 2 commits.
t32k Dec 29, 2016
38b8a99
Add prettify method
t32k Dec 31, 2016
951e1fb
Use this keyword
t32k Dec 31, 2016
9508c41
Cosme 2017
t32k Dec 31, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "eslint:recommended",
"env": {
"node": true,
"es6": true
},
"rules": {
"arrow-parens": "error",
"arrow-spacing": "error",
"generator-star-spacing": "error",
"no-duplicate-imports": "error",
"no-useless-computed-key": "error",
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-var": "error",
"object-shorthand": "error",
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",
"rest-spread-spacing": "error",
"template-curly-spacing": "error",
"yield-star-spacing": "error"
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use xo instead of eslint and its config.

22 changes: 0 additions & 22 deletions .jshintrc

This file was deleted.

10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
sudo: false
language: node_js
node_js:
- '5'
- '4'
notifications:
slack:
secure: qW1mL7rMeWxkZq1lriz5KhVxz+/R2HGg69dpcHp3RpxOW1CpJ6qry4m+Zk5GidkJWNi0kxGBKYsCClE7Gmi4R9RgW4wXrP+RjfO1Zea/oqvlN7GHel5zXq+yhEMEdD3oXsygPa+dZ/letM3oOiZCi4VBoE7MUt3T1jlsF9h/+nc=
- '7'
- '6'
cache:
directories:
- node_modules
env:
global:
- NPM_CONFIG_PROGRESS=false
Expand Down
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Installation

StyleStats works on Node.js `>=4.x`.
StyleStats works on Node.js `>=6.x`.

```
$ npm install -g stylestats
Expand All @@ -22,13 +22,13 @@ StyleStats!
├─────────────────────────────────┼──────────────────────────┤
│ Style Elements │ 0 │
├─────────────────────────────────┼──────────────────────────┤
│ Size │ 240B
│ Size │ 240.0B
├─────────────────────────────────┼──────────────────────────┤
│ Data URI Size │ 0 │
├─────────────────────────────────┼──────────────────────────┤
│ Ratio of Data URI Size │ 0.0%
│ Ratio of Data URI Size │ 0
├─────────────────────────────────┼──────────────────────────┤
│ Gzipped Size │ 158B
│ Gzipped Size │ 158.0B
├─────────────────────────────────┼──────────────────────────┤
│ Rules │ 7 │
├─────────────────────────────────┼──────────────────────────┤
Expand Down Expand Up @@ -110,13 +110,13 @@ $ stylestats 'path/**/*.css'
You can specify a remote CSS file.

```sh
$ stylestats http://t32k.me/wisteria/css/wisteria.css
$ stylestats https://t32k.me/wisteria/css/wisteria.css
```

If you specify an HTML page, StyleStats will analyze stylesheets and `style` elements.

```sh
$ stylestats http://t32k.me/
$ stylestats https://t32k.me/
```

`--format` option outputs JSON, HTML, Markdown and CSV.
Expand All @@ -128,17 +128,10 @@ $ stylestats foo.css -f <json|html|md|csv>
If you have __[gist](https://github.com/defunkt/gist)__ installed, you can upload StyleStats data to [GitHub Gist](https://gist.github.com/9725673) with a one-liner command.

```sh
$ stylestats http://t32k.me/ -f md > stats.md && gist stats.md
$ stylestats https://t32k.me/ -f md > stats.md && gist stats.md
https://gist.github.com/9725673
```

## Other tools

+ [Online tool](http://www.stylestats.org/)
+ [Gulp module](https://github.com/1000ch/gulp-stylestats) by [@1000ch](https://github.com/1000ch)
+ [Grunt module](https://github.com/tvooo/grunt-stylestats) by [@tvooo](https://github.com/tvooo)


## Metrics

![Metrics](http://i.imgur.com/oEABjEl.png)
Expand Down Expand Up @@ -293,15 +286,19 @@ $ stylestats path/to/stylesheet.css -c .stylestatsrc

Config list is show to [default.json](https://github.com/t32k/stylestats/blob/master/assets/default.json)

### `StyleStats.parse(fn)`
### `StyleStats#parse()`

```javascript
var StyleStats = require('stylestats');
var stats = new StyleStats('path/to/stylesheet.css');

stats.parse(function (error, result) {
console.log(JSON.stringify(result, null, 2));
});
stats.parse()
.then(function(result) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why function?

console.log(JSON.stringify(result, null, 2));
})
.catch(function(error) {
console.log(error);
});
```

## Example
Expand Down
110 changes: 48 additions & 62 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/env node

'use strict';
/* eslint no-console: "off" */

var fs = require('fs');
var chalk = require('chalk');
var program = require('commander');

var StyleStats = require('../lib/stylestats');
var Format = require('../lib/format');
var specs = require('../lib/specs');
var util = require('../lib/util');
const fs = require('fs');
const chalk = require('chalk');
const program = require('commander');
const StyleStats = require('../lib/stylestats');
const Format = require('../lib/format');
const specs = require('../lib/specs');
const util = require('../lib/util');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

util and fotmat should be exposed as property of stylestats.
This requires refactoring.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next time! I believe you can do that :)


program
.version(require('../package.json').version)
Expand All @@ -29,11 +28,13 @@ if (!program.args.length) {
}

// Config
var config = {
requestOptions: {headers: {}}
const config = {
requestOptions: {
headers: {}
}
};
var MOBILE_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 Version/8.0 Safari/600.1.4';
var numberConfig = {
const MOBILE_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A5297c Safari/602.1';
const numberConfig = {
"published": false,
"paths": false,
"mostIdentifierSelector": false,
Expand All @@ -43,7 +44,7 @@ var numberConfig = {
"uniqueColors": false,
"propertiesCount": false
};
var userConfig = {};
let userConfig = {};

if (program.mobile) {
config.requestOptions.headers['User-Agent'] = MOBILE_UA;
Expand All @@ -52,7 +53,7 @@ if (program.number) {
Object.assign(config, numberConfig);
}
if (program.config && util.isFile(program.config)) {
var configString = fs.readFileSync(program.config, {
const configString = fs.readFileSync(program.config, {
encoding: 'utf8'
});
try {
Expand All @@ -67,51 +68,36 @@ Object.assign(config, userConfig);


// Parse
var stats = new StyleStats(program.args, config);
stats.parse(function (error, result) {
if (error) {
console.log(chalk.red(' [ERROR] ' + error.message));
}
var format = new Format(result);
if (fs.existsSync(program.template)) {

format.setTemplate(fs.readFileSync(program.template, {
encoding: 'utf8'
}));

format.parseTemplate(function (text) {
console.log(text);
});

} else if (!program.specs) {
switch (program.format) {
case 'json':
format.toJSON(function (json) {
console.log(json);
});
break;
case 'csv':
format.toCSV(function (csv) {
console.log(csv);
});
break;
case 'html':
format.toHTML(function (html) {
console.log(html);
});
break;
case 'md':
format.toMarkdown(function (md) {
console.log(md);
});
break;
default:
format.toTable(function (table) {
console.log(' StyleStats!\n' + table);
});
break;
const stats = new StyleStats(program.args, config);
stats.parse()
.then((result) => {
const format = new Format(result);
// Custom format
if (fs.existsSync(program.template)) {
format.setTemplate(fs.readFileSync(program.template, { encoding: 'utf8' }));
console.log(format.getFormattedText());
// Other formants
} else if (!program.specs) {
switch (program.format) {
case 'md':
console.log(format.toMarkdown());
break;
case 'html':
console.log(format.toHTML());
break;
case 'json':
console.log(format.toJSON());
break;
case 'csv':
format.toCSV().then((csv) => console.log(csv));
break;
default:
console.log(` StyleStats!
${format.toTable()}`);
break;
}
} else {
specs(result, program.specs);
}
} else {
specs(result, program.specs);
}
});
})
.catch((error) => console.log(chalk.red(` [ERROR] ${error.message}`)));