From 8dca64b5261be5719c8a88d10add77250b6ce67f Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 6 Jan 2013 14:13:17 +0100 Subject: [PATCH] Followup to making task grunt 0.4 compatible Also improve code style --- Gruntfile.js | 41 +++++++++++------------------------------ package.json | 6 +++--- readme.md | 3 +++ tasks/recess.js | 45 ++++++++++++++++++++++----------------------- 4 files changed, 39 insertions(+), 56 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index cc4d611..c8d9270 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,6 +1,5 @@ -module.exports = function( grunt ) { - 'use strict'; - +'use strict'; +module.exports = function (grunt) { grunt.initConfig({ recess: { pass: { @@ -15,38 +14,20 @@ module.exports = function( grunt ) { ] } }, - watch: { - files: '', - tasks: 'default' - }, jshint: { - lint: [ - 'grunt.js', - 'tests/**/*.js' - ], options: { - es5: true, - esnext: true, - bitwise: true, - curly: true, - eqeqeq: true, - latedef: true, - newcap: true, - noarg: true, - noempty: true, - regexp: true, - undef: true, - strict: true, - trailing: true, - smarttabs: true, - node: true - } + jshintrc: '.jshintrc' + }, + all: [ + 'Gruntfile.js', + 'tasks/*.js', + 'tests/*.js' + ] } }); grunt.loadTasks('tasks'); - grunt.loadNpmTasks('grunt-contrib-jshint'); - - grunt.registerTask( 'default', ['jshint', 'recess:pass', 'recess:fail'] ); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.registerTask('default', ['jshint', 'recess:pass', 'recess:fail']); }; diff --git a/package.json b/package.json index 20e1b43..9ec149e 100644 --- a/package.json +++ b/package.json @@ -18,18 +18,18 @@ "email": "sindresorhus@gmail.com", "url": "http://sindresorhus.com" }, - "main": "grunt.js", + "main": "Gruntfile.js", "repository": { "type": "git", "url": "git://github.com/sindresorhus/grunt-recess.git" }, "dependencies": { "recess": "~1.1.6", - "grunt-lib-legacyhelpers": "~0.1.x" + "grunt-lib-legacyhelpers": "~0.1.0" }, "devDependencies": { "grunt": "~0.4.0", - "grunt-contrib-jshint": "~0.1.x" + "grunt-contrib-jshint": "~0.1.0" }, "engines": { "node": ">=0.8.0" diff --git a/readme.md b/readme.md index ec9beb3..34a1a07 100644 --- a/readme.md +++ b/readme.md @@ -9,6 +9,8 @@ ## Getting Started +**Requires grunt 0.4** + Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-recess` Then add this line to your project's `grunt.js` gruntfile: @@ -89,6 +91,7 @@ noUniversalSelectors: true // Doesn't complain about using the universal * selec prefixWhitespace: true // Adds whitespace prefix to line up vender prefixed properties strictPropertyOrder: true // Complains if not strict property order stripColors: false // Strip colors from the Terminal output +// ^ Deprecated. Instead pass `--no-color` to grunt zeroUnits: true // Doesn't complain if you add units to values of 0 ``` diff --git a/tasks/recess.js b/tasks/recess.js index 9d75017..39e71ef 100644 --- a/tasks/recess.js +++ b/tasks/recess.js @@ -1,24 +1,22 @@ - -module.exports = function( grunt ) { - 'use strict'; - - grunt.registerMultiTask('recess', 'Lint and minify CSS and LESS', function() { +'use strict'; +module.exports = function (grunt) { + grunt.registerMultiTask('recess', 'Lint and minify CSS and LESS', function () { var recess = require('recess'); - var helpers = require('grunt-lib-legacyhelpers').init(grunt); + var helpers = require('grunt-lib-legacyhelpers').init(grunt); var lf = grunt.util.linefeed; var cb = this.async(); - var files = grunt.file.expandFiles( this.file.src ); + var files = this.file.src; var dest = this.file.dest; var options = this.data.options || {}; var compress = options.compress; var separator = compress ? '' : lf + lf; - if ( !files.length ) { + if (!files.length) { grunt.log.writeln('No existing files in this target.'); return cb(); } - recess( files, options, function( err, data ) { + recess(files, options, function (err, data) { var min = []; var max = []; @@ -28,28 +26,29 @@ module.exports = function( grunt ) { // // .reverse() the array because of bug: // https://github.com/twitter/recess/issues/42 - data = Array.isArray( data ) ? data.reverse() : [ data ]; + data = Array.isArray(data) ? data.reverse() : [data]; - data.forEach(function( item ) { - if ( item.options.compile ) { - min.push( item.output ); - max.push( item.data ); + data.forEach(function (item) { + if (item.options.compile) { + min.push(item.output); + max.push(item.data); // Extract status and check - } else if ( item.output[1] && item.output[1].indexOf('Perfect!') !== -1 ) { - grunt.log.writeln( item.output.join( lf ) ); + } else if (item.output[1] && item.output[1].indexOf('Perfect!') !== -1) { + grunt.log.writeln(item.output.join(lf)); } else { - grunt.fail.warn( item.output.join( lf ) ); + grunt.fail.warn(item.output.join(lf)); } }); - if ( min.length ) { - if ( dest ) { + if (min.length) { + if (dest) { // Concat files - grunt.file.write( dest, min.join( separator ) ); - grunt.log.writeln( 'File "' + dest + '" created.' ); + grunt.file.write(dest, min.join(separator)); + grunt.log.writeln('File "' + dest + '" created.'); - if ( compress ) { - helpers.min_max_info(min.join( separator ), max.join( separator ) ); + if (compress) { + /*jshint camelcase:false */ + helpers.min_max_info(min.join(separator), max.join(separator)); } } else { grunt.fail.fatal('No destination specified. Required when options.compile is enabled.');