Skip to content
This repository was archived by the owner on Mar 28, 2018. It is now read-only.

Commit 2ac28ae

Browse files
committed
Merge pull request #1 from johnotander/master
Add first pass functionality
2 parents 3d54f9f + 41256d2 commit 2ac28ae

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

.jshintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

index.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
'use strict';
22

3-
module.exports = function postcssCssstats(options) {
4-
options = options || {};
3+
var _ = require('lodash');
4+
var postcss = require('postcss');
5+
var cssstats = require('cssstats');
56

6-
return true;
7-
};
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+
// XXX TODO: cssstats should also be able to handle an AST
18+
callback(cssstats(css.toString()));
19+
};
20+
});

package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,25 @@
1515
"url": "https://github.com/cssstats/postcss-cssstats.git"
1616
},
1717
"keywords": [
18-
18+
"cssstats",
19+
"css",
20+
"stats",
21+
"statistics",
22+
"postcss",
23+
"postcss-plugin"
1924
],
2025
"license": "MIT",
2126
"bugs": {
2227
"url": "https://github.com/cssstats/postcss-cssstats/issues"
2328
},
2429
"homepage": "https://github.com/cssstats/postcss-cssstats",
25-
"dependencies": {},
30+
"dependencies": {
31+
"cssstats": "^1.5.1",
32+
"lodash": "^3.8.0",
33+
"postcss": "^4.1.9"
34+
},
2635
"devDependencies": {
36+
"is-present": "0.0.1",
2737
"mocha": "*"
2838
}
2939
}

test/fixtures/basic.css

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.foo {
2+
color: tomato;
3+
}
4+
5+
.bar .baz {
6+
color: hotpink;
7+
}

test/test.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
'use strict';
22

3+
var fs = require('fs');
34
var assert = require('assert');
5+
var postcss = require('postcss');
6+
var isPresent = require('is-present');
47
var postcssCssstats = require('..');
58

69
describe('postcss-cssstats', function() {
710

8-
it('should do something awesome', function() {
9-
assert.equal(postcssCssstats(), true);
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+
});
1020
});
1121
});
22+
23+
function fixture(name) {
24+
return fs.readFileSync('test/fixtures/' + name + '.css', 'utf8').toString();
25+
}

0 commit comments

Comments
 (0)