Permalink
Browse files

# This is a combination of 2 commits.

# The first commit's message is:

Add prettify flag

# This is the 2nd commit message:

Update Readme

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Fri Dec 30 04:42:23 2016 +0900
#
# interactive rebase in progress; onto 0eb5246
# Last commands done (8 commands done):
#    pick 25c59b4 Add prettify flag
#    s 1bd4496 Update Readme
# Next commands to do (2 remaining commands):
#    pick bed2b91 Add prettify method
#    pick 6a98da4 Use this keyword
# You are currently editing a commit while rebasing branch 'v7.0' on '0eb5246'.
#
# Changes to be committed:
#	modified:   README.md
#	modified:   bin/cli.js
#	modified:   lib/format.js
#	modified:   lib/stylestats.js
#
  • Loading branch information...
t32k committed Dec 29, 2016
1 parent 591f15d commit 3bc4e8f6413900001079b66ca0aa34056fd06bc6
Showing with 24 additions and 13 deletions.
  1. +11 −9 README.md
  2. +5 −0 bin/cli.js
  3. +1 −2 lib/format.js
  4. +7 −2 lib/stylestats.js
View
@@ -119,17 +119,17 @@ If you specify an HTML page, StyleStats will analyze stylesheets and `style` ele
$ stylestats https://t32k.me/
```
`--format` option outputs JSON, HTML, Markdown and CSV.
`--format` option outputs JSON and CSV.
```sh
$ stylestats foo.css -f <json|html|md|csv>
$ stylestats foo.css -f <json|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.
If you have __[gist](https://github.com/defunkt/gist)__ installed, you can upload StyleStats data to [GitHub Gist](https://gist.github.com/) with a one-liner command.
```sh
$ stylestats https://t32k.me/ -f md > stats.md && gist stats.md
https://gist.github.com/9725673
$ stylestats https://t32k.me/ > stats.txt && gist stats.txt
>> https://gist.github.com/anonymous/d6259fce3d80d2c71ebc7edc71c06088
```
## Metrics
@@ -246,8 +246,8 @@ $ stylestats --help
-h, --help output usage information
-V, --version output the version number
-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
-f, --format <format> set the output format <json|csv>
-p, --prettify prettify raw data
-n, --number show only numeral metrics
-m, --mobile set the mobile user agent
```
@@ -276,7 +276,7 @@ $ stylestats path/to/stylesheet.css -c .stylestatsrc
## API Reference
### `new StyleStats(stylesheet, config)`
### `new StyleStats(stylesheet, [config])`
1. `stylesheet` Required `String|Array` Stylesheet file path or its array.
2. `config` Optional `String|Object` Configuration JSON file path or object.
@@ -285,7 +285,9 @@ $ 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()`
### `StyleStats#parse([flag])`
`. `flag` Optional `Boolean` Return prettified data.
```javascript
const StyleStats = require('stylestats');
View
@@ -6,12 +6,14 @@ const program = require('commander');
const StyleStats = require('../lib/stylestats');
const Format = require('../lib/format');
const util = require('../lib/util');
const prettify = require('../lib/prettify');
program
.version(require('../package.json').version)
.usage('[options] <file ...>')
.option('-c, --config <path>', 'set configurations')
.option('-f, --format <format>', 'set the output format <json|csv>')
.option('-p, --prettify', 'prettify raw data')
.option('-n, --number', 'show only numeral metrics')
.option('-m, --mobile', 'set the mobile user agent')
.parse(process.argv);
@@ -64,6 +66,9 @@ Object.assign(config, userConfig);
const stats = new StyleStats(program.args, config);
stats.parse()
.then(result => {
if (program.prettify || !program.format) {
result = prettify(result);
}
const format = new Format(result);
// Other formants
switch (program.format) {
View
@@ -1,6 +1,5 @@
const Table = require('cli-table');
const json2csv = require('json2csv');
const prettify = require('../lib/prettify');
class Format {
constructor(context) {
@@ -43,7 +42,7 @@ class Format {
compact: false
}
});
const data = prettify(this.context);
const data = this.context;
Object.keys(data).forEach(key => {
const row = {};
row[key] = data[key];
View
@@ -11,6 +11,7 @@ const path = require('path');
const glob = require('glob');
const validUrl = require('valid-url');
const util = require('./util');
const prettify = require('./prettify');
const Parser = require('./parser');
const Analyzer = require('./analyzer');
@@ -70,16 +71,17 @@ class StyleStats {
}
/**
* Parse CSS
* @param {Boolean} flag(optional)
* @returns {Promise}
*/
parse() {
parse(flag) {
const that = this;
return new Promise((resolve, reject) => {
this.parser.parse().then(data => {
const analyzedData = new Analyzer(data, that.options).analyze();
const stats = {};
let stats = {};
if (that.options.published) {
stats.published = new Date();
}
@@ -98,6 +100,9 @@ class StyleStats {
if (that.options.mediaQueries) {
stats.mediaQueries = data.mediaQueries;
}
if (flag) {
stats = prettify(stats);
}
resolve(stats);
}).catch(err => reject(err));
});

0 comments on commit 3bc4e8f

Please sign in to comment.