Skip to content

Commit

Permalink
Merge pull request #90 from t32k/develop
Browse files Browse the repository at this point in the history
Release v4.2.0
  • Loading branch information
Shogo Sensui committed Nov 30, 2014
2 parents 8f0e0c8 + 1c08587 commit d40ae25
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 29 deletions.
25 changes: 13 additions & 12 deletions README.md
@@ -1,12 +1,6 @@
![StyleStats](http://i.imgur.com/81kKnxH.png)
# [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 is a Node.js library to collect CSS statistics.

[![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)
[![NPM version](https://badge.fury.io/js/stylestats.svg)](http://badge.fury.io/js/stylestats)
[![Dependency Status](https://david-dm.org/t32k/stylestats.svg)](https://david-dm.org/t32k/stylestats)
> StyleStats is a Node.js library to collect CSS statistics.
## Installation

Expand Down Expand Up @@ -47,10 +41,14 @@ StyleStats!
│ Unique Font Size │ 12px │
│ │ 16px │
├─────────────────────────────────┼────────────────┤
│ Total Unique Font Families │ 0 │
├─────────────────────────────────┼────────────────┤
│ Unique Font Family │ N/A │
├─────────────────────────────────┼────────────────┤
│ Total Unique Colors │ 3 │
├─────────────────────────────────┼────────────────┤
│ Unique Color │ #333
│ │ #CCC
│ Unique Color │ #333333
│ │ #CCCCCC
│ │ RED │
├─────────────────────────────────┼────────────────┤
│ ID Selectors │ 1 │
Expand Down Expand Up @@ -222,7 +220,7 @@ $ stylestats -h
-V, --version output the version number
-c, --config [path] Path and name of the incoming JSON file.
-t, --type [format] Specify the output format. <json|html|csv>
-s, --simple Show compact style's log.
-s, --simple Show compact style log.
-g, --gzip Show gzipped file size.
-n, --number Show only numeral metrics.
-u, --ua [OS] Specify the user agent. <ios|android>
Expand Down Expand Up @@ -295,6 +293,8 @@ Statistics tree of above css:
"lowestCohesionSelector": [ ".foo" ],
"totalUniqueFontSizes": 2,
"uniqueFontSize": [ "12px", "16px" ],
"totalUniqueFontFamilies": 0,
"uniqueFontFamily": [],
"totalUniqueColors": 3,
"uniqueColor": [ "#333333", "#CCCCCC", "RED" ],
"idSelectors": 1,
Expand Down Expand Up @@ -322,6 +322,7 @@ We launched online tool for StyleStats!

## Release History

+ v4.2.0: Add `totalUniqueFontFamilies`, `uniqueFontFamily` metics.
+ v4.1.0: Fix `uniqueColor` metrics. Update `gzip-size` module.
+ v4.0.0: __API is changed:__ `StyleStats.parse()`. Improve CLI tool.
+ v3.2.0: Support request option, and add ClI options.
Expand All @@ -337,4 +338,4 @@ We launched online tool for StyleStats!

# License

Code is released under [the MIT license](LICENSE).
Code is released under [the MIT license](LICENSE).
2 changes: 2 additions & 0 deletions assets/aliases.json
Expand Up @@ -16,6 +16,8 @@
"lowestCohesionSelector": "Lowest Cohesion Selector",
"totalUniqueFontSizes": "Total Unique Font Sizes",
"uniqueFontSize": "Unique Font Size",
"totalUniqueFontFamilies": "Total Unique Font Families",
"uniqueFontFamily": "Unique Font Family",
"totalUniqueColors": "Total Unique Colors",
"uniqueColor": "Unique Color",
"idSelectors": "ID Selectors",
Expand Down
2 changes: 2 additions & 0 deletions assets/default.json
Expand Up @@ -16,6 +16,8 @@
"lowestCohesionSelector": true,
"totalUniqueFontSizes": true,
"uniqueFontSize": true,
"totalUniqueFontFamilies": true,
"uniqueFontFamily": true,
"totalUniqueColors": true,
"uniqueColor": true,
"idSelectors": true,
Expand Down
6 changes: 3 additions & 3 deletions assets/stats.template
@@ -1,8 +1,8 @@
<p class="c-meta">
<div class="c-meta">
<b>Published: </b><span><%= published %></span><br>
<b>Paths: </b><span><%= paths.join(',') %></span><br>
<b>Generator: </b><span><a href="https://github.com/t32k/stylestats">t32k/stylestats // GitHub</a></span><br>
</p>
<b>Generator: </b><span><a href="https://github.com/t32k/stylestats">t32k/stylestats | GitHub</a></span><br>
</div>
<table class="c-data">
<tr class="c-data-s-head">
<th>Metrics</th>
Expand Down
20 changes: 20 additions & 0 deletions lib/analyzer.js
Expand Up @@ -138,6 +138,7 @@ Analyzer.prototype.analyzeSelectors = function() {
* {Number} importantKeywords,
* {Number} floatProperties,
* {Array} uniqueFontSize,
* {Array} uniqueFontFamily
* {Array} uniqueColor,
* {Object} properties
* }
Expand All @@ -150,6 +151,7 @@ Analyzer.prototype.analyzeDeclarations = function() {
importantKeywords: 0,
floatProperties: 0,
uniqueFontSize: [],
uniqueFontFamily: [],
uniqueColor: [],
properties: {}
};
Expand All @@ -172,6 +174,11 @@ Analyzer.prototype.analyzeDeclarations = function() {
result.floatProperties += 1;
}

// if it contains font-family
if (declaration.property.indexOf('font-family') > -1) {
result.uniqueFontFamily.push(declaration.value.replace(/(\!important)/g, '').trim());
}

// if it contains font-size
if (declaration.property.indexOf('font-size') > -1) {
result.uniqueFontSize.push(declaration.value.replace(/\!important/, '').trim());
Expand All @@ -195,6 +202,9 @@ Analyzer.prototype.analyzeDeclarations = function() {
// Return byte size.
result.dataUriSize = Buffer.byteLength(result.dataUriSize, 'utf8');

// Sort `font-family` property.
result.uniqueFontFamily = _.sortBy(_.uniq(result.uniqueFontFamily));

// Sort `font-size` property.
result.uniqueFontSize = _.sortBy(_.uniq(result.uniqueFontSize).slice(), function(item) {
return item.replace(/[^0-9\.]/g, '') - 0;
Expand Down Expand Up @@ -245,8 +255,12 @@ Analyzer.prototype.analyzeDeclarations = function() {
* {Number} lowestCohesionSelector,
* {Number} totalUniqueFontSizes,
* {String} uniqueFontSize,
* {Number} totalUniqueFontFamilies,
* {String} uniqueFontSize,
* {Number} totalUniqueColors,
* {String} uniqueColor,
* {Number} totalUniqueFontFamilies
* {String} uniqueFontFamily,
* {Number} idSelectors,
* {Number} universalSelectors,
* {Number} unqualifiedAttributeSelectors,
Expand Down Expand Up @@ -306,6 +320,12 @@ Analyzer.prototype.analyze = function() {
if (this.options.uniqueFontSize) {
analysis.uniqueFontSize = declarationAnalysis.uniqueFontSize;
}
if (this.options.totalUniqueFontFamilies) {
analysis.totalUniqueFontFamilies = declarationAnalysis.uniqueFontFamily.length;
}
if (this.options.uniqueFontFamily) {
analysis.uniqueFontFamily = declarationAnalysis.uniqueFontFamily;
}
if (this.options.totalUniqueColors) {
analysis.totalUniqueColors = declarationAnalysis.uniqueColor.length;
}
Expand Down
26 changes: 13 additions & 13 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "stylestats",
"version": "4.1.4",
"version": "4.2.0",
"main": "lib/stylestats.js",
"bin": {
"stylestats": "bin/cli.js"
Expand Down Expand Up @@ -41,26 +41,26 @@
"assets"
],
"dependencies": {
"glob": "^4.0.5",
"less": "^1.7.4",
"chalk": "^0.5.1",
"stylus": "^0.48.1",
"numeral": "^1.5.3",
"promise": "^6.0.0",
"request": "^2.40.0",
"cheerio": "^0.17.0",
"json2csv": "^2.2.1",
"cheerio": "^0.18.0",
"cli-table": "^0.3.0",
"commander": "^2.3.0",
"css-parse": "^2.0.0",
"glob": "^4.0.5",
"gzip-size": "^1.0.0",
"json2csv": "^2.2.1",
"less": "^1.7.5",
"numeral": "^1.5.3",
"promise": "^6.0.0",
"request": "^2.40.0",
"stylus": "^0.49.3",
"underscore": "^1.7.0"
},
"devDependencies": {
"mocha": "^1.21.4",
"testem": "^0.6.18",
"istanbul": "^0.3.0",
"coveralls": "^2.11.1",
"mocha-lcov-reporter": "^0.0.1"
"istanbul": "^0.3.0",
"mocha": "^2.0.1",
"mocha-lcov-reporter": "^0.0.1",
"testem": "^0.6.18"
}
}
8 changes: 7 additions & 1 deletion test/stats-test.js
Expand Up @@ -52,6 +52,12 @@ describe('CSS Statistics', function() {
it('should return total unique colors', function() {
assert.equal(statsResult.totalUniqueColors, 2);
});
it('should return total unique font families', function() {
assert.equal(statsResult.totalUniqueFontFamilies, 0);
});
it('should return unique font family', function() {
assert.equal(statsResult.uniqueFontFamily, 0);
});
it('should return id selectors', function() {
assert.equal(statsResult.idSelectors, 1);
});
Expand Down Expand Up @@ -182,7 +188,7 @@ describe('Analyze HTML pages', function() {
if (error) {
throw error;
}
assert.equal(htmlResult.styleElements, 1);
assert.equal(htmlResult.stylesheets, 1);
done();
});

Expand Down

0 comments on commit d40ae25

Please sign in to comment.