Skip to content

Commit d9d55cf

Browse files
committed
Verbose option (close #62)
1 parent d2c361e commit d9d55cf

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Example configuration:
4040
```json
4141
{
4242
"exclude": ["node_modules/**"],
43+
"verbose": true,
44+
4345
"always-semicolon": true,
4446
"block-indent": true,
4547
"colon-space": true,
@@ -56,6 +58,25 @@ Example configuration:
5658
5759
## Options
5860
61+
### verbose
62+
63+
Available value: `{Boolean}` true
64+
65+
Config mode: `{ "verbose": true }`
66+
```bash
67+
$ ./bin/csscomb ./test
68+
./test/integral.expect.css
69+
./test/integral.origin.css
70+
2 files processed
71+
94 ms spent
72+
```
73+
74+
CLI mode:
75+
```bash
76+
$ ./bin/csscomb ./test --verbose
77+
$ ./bin/csscomb ./test -v
78+
```
79+
5980
### always-semicolon
6081
6182
Available value: `{Boolean}` true

lib/cli.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Command line implementation for CSSComb
33
*
44
* Usage example:
5-
* ./node_modules/.bin/csscomb file1 [dir1 [fileN [dirN]]]
5+
* ./node_modules/.bin/csscomb [options] file1 [dir1 [fileN [dirN]]]
66
*/
77
var fs = require('fs');
88
var program = require('commander');
@@ -12,6 +12,7 @@ var Comb = require('./csscomb');
1212
program
1313
.version(require('../package.json').version)
1414
.usage('[options] <file ...>')
15+
.option('-v, --verbose', 'verbose mode')
1516
.option('-c, --config [path]', 'configuration file path')
1617
.parse(process.argv);
1718

@@ -24,12 +25,20 @@ var configPath = program.config || (process.cwd() + '/.csscomb.json');
2425

2526
if (fs.existsSync(configPath)) {
2627
var comb = new Comb();
27-
comb.configure(require(configPath));
28+
var config = require(configPath);
29+
var time = new Date();
30+
config.verbose = program.verbose === true || config.verbose;
31+
comb.configure(config);
2832
vow.all(program.args.map(function(path) {
2933
return comb.processPath(path);
3034
})).fail(function(e) {
3135
console.log('stack: ', e.stack);
3236
process.exit(1);
37+
}).always(function() {
38+
if (config.verbose) {
39+
console.log(comb.count + ' file' + (comb.count === 1 ? '' : 's') + ' processed');
40+
console.log((new Date().getTime() - time.getTime()) + ' ms spent');
41+
}
3342
});
3443
} else {
3544
console.log('Configuration file ' + configPath + ' was not found.');

lib/csscomb.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Comb.prototype = {
5252
this._exclude = (config.exclude || []).map(function(pattern) {
5353
return new minimatch.Minimatch(pattern);
5454
});
55+
56+
this.count = 0;
57+
this._verbose = config.verbose;
5558
},
5659

5760
/**
@@ -115,7 +118,10 @@ Comb.prototype = {
115118
var _this = this;
116119
if (this._shouldProcess(path) && path.match(/\.css$/)) {
117120
return vfs.read(path, 'utf8').then(function(data) {
118-
return vfs.write(path, _this.processString(data, path), 'utf8');
121+
return vfs.write(path, _this.processString(data, path), 'utf8').then(function() {
122+
_this.count++;
123+
if (_this._verbose) console.log(path);
124+
});
119125
});
120126
}
121127
return null;

0 commit comments

Comments
 (0)