Skip to content

Commit 29b4df9

Browse files
committed
Merge pull request #12 from csscomb/tg/csscomb.js-2.0
Update csscomb.js to version 2.0
2 parents dc9f7a8 + fa499c6 commit 29b4df9

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function(grunt) {
2222
jshintrc: '.jshintrc',
2323
},
2424
},
25-
25+
2626
// Before generating any new files, remove any previously-created files.
2727
clean: {
2828
tests: ['test/fixtures/tmp_*.css'],
@@ -37,7 +37,7 @@ module.exports = function(grunt) {
3737
},
3838
custom: {
3939
options: {
40-
sortOrder: 'test/fixtures/sort.json'
40+
config: 'test/fixtures/sort.json'
4141
},
4242
files: {
4343
'test/fixtures/tmp_customsort.css': ['test/fixtures/style.css'],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test": "grunt test"
3030
},
3131
"dependencies": {
32-
"csscomb": "1.0.0"
32+
"csscomb": "2.0.x"
3333
},
3434
"devDependencies": {
3535
"grunt-contrib-jshint": "~0.6.0",

tasks/csscomb.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,49 @@
66
* Licensed under the MIT license.
77
*/
88
'use strict';
9+
10+
var path = require('path');
11+
912
module.exports = function (grunt) {
1013

1114
grunt.registerMultiTask('csscomb', 'Sorting CSS properties in specific order.', function () {
1215

1316
var Comb = require('csscomb'),
14-
defaultConfig = require('../node_modules/csscomb/.csscomb.json');
17+
comb = new Comb();
18+
19+
function getConfigPath(configPath) {
20+
var HOME = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
21+
22+
configPath = configPath || process.cwd() + '/.csscomb.json';
23+
24+
// If we've finally found a config, return its path:
25+
if (grunt.file.exists(configPath)) return configPath;
26+
27+
// If we are in HOME dir already and yet no config file, quit:
28+
if (path.dirname(configPath) === HOME) return;
29+
30+
// If there is no config in this directory, go one level up and look for
31+
// a config there:
32+
configPath = path.dirname(path.dirname(configPath)) + '/.csscomb.json';
33+
return getConfigPath(configPath);
34+
}
1535

1636
// Get config file from task's options:
17-
var config = grunt.task.current.options().sortOrder;
37+
var config = grunt.task.current.options().config || getConfigPath();
1838

1939
// Check if config file is set and exists. If not, use default one:
2040
if (config && grunt.file.exists(config)) {
2141
grunt.log.ok('Using custom config file "' + config + '"...');
2242
config = grunt.file.readJSON(config);
2343
} else {
24-
config = defaultConfig;
44+
grunt.log.ok('Using default config file...');
45+
config = comb.getConfig('csscomb');
2546
}
2647

27-
this.files.forEach(function (f) {
48+
// Configure csscomb:
49+
comb.configure(config);
2850

29-
// Create a new instance of csscomb and configure it:
30-
var comb = new Comb();
31-
comb.configure(config);
51+
this.files.forEach(function (f) {
3252

3353
f.src.filter(function (filepath) {
3454
// Warn on and remove invalid source files (if nonull was set).
@@ -50,4 +70,4 @@ module.exports = function (grunt) {
5070
});
5171
});
5272
});
53-
};
73+
};

0 commit comments

Comments
 (0)