-
Notifications
You must be signed in to change notification settings - Fork 70
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
Update v7.0 #155
Changes from 27 commits
5ec6794
c72cb65
c1d98b1
a3c9028
af3df75
51b8b6f
aef23ee
f7d6e13
710d2e0
6ed9e73
9426836
2a0e7b2
8478c3f
12562e5
0b56a92
747e596
3306b53
fcf4357
37228c9
12f1077
f25acbf
b3208bc
3d5f42c
0549674
29e9c56
62bb836
67bdeaf
8d7ba00
4d3f5b7
3be4591
805042c
60ee756
c6fff56
0eb5246
2477c7d
e19aa0b
8526032
591f15d
3bc4e8f
38b8a99
951e1fb
9508c41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
} | ||
} | ||
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
## Installation | ||
|
||
StyleStats works on Node.js `>=4.x`. | ||
StyleStats works on Node.js `>=6.x`. | ||
|
||
``` | ||
$ npm install -g stylestats | ||
|
@@ -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 │ | ||
├─────────────────────────────────┼──────────────────────────┤ | ||
|
@@ -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. | ||
|
@@ -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) | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
console.log(JSON.stringify(result, null, 2)); | ||
}) | ||
.catch(function(error) { | ||
console.log(error); | ||
}); | ||
``` | ||
|
||
## Example | ||
|
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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, | ||
|
@@ -43,7 +44,7 @@ var numberConfig = { | |
"uniqueColors": false, | ||
"propertiesCount": false | ||
}; | ||
var userConfig = {}; | ||
let userConfig = {}; | ||
|
||
if (program.mobile) { | ||
config.requestOptions.headers['User-Agent'] = MOBILE_UA; | ||
|
@@ -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 { | ||
|
@@ -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}`))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
xo
instead ofeslint
and its config.