├── .editorconfig ├── .gitignore ├── .jshintignore ├── .jshintrc ├── .travis.yml ├── LICENSE.md ├── README.md ├── index.js ├── package.json └── test ├── fixtures └── basic.css └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *.swp 3 | -------------------------------------------------------------------------------- /.jshintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "immed": true, 8 | "newcap": true, 9 | "noarg": true, 10 | "undef": true, 11 | "unused": "vars", 12 | "strict": true, 13 | "globals": { 14 | "describe": false, 15 | "it": false 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | 4 | node_js: 5 | - 'iojs' 6 | - '0.12' 7 | - '0.11' 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 John Otander 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # postcss-cssstats [![Build Status](https://secure.travis-ci.org/cssstats/postcss-cssstats.png?branch=master)](https://travis-ci.org/cssstats/postcss-cssstats) 2 | 3 | A PostCSS plugin for [cssstats](https://github.com/cssstats/cssstats). 4 | 5 | ## Installation 6 | 7 | ```bash 8 | npm install --save postcss-cssstats 9 | ``` 10 | 11 | ## Usage 12 | 13 | This plugin will return a cssstats object in the callback which can 14 | be used for css analysis. For more information on the stats object see 15 | the [cssstats documentation](https://github.com/cssstats/css-statistics#returned-object). 16 | 17 | ```javascript 18 | var postcss = require('postcss'); 19 | var cssstats = require('postcss-cssstats'); 20 | 21 | var output = postcss([ 22 | cssstats(function(stats) { 23 | console.log(stats); 24 | }) 25 | ]).process(css); 26 | ``` 27 | 28 | ### Usage with Gulp.js 29 | 30 | ```js 31 | gulp.task('cssstats', function() { 32 | var cssstats = require('postcss-cssstats'); 33 | var postcss = require('gulp-postcss'); 34 | return gulp 35 | .src('app/_design/less/index.css') 36 | .pipe( 37 | postcss([ 38 | cssstats( 39 | function(stats) { 40 | console.log(stats); 41 | } 42 | ) 43 | ]) 44 | ); 45 | }); 46 | ``` 47 | 48 | ## License 49 | 50 | MIT 51 | 52 | ## Contributing 53 | 54 | 1. Fork it 55 | 2. Create your feature branch (`git checkout -b my-new-feature`) 56 | 3. Commit your changes (`git commit -am 'Add some feature'`) 57 | 4. Push to the branch (`git push origin my-new-feature`) 58 | 5. Create new Pull Request 59 | 60 | Crafted with <3 by John Otander ([@4lpine](https://twitter.com/4lpine)). 61 | 62 | *** 63 | 64 | > This package was initially generated with [yeoman](http://yeoman.io) and the [p generator](https://github.com/johnotander/generator-p.git). 65 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var _ = require('lodash'); 4 | var postcss = require('postcss'); 5 | var cssstats = require('cssstats'); 6 | 7 | module.exports = postcss.plugin('cssstats', function(options, callback) { 8 | if (_.isFunction(options)) { 9 | callback = options; 10 | options = {}; 11 | } else { 12 | options = options || {}; 13 | callback = callback || _.noop; 14 | } 15 | 16 | return function(css, postcssResult) { 17 | callback(cssstats(css)); 18 | }; 19 | }); 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "postcss-cssstats", 3 | "description": "A PostCSS plugin for cssstats.", 4 | "author": "John Otander", 5 | "version": "1.0.1", 6 | "main": "index.js", 7 | "directories": { 8 | "test": "test" 9 | }, 10 | "scripts": { 11 | "test": "mocha test", 12 | "hint": "jshint ." 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/cssstats/postcss-cssstats.git" 17 | }, 18 | "keywords": [ 19 | "cssstats", 20 | "css", 21 | "stats", 22 | "statistics", 23 | "postcss", 24 | "postcss-plugin" 25 | ], 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/cssstats/postcss-cssstats/issues" 29 | }, 30 | "homepage": "https://github.com/cssstats/postcss-cssstats", 31 | "dependencies": { 32 | "cssstats": "1.6.0", 33 | "lodash": "^3.8.0", 34 | "postcss": "^4.1.9" 35 | }, 36 | "devDependencies": { 37 | "is-present": "0.0.1", 38 | "mocha": "*" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/fixtures/basic.css: -------------------------------------------------------------------------------- 1 | .foo { 2 | color: tomato; 3 | } 4 | 5 | .bar .baz { 6 | color: hotpink; 7 | } 8 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var assert = require('assert'); 5 | var postcss = require('postcss'); 6 | var isPresent = require('is-present'); 7 | var postcssCssstats = require('..'); 8 | 9 | describe('postcss-cssstats', function() { 10 | 11 | it('should return a stats object', function(done) { 12 | postcss() 13 | .use(postcssCssstats({}, function(stats) { 14 | assert.ok(isPresent(stats)); 15 | })) 16 | .process(fixture('basic')) 17 | .then(function() { 18 | done(); 19 | }); 20 | }); 21 | }); 22 | 23 | function fixture(name) { 24 | return fs.readFileSync('test/fixtures/' + name + '.css', 'utf8').toString(); 25 | } 26 | --------------------------------------------------------------------------------