Skip to content

Commit

Permalink
Update v0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
t32k committed Aug 10, 2013
1 parent 67123b9 commit 55669a4
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 59 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ A string value that is used to specify custom-sort-order.json file path.

```js
grunt.initConfig({
csscomb: {
foo : {
files: {
'dest/resorted-foo.css': ['src/foo.css'],
},
},
bar : {
files: {
'dest/resorted-foo.css': ['src/foo.css'],
'dest/resorted-bar.css': ['src/bar.css'],
},
},
})
Expand All @@ -76,7 +82,7 @@ grunt.initConfig({

## Release History

+ v0.5.0: Add error handling.
+ v0.5.0: Enable multiple files.
+ v0.4.0: Move to csscomb's repository.
+ v0.3.0: Fix sort option bug.
+ v0.2.0: Fix bugs.
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
"scripts": {
"test": "grunt test"
},
"dependencies": {
"async": "~0.2.9"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-clean": "~0.4.0",
Expand Down
79 changes: 40 additions & 39 deletions tasks/csscomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,62 @@
* Licensed under the MIT license.
*/
'use strict';
module.exports = function(grunt) {
module.exports = function (grunt) {

grunt.registerMultiTask('csscomb', 'Sorting CSS properties in specific order.', function() {
var fs = require('fs'),
grunt.registerMultiTask('csscomb', 'Sorting CSS properties in specific order.', function () {

var async = require('async'),
fs = require('fs'),
path = require('path'),
exec = require('child_process').exec;
var command,
done = this.async(),
realPath = path.dirname(fs.realpathSync(__filename)),
cssComb = 'php ' + realPath + '/lib/csscomb.php',
fileSrc = '',
fileDest = '',
fileSort = '',
options = this.options({
sortOrder: null
});
done = this.async();

if (options.sortOrder !== null) {
if (grunt.file.exists(options.sortOrder)) {
fileSort = ' -s ' + options.sortOrder;
} else {
grunt.log.error('Custom sort .json file not found.');
return false;
}
}
async.eachSeries(this.files, function (file, next) {
var args = [],
child = {
cmd: 'php',
args: args
},
options = grunt.task.current.options({
sortOrder: null
});

function puts(error, stdout, stderr) {
if (error !== null) {
grunt.log.error(error);
args.push(realPath + '/lib/csscomb.php');

} else {
grunt.log.ok(stdout);
if (options.sortOrder !== null) {
if (grunt.file.exists(options.sortOrder)) {
args.push('-s', options.sortOrder);
} else {
grunt.log.error('Custom sort .json file not found.');
return false;
}
}
}

this.files.forEach(function(file) {
fileSrc = file.src.filter(function(filepath) {
var fileSrc = file.src.filter(function (filepath) {
// Remove nonexistent files (it's up to you to filter or warn here).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
return filepath;
}
}).map(function(filepath) {
return filepath;
});
fileSrc = ' -i ' + fileSrc;
args.push('-i', fileSrc);

if (file.dest !== null) {
fileDest = ' -o ' + file.dest;
args.push('-o', file.dest);
}
command = cssComb + fileSort + fileSrc + fileDest;
exec(command, puts);
grunt.verbose.writeln('`' + command + '` was initiated.');
});


grunt.util.spawn(child, function (error, result, code) {
if (error !== null) {
grunt.log.error(error);
} else {
grunt.log.ok(result);
next();
}
});
grunt.verbose.ok('`php ' + child.args.join(' ') + '` was initiated.');
}, done);

});
};
16 changes: 8 additions & 8 deletions test/fixtures/multi1.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.multi1 {
text-align: center;
border-color: 1px #000 solid;
background-color: red;
height: 100px;
z-index: 100;
display: block;
font-weight: bold;
width: 100px;
visibility: hidden;
max-height: 44px;
width: 100px;
height: 100px;
border-color: 1px #000 solid;
background-color: red;
vertical-align: 5px;
visibility: hidden;
z-index: 100;
text-align: center;
font-weight: bold;
}
14 changes: 7 additions & 7 deletions test/fixtures/multi2.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.multi2 {
width: 10px;
border: 1px #fff solid;
position: absolute;
z-index: 10;
margin: 10px;
left: 10px;
height: 10px;
float: left;
top: 10px;
left: 10px;
z-index: 10;
display: table;
float: left;
margin: 10px;
padding: 10px;
width: 10px;
height: 10px;
border: 1px #fff solid;
}
6 changes: 3 additions & 3 deletions test/fixtures/style.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.comb {
text-align: center;
width: 100px;
background-color: red;
height: 100px;
display: block;
background-color: red;
text-align: center;
font-weight: bold;
display: block;
}

0 comments on commit 55669a4

Please sign in to comment.