Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ To run `csscomb`, you can use the following command from the project root:
-h, --help output usage information
-V, --version output the version number
-c, --config [path] configuration file path
-l, --lint in case some fixes needed returns an error
```

## Configuration
Expand Down
25 changes: 17 additions & 8 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ program
.usage('[options] <file ...>')
.option('-v, --verbose', 'verbose mode')
.option('-c, --config [path]', 'configuration file path')
.option('-l, --lint', 'in case some fixes needed returns an error')
.parse(process.argv);

if (!program.args.length) {
Expand All @@ -26,21 +27,29 @@ var configPath = program.config || (process.cwd() + '/.csscomb.json');
if (fs.existsSync(configPath)) {
var comb = new Comb();
var config = require(configPath);
var time = new Date();

console.time('spent');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ух, совсем забыл про time. Спасибо, что поправил.


config.verbose = program.verbose === true || config.verbose;
config.lint = program.lint;

comb.configure(config);
vow.all(program.args.map(function(path) {
return comb.processPath(path);
})).fail(function(e) {
console.log('stack: ', e.stack);
process.exit(1);
}).always(function() {

vow.all(program.args.map(comb.processPath.bind(comb)))
.then(function() {
if (config.verbose) {
console.log('');
console.log(comb.processed + ' file' + (comb.processed === 1 ? '' : 's') + ' processed');
console.log(comb.changed + ' file' + (comb.changed === 1 ? '' : 's') + ' fixed');
console.log((new Date().getTime() - time.getTime()) + ' ms spent');
console.timeEnd('spent');
}
if (config.lint && comb.tbchanged) {
process.exit(1);
}
})
.fail(function(e) {
console.log('stack: ', e.stack);
process.exit(1);
});
} else {
console.log('Configuration file ' + configPath + ' was not found.');
Expand Down
24 changes: 19 additions & 5 deletions lib/csscomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var gonzales = require('gonzales');
var minimatch = require('minimatch');
var vow = require('vow');
var vfs = require('vow-fs');
var doNothing = function() {};

/**
* Starts Code Style processing process.
Expand Down Expand Up @@ -56,8 +57,10 @@ Comb.prototype = {
});

this.processed = 0;
this.tbchanged = 0;
this.changed = 0;
this._verbose = config.verbose;
this._lint = config.lint;
},

/**
Expand Down Expand Up @@ -125,11 +128,22 @@ Comb.prototype = {
return vfs.read(path, 'utf8').then(function(data) {
var processedData = _this.processString(data, path);
var changed = data !== processedData;
return vfs.write(path, processedData, 'utf8').then(function() {
_this.processed++;
if (changed) _this.changed++;
if (_this._verbose) console.log((changed ? '✓' : ' ') + ' ' + path);
});
var lint = _this._lint;

var tick = changed ? (lint ? '!' : '✓') : ' ';
var message = _this._verbose ? console.log.bind(null, tick, path) : doNothing;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

скобки: doNothing()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не, здесь все правильно, message это функция, она там дальше по коду используется.


_this.processed++;
changed && _this.tbchanged++;

if (!changed || lint) {
message();
} else {
return vfs.write(path, processedData, 'utf8').then(function() {
_this.changed++;
message();
});
}
});
}
return null;
Expand Down