Skip to content

Commit

Permalink
Merge 1c378f0 into 6cdf422
Browse files Browse the repository at this point in the history
  • Loading branch information
t32k committed Dec 29, 2016
2 parents 6cdf422 + 1c378f0 commit 225266e
Show file tree
Hide file tree
Showing 29 changed files with 1,279 additions and 1,649 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
node_modules
npm-debug.log
coverage
.nyc_output
22 changes: 0 additions & 22 deletions .jshintrc

This file was deleted.

16 changes: 7 additions & 9 deletions .travis.yml
@@ -1,15 +1,13 @@
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
- COVERALLS_SERVICE_NAME=travis-ci
- secure: PakDWK46H2Df93ENpIYjixCGRNvQRWS1gj2LjeTt8tZniulOZxNf8cNQORIt0tvILWxqQWw299xEd+XeehT86P/p++A/clK3KTLSEnOJz54xRXp9BbMurMq4f2kpsxr4mXal/N7J5Hwh/7oYwi2E3Uks03IQlKa3uC4DFYc4hG8=
script: make test-cov
after_success: make coveralls
after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
11 changes: 0 additions & 11 deletions Makefile

This file was deleted.

40 changes: 16 additions & 24 deletions README.md
@@ -1,8 +1,8 @@
# [StyleStats](http://www.stylestats.org/) [![Build Status](https://secure.travis-ci.org/t32k/stylestats.svg?branch=master)](http://travis-ci.org/t32k/stylestats) [![Coverage Status](http://img.shields.io/coveralls/t32k/stylestats.svg)](https://coveralls.io/r/t32k/stylestats) [![Code Climate](http://img.shields.io/codeclimate/github/t32k/stylestats.svg)](https://codeclimate.com/github/t32k/stylestats) [![Dependency Status](https://david-dm.org/t32k/stylestats.svg)](https://david-dm.org/t32k/stylestats)
# [StyleStats](http://www.stylestats.org/) [![Build Status](https://secure.travis-ci.org/t32k/stylestats.svg?branch=master)](http://travis-ci.org/t32k/stylestats) [![Coverage Status](http://img.shields.io/coveralls/t32k/stylestats.svg)](https://coveralls.io/r/t32k/stylestats) [![Code Climate](http://img.shields.io/codeclimate/github/t32k/stylestats.svg)](https://codeclimate.com/github/t32k/stylestats) [![Dependency Status](https://david-dm.org/t32k/stylestats.svg)](https://david-dm.org/t32k/stylestats) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)

## 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 @@ -224,8 +217,8 @@ $ stylestats -c path/to/.stylestatsrc
API:

```js
var StyleStats = require('stylestats');
var stats = new StyleStats('path/to/stylesheet.css', 'path/to/.stylestatsrc');
const StyleStats = require('stylestats');
const stats = new StyleStats('path/to/stylesheet.css', 'path/to/.stylestatsrc');
```

Default configuration is [here](assets/default.json).
Expand Down Expand Up @@ -255,7 +248,6 @@ $ stylestats --help
-c, --config <path> set configurations
-f, --format <format> set the output format <json|html|md|csv>
-t, --template <path> set the template path for output format
-s, --specs <path> run test with your test specs file
-n, --number show only numeral metrics
-m, --mobile set the mobile user agent
```
Expand Down Expand Up @@ -293,15 +285,15 @@ $ 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');
const StyleStats = require('stylestats');
const stats = new StyleStats('path/to/stylesheet.css');

stats.parse(function (error, result) {
console.log(JSON.stringify(result, null, 2));
});
stats.parse()
.then((result) => console.log(JSON.stringify(result, null, 2)))
.catch((err) => console.log(error));
```

## Example
Expand Down
118 changes: 48 additions & 70 deletions bin/cli.js
@@ -1,49 +1,45 @@
#!/usr/bin/env node

'use strict';

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 util = require('../lib/util');

program
.version(require('../package.json').version)
.usage('[options] <file ...>')
.option('-c, --config <path>', 'set configurations')
.option('-f, --format <format>', 'set the output format <json|html|md|csv>')
.option('-t, --template <path>', 'set the template path for output formant')
.option('-s, --specs <path>', 'run test with your test specs file')
.option('-n, --number', 'show only numeral metrics')
.option('-m, --mobile', 'set the mobile user agent')
.parse(process.argv);


if (!program.args.length) {
if (program.args.length === 0) {
console.log(chalk.red('\n No input file specified.'));
program.help();
}

// 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 = {
"published": false,
"paths": false,
"mostIdentifierSelector": false,
"lowestCohesionSelector": false,
"uniqueFontFamilies": false,
"uniqueFontSizes": false,
"uniqueColors": false,
"propertiesCount": false
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,
lowestCohesionSelector: false,
uniqueFontFamilies: false,
uniqueFontSizes: false,
uniqueColors: false,
propertiesCount: false
};
var userConfig = {};
let userConfig = {};

if (program.mobile) {
config.requestOptions.headers['User-Agent'] = MOBILE_UA;
Expand All @@ -52,66 +48,48 @@ 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 {
userConfig = JSON.parse(configString);
} catch (e) {
throw e;
} catch (err) {
throw err;
}
} else if (util.isObject(program.config)) {
userConfig = config;
}
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) {
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());
return;
}
// Other formants
switch (program.format) {
case 'json':
format.toJSON(function (json) {
console.log(json);
});
break;
case 'csv':
format.toCSV(function (csv) {
console.log(csv);
});
case 'md':
console.log(format.toMarkdown());
break;
case 'html':
format.toHTML(function (html) {
console.log(html);
});
console.log(format.toHTML());
break;
case 'md':
format.toMarkdown(function (md) {
console.log(md);
});
case 'json':
console.log(format.toJSON());
break;
case 'csv':
format.toCSV().then(csv => console.log(csv));
break;
default:
format.toTable(function (table) {
console.log(' StyleStats!\n' + table);
});
console.log(` StyleStats!
${format.toTable()}`);
break;
}
} else {
specs(result, program.specs);
}
});
})
.catch(err => console.log(chalk.red(` [ERROR] ${err.message}`)));

0 comments on commit 225266e

Please sign in to comment.