diff --git a/.travis.yml b/.travis.yml index 1c9c17d..0aa55fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js node_js: - - "0.10" + - "14.13.0" before_script: - npm install grunt-cli \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index fac8a87..4962be4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -24,7 +24,7 @@ module.exports = function (grunt) { // Before generating any new files, remove any previously-created files. clean: { - tests: ['test/fixtures/tmp_*.css','test/fixtures/dest/*.resorted.css'], + tests: ['test/fixtures/tmp_*.css', 'test/fixtures/dest/*.resorted.css', 'test/fixtures/src/*.resorted.css'], }, // Configuration to be run (and then tested). @@ -54,6 +54,10 @@ module.exports = function (grunt) { src: ['*.css', '!*.resorted.css'], dest: 'test/fixtures/dest/', ext: '.resorted.css' + }, + src_only: { + src: ['test/fixtures/src/*.css', '!test/fixtures/src/*.resorted.css'], + ext: '.resorted.css' } }, diff --git a/README.md b/README.md index 2012d08..a9d7db2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ## Getting Started -This plugin requires Grunt `>=0.4.x`. +This plugin requires Grunt `>=1.0.x`. If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: @@ -101,8 +101,26 @@ grunt.initConfig({ }); ``` +#### Src Only + +If you provide only a `src` with no value for `dest`, then `dest` will automatically be set to the `src` directory. + +```js +grunt.initConfig({ + csscomb: { + src_only: { + src: ['foo/bar.css'], + ext: '.resorted.css' + } + } +}); +``` + ## Release History ++ v4.2.0: Update dependencies. ++ v4.1.0: Update csscomb.js to v4.3.0; update dependencies. ++ v4.0.0: Update csscomb.js to v4; update dependencies; allow src only. + v3.1.1: Update grunt version. + v3.0.0: Update csscomb.js to v3.0 but `grunt-csscomb` API doesn't change. + v2.0.1: Stop searching config if we reach root directory. diff --git a/package.json b/package.json index ea861a8..00db708 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt-csscomb", "description": "The grunt plugin for sorting CSS properties in specific order.", - "version": "3.1.1", + "version": "4.2.0", "homepage": "https://github.com/csscomb/grunt-csscomb", "author": [ { @@ -37,22 +37,22 @@ ], "main": "Gruntfile.js", "engines": { - "node": ">= 0.10.0" + "node": ">= 10.0.0" }, "scripts": { "test": "grunt test" }, "dependencies": { - "csscomb": "~3.1.0" + "csscomb": "~4.3.0" }, "devDependencies": { - "grunt": "^0.4.5", - "grunt-contrib-clean": "^0.6.0", - "grunt-contrib-jshint": "^0.11.2", - "grunt-contrib-nodeunit": "^0.4.1" + "grunt": "^1.3.0", + "grunt-contrib-clean": "^2.0.0", + "grunt-contrib-jshint": "^2.1.0", + "grunt-contrib-nodeunit": "^2.1.0" }, "peerDependencies": { - "grunt": ">=0.4.0" + "grunt": ">=1.0.0" }, "keywords": [ "gruntplugin", diff --git a/tasks/csscomb.js b/tasks/csscomb.js index 305f3f3..8f2042a 100644 --- a/tasks/csscomb.js +++ b/tasks/csscomb.js @@ -71,17 +71,21 @@ module.exports = function (grunt) { return true; } }).forEach(function (src) { + var dest = f.dest, + syntax = src.split('.').pop(); + if (!dest) { + dest = grunt.file.expandMapping(src, '', { ext: f.ext || '.' + syntax })[0].dest; + } // Get CSS from a source file: var css = grunt.file.read(src); - var combed; // Comb it: grunt.log.ok('Sorting file "' + src + '"...'); - var syntax = src.split('.').pop(); try { - combed = comb.processString(css, { syntax: syntax }); - grunt.file.write(f.dest, combed); + comb.processString(css, { syntax: syntax }).then(function(combed) { + grunt.file.write(dest, combed); + }); } catch(e) { grunt.log.error(e); } diff --git a/test/csscomb_test.js b/test/csscomb_test.js index 2ee9207..aaa323a 100644 --- a/test/csscomb_test.js +++ b/test/csscomb_test.js @@ -8,7 +8,7 @@ exports.csscomb = { var actual = grunt.file.read('test/fixtures/tmp_resort.css'); var expected = grunt.file.read('test/expected/resort.css'); - test.equal(actual, expected, 'sholud be sorted.'); + test.equal(actual, expected, 'should be sorted.'); test.done(); }, @@ -17,7 +17,7 @@ exports.csscomb = { var actual = grunt.file.read('test/fixtures/tmp_customsort.css'); var expected = grunt.file.read('test/expected/customsort.css'); - test.equal(actual, expected, 'sholud be custom sorted.'); + test.equal(actual, expected, 'should be custom sorted.'); test.done(); }, @@ -26,11 +26,11 @@ exports.csscomb = { var actual = grunt.file.read('test/fixtures/tmp_multi1.css'); var expected = grunt.file.read('test/expected/multi1.css'); - test.equal(actual, expected, 'sholud be sorted.'); + test.equal(actual, expected, 'should be sorted.'); var actual2 = grunt.file.read('test/fixtures/tmp_multi2.css'); var expected2 = grunt.file.read('test/expected/multi2.css'); - test.equal(actual2, expected2, 'sholud be sorted.'); + test.equal(actual2, expected2, 'should be sorted.'); test.done(); }, @@ -39,11 +39,24 @@ exports.csscomb = { var actual = grunt.file.read('test/fixtures/dest/multi1.resorted.css'); var expected = grunt.file.read('test/expected/multi1.css'); - test.equal(actual, expected, 'sholud be sorted.'); + test.equal(actual, expected, 'should be sorted.'); var actual2 = grunt.file.read('test/fixtures/dest/multi2.resorted.css'); var expected2 = grunt.file.read('test/expected/multi2.css'); - test.equal(actual2, expected2, 'sholud be sorted.'); + test.equal(actual2, expected2, 'should be sorted.'); + + test.done(); + }, + src_only: function (test) { + test.expect(2); + + var actual = grunt.file.read('test/fixtures/src/multi1.resorted.css'); + var expected = grunt.file.read('test/expected/multi1.css'); + test.equal(actual, expected, 'should be sorted.'); + + var actual2 = grunt.file.read('test/fixtures/src/multi2.resorted.css'); + var expected2 = grunt.file.read('test/expected/multi2.css'); + test.equal(actual2, expected2, 'should be sorted.'); test.done(); } diff --git a/test/fixtures/src/multi1.css b/test/fixtures/src/multi1.css new file mode 100644 index 0000000..c3944af --- /dev/null +++ b/test/fixtures/src/multi1.css @@ -0,0 +1,13 @@ +.multi1 { + z-index: 100; + display: block; + visibility: hidden; + max-height: 44px; + width: 100px; + height: 100px; + border-color: 1px #000 solid; + background-color: red; + vertical-align: 5px; + text-align: center; + font-weight: bold; +} \ No newline at end of file diff --git a/test/fixtures/src/multi1.resorted.css b/test/fixtures/src/multi1.resorted.css new file mode 100644 index 0000000..481901a --- /dev/null +++ b/test/fixtures/src/multi1.resorted.css @@ -0,0 +1,19 @@ +.multi1 +{ + font-weight: bold; + + z-index: 100; + + display: block; + visibility: hidden; + + width: 100px; + height: 100px; + max-height: 44px; + + text-align: center; + vertical-align: 5px; + + border-color: 1px #000 solid; + background-color: red; +} diff --git a/test/fixtures/src/multi2.css b/test/fixtures/src/multi2.css new file mode 100644 index 0000000..2ec4d0b --- /dev/null +++ b/test/fixtures/src/multi2.css @@ -0,0 +1,13 @@ +.multi2 { + position: absolute; + top: 10px; + left: 10px; + z-index: 10; + display: table; + float: left; + margin: 10px; + padding: 10px; + width: 10px; + height: 10px; + border: 1px #fff solid; +} \ No newline at end of file diff --git a/test/fixtures/src/multi2.resorted.css b/test/fixtures/src/multi2.resorted.css new file mode 100644 index 0000000..7af8039 --- /dev/null +++ b/test/fixtures/src/multi2.resorted.css @@ -0,0 +1,17 @@ +.multi2 +{ + position: absolute; + z-index: 10; + top: 10px; + left: 10px; + + display: table; + float: left; + + width: 10px; + height: 10px; + margin: 10px; + padding: 10px; + + border: 1px #fff solid; +}