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 d50979a..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: @@ -31,7 +31,7 @@ grunt.initConfig({ }, your_target: { // Target-specific file lists and/or options go here. - }, + } } }); ``` @@ -52,13 +52,13 @@ grunt.initConfig({ 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'], - }, + 'dest/resorted-bar.css': ['src/bar.css'] + } } } }); @@ -76,7 +76,7 @@ grunt.initConfig({ config: '/path/to/config.json' }, files: { - 'dest/resorted-foo.css': ['src/foo.css'], + 'dest/resorted-foo.css': ['src/foo.css'] } } } @@ -101,17 +101,36 @@ grunt.initConfig({ }); ``` -## Release History +#### 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. + v2.0.0: Bump up. + v1.2.1: Bump up. -+ v1.2.0: Update csscomb.js to version 2.0 and change `sortOrder` to `config`. ++ v1.2.0: Update csscomb.js to v2.0 and change API `sortOrder` to `config`. + v1.1.0: Improve process. + v1.0.0: Support [csscomb.js](http://github.com/csscomb/csscomb.js). + 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. -+ v0.1.0: Release. \ No newline at end of file ++ v0.1.0: Release. diff --git a/package.json b/package.json index 293e2d7..00db708 100644 --- a/package.json +++ b/package.json @@ -1,64 +1,64 @@ { - "name": "grunt-csscomb", - "description": "The grunt plugin for sorting CSS properties in specific order.", - "version": "2.0.1", - "homepage": "https://github.com/csscomb/grunt-csscomb", - "author": [ - { - "name": "Koji Ishimoto", - "email": "ijok.ijok@gmail.com", - "url": "http://t32k.me/" - }, - { - "name": "Tony Ganch", - "email": "tonyganch+github@gmail.com", - "web": "http://tonyganch.com/" - } - ], - "contributors": [ - { - "name": "Shogo Sensui", - "email": "shogo.sensui@gmail.com", - "web": "http://1000ch.net/" - } - ], - "repository": { - "type": "git", - "url": "https://github.com/csscomb/grunt-csscomb.git" + "name": "grunt-csscomb", + "description": "The grunt plugin for sorting CSS properties in specific order.", + "version": "4.2.0", + "homepage": "https://github.com/csscomb/grunt-csscomb", + "author": [ + { + "name": "Koji Ishimoto", + "email": "ijok.ijok@gmail.com", + "url": "http://t32k.me/" }, - "bugs": { - "url": "https://github.com/csscomb/grunt-csscomb/issues" - }, - "licenses": [ - { - "type": "MIT", - "url": "https://github.com/csscomb/grunt-csscomb/blob/master/LICENSE-MIT" - } - ], - "main": "Gruntfile.js", - "engines": { - "node": ">= 0.10.0" - }, - "scripts": { - "test": "grunt test" - }, - "dependencies": { - "csscomb": "~2.0.0" - }, - "devDependencies": { - "grunt-contrib-jshint": "~0.6.0", - "grunt-contrib-clean": "~0.4.0", - "grunt-contrib-nodeunit": "~0.2.0", - "grunt": "~0.4.2" - }, - "peerDependencies": { - "grunt": "~0.4.2" - }, - "keywords": [ - "gruntplugin", - "CSScomb", - "Sass", - "SCSS", - "LESS" - ] -} \ No newline at end of file + { + "name": "Tony Ganch", + "email": "tonyganch+github@gmail.com", + "web": "http://tonyganch.com/" + } + ], + "contributors": [ + { + "name": "Shogo Sensui", + "email": "shogo.sensui@gmail.com", + "web": "http://1000ch.net/" + } + ], + "repository": { + "type": "git", + "url": "https://github.com/csscomb/grunt-csscomb.git" + }, + "bugs": { + "url": "https://github.com/csscomb/grunt-csscomb/issues" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://github.com/csscomb/grunt-csscomb/blob/master/LICENSE-MIT" + } + ], + "main": "Gruntfile.js", + "engines": { + "node": ">= 10.0.0" + }, + "scripts": { + "test": "grunt test" + }, + "dependencies": { + "csscomb": "~4.3.0" + }, + "devDependencies": { + "grunt": "^1.3.0", + "grunt-contrib-clean": "^2.0.0", + "grunt-contrib-jshint": "^2.1.0", + "grunt-contrib-nodeunit": "^2.1.0" + }, + "peerDependencies": { + "grunt": ">=1.0.0" + }, + "keywords": [ + "gruntplugin", + "CSScomb", + "Sass", + "SCSS", + "LESS" + ] +} diff --git a/tasks/csscomb.js b/tasks/csscomb.js index 32d0064..8f2042a 100644 --- a/tasks/csscomb.js +++ b/tasks/csscomb.js @@ -54,7 +54,7 @@ module.exports = function (grunt) { config = grunt.file.readJSON(config); } else { grunt.log.ok('Using default config file...'); - config = comb.getConfig('csscomb'); + config = Comb.getConfig('csscomb'); } // Configure csscomb: @@ -71,15 +71,24 @@ 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); // Comb it: grunt.log.ok('Sorting file "' + src + '"...'); - var syntax = src.split('.').pop(); - var combed = comb.processString(css, syntax); - grunt.file.write(f.dest, combed); + try { + 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; +}