Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Followup to making task grunt 0.4 compatible
Browse files Browse the repository at this point in the history
Also improve code style
  • Loading branch information
sindresorhus committed Jan 6, 2013
1 parent 5151fe2 commit 8dca64b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 56 deletions.
41 changes: 11 additions & 30 deletions Gruntfile.js
@@ -1,6 +1,5 @@
module.exports = function( grunt ) {
'use strict';

'use strict';
module.exports = function (grunt) {
grunt.initConfig({
recess: {
pass: {
Expand All @@ -15,38 +14,20 @@ module.exports = function( grunt ) {
]
}
},
watch: {
files: '<config:lint.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']);
};
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Expand Up @@ -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:
Expand Down Expand Up @@ -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
```

Expand Down
45 changes: 22 additions & 23 deletions 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 = [];

Expand All @@ -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.');
Expand Down

0 comments on commit 8dca64b

Please sign in to comment.