grunt-contrib-less
Advanced tools
Comparing version 0.2.2 to 0.3.0
30
grunt.js
@@ -48,13 +48,7 @@ /* | ||
files: { | ||
'tmp/less_a.css': ['test/fixtures/style.less'], | ||
'tmp/less_b.css': ['test/fixtures/style.less'], | ||
'tmp/less_c.css': ['test/fixtures/**/*.nomatches'], | ||
'tmp/less_d.css': ['test/fixtures/style.less', 'test/fixtures/style2.less'] | ||
'tmp/less.css': ['test/fixtures/style.less'], | ||
'tmp/concat.css': ['test/fixtures/style.less', 'test/fixtures/style2.less'], | ||
'tmp/individual/*.css': ['test/fixtures/style*.less', 'test/fixtures/level2/*.less'] | ||
} | ||
}, | ||
no_paths_specified: { | ||
files: { | ||
'tmp/less_no_paths_specified.css': ['test/fixtures/style_no_paths_specified.less'], | ||
} | ||
}, | ||
compress: { | ||
@@ -66,5 +60,19 @@ options: { | ||
files: { | ||
'tmp/less_a.min.css': ['test/fixtures/style.less'] | ||
'tmp/compress.css': ['test/fixtures/style.less'] | ||
} | ||
}, | ||
flatten: { | ||
files: { | ||
'tmp/individual_flatten/*.css': ['test/fixtures/style*.less', 'test/fixtures/level2/*.less'] | ||
}, | ||
options: { | ||
flatten: true, | ||
paths: ['test/fixtures/include'] | ||
}, | ||
}, | ||
nopaths: { | ||
files: { | ||
'tmp/nopaths.css': ['test/fixtures/nopaths.less'], | ||
} | ||
}, | ||
yuicompress: { | ||
@@ -76,3 +84,3 @@ options: { | ||
files: { | ||
'tmp/less_a.yuimin.css': ['test/fixtures/style.less'] | ||
'tmp/yuicompress.css': ['test/fixtures/style.less'] | ||
} | ||
@@ -79,0 +87,0 @@ } |
{ | ||
"name": "grunt-contrib-less", | ||
"description": "Compile LESS files to CSS.", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/gruntjs/grunt-contrib-less", | ||
@@ -32,7 +32,7 @@ "author": { | ||
"less": "~1.3.0", | ||
"grunt-contrib-lib": "~0.2.0" | ||
"grunt-contrib-lib": "~0.3.0" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.3.15", | ||
"grunt-contrib-clean": "~0.2.0" | ||
"grunt-contrib-clean": "~0.3.0" | ||
}, | ||
@@ -42,2 +42,2 @@ "keywords": [ | ||
] | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# grunt-contrib-less | ||
# grunt-contrib-less [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-less.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-less) | ||
> Compile LESS files to CSS (part of the [grunt-contrib](https://github.com/gruntjs/grunt-contrib) collection). Submitted by [Tyler Kellen](https://github.com/tkellen). | ||
@@ -28,3 +28,3 @@ | ||
Note: When the value contains an array of multiple filepaths, the contents are concatenated in the order passed. | ||
As of v0.3.0, you can use *.{ext} as your destination filename to individually compile each file to the destination directory. Otherwise, when the source contains an array of multiple filepaths, the contents are concatenated in the order passed. | ||
@@ -75,3 +75,4 @@ ##### options ```object``` | ||
* 2012/08/16 - v0.2.2 - Support all less options, normalize linefeeds, default path to dirname of src file. | ||
* 2012/08/10 - v0.2.0 - Refactored from grunt-contrib into individual repo. | ||
* 2012/09/24 - v0.3.0 - general cleanup and consolidation. test refactoring. global options depreciated. revert normalize linefeeds for now. | ||
* 2012/09/16 - v0.2.2 - support all less options, normalize linefeeds, default path to dirname of src file. | ||
* 2012/09/10 - v0.2.0 - refactored from grunt-contrib into individual repo. |
@@ -16,8 +16,6 @@ /* | ||
var _ = grunt.util._; | ||
var less = require('less'); | ||
var path = require('path'); | ||
var async = grunt.util.async; | ||
var helpers = require('grunt-contrib-lib').init(grunt); | ||
var less = require('less'); | ||
var lessOptions = { | ||
@@ -29,3 +27,9 @@ parse: ['paths', 'optimization', 'filename', 'strictImports'], | ||
grunt.registerMultiTask('less', 'Compile LESS files to CSS', function() { | ||
var options = helpers.options(this); | ||
var helpers = require('grunt-contrib-lib').init(grunt); | ||
var options = helpers.options(this, { | ||
basePath: false, | ||
flatten: false | ||
}); | ||
grunt.verbose.writeflags(options, 'Options'); | ||
@@ -38,29 +42,50 @@ | ||
var basePath; | ||
var newFileDest; | ||
var srcFiles; | ||
var sourceCode; | ||
var helperOptions; | ||
async.forEachSeries(this.files, function(file, next) { | ||
srcFiles = grunt.file.expandFiles(file.src); | ||
grunt.util.async.forEachSeries(this.files, function(file, next) { | ||
file.dest = path.normalize(file.dest); | ||
srcFiles = grunt.file.expandFiles(file.src); | ||
async.concatSeries(srcFiles, function(srcFile, nextConcat) { | ||
helperOptions = _.extend({filename: srcFile}, options); | ||
helperOptions.paths = helperOptions.paths || [path.dirname(srcFile)]; | ||
if (srcFiles.length === 0) { | ||
grunt.fail.warn('Unable to compile; no valid source files were found.'); | ||
} | ||
sourceCode = grunt.file.read(srcFile); | ||
if (helpers.isIndividualDest(file.dest)) { | ||
basePath = helpers.findBasePath(srcFiles, options.basePath); | ||
compileLess(sourceCode, helperOptions, function(css, err) { | ||
if(!err) { | ||
nextConcat(null, css); | ||
} else { | ||
done(); | ||
} | ||
grunt.util.async.forEachSeries(srcFiles, function(srcFile, nextFile) { | ||
newFileDest = helpers.buildIndividualDest(file.dest, srcFile, basePath, options.flatten); | ||
compileLess(srcFile, options, function(css, err) { | ||
if(!err) { | ||
grunt.file.write(newFileDest, css || ''); | ||
grunt.log.writeln('File ' + newFileDest.cyan + ' created.'); | ||
nextFile(null); | ||
} else { | ||
done(); | ||
} | ||
}); | ||
}, function(err) { | ||
next(); | ||
}); | ||
}, function(err, css) { | ||
grunt.file.write(file.dest, css.join(grunt.util.linefeed) || ''); | ||
grunt.log.writeln('File ' + file.dest + ' created.'); | ||
} else { | ||
grunt.util.async.concatSeries(srcFiles, function(srcFile, nextConcat) { | ||
compileLess(srcFile, options, function(css, err) { | ||
if(!err) { | ||
nextConcat(null, css); | ||
} else { | ||
done(); | ||
} | ||
}); | ||
}, function(err, css) { | ||
grunt.file.write(file.dest, css.join('\n') || ''); | ||
grunt.log.writeln('File ' + file.dest.cyan + ' created.'); | ||
next(); | ||
}); | ||
next(); | ||
}); | ||
} | ||
}, function() { | ||
@@ -80,3 +105,3 @@ done(); | ||
grunt.log.error(message); | ||
grunt.fail.warn('Error compiling LESS.', 1); | ||
grunt.fail.warn('Error compiling LESS.'); | ||
}; | ||
@@ -94,8 +119,14 @@ | ||
var compileLess = function(source, options, callback) { | ||
var compileLess = function(srcFile, options, callback) { | ||
options = grunt.util._.extend({filename: srcFile}, options); | ||
options.paths = options.paths || [path.dirname(srcFile)]; | ||
var css; | ||
var srcCode = grunt.file.read(srcFile); | ||
var parser = new less.Parser(pick(options, lessOptions.parse)); | ||
parser.parse(source, function(parse_error, tree) { | ||
if (parse_error) { | ||
lessError(parse_error); | ||
parser.parse(srcCode, function(parse_err, tree) { | ||
if (parse_err) { | ||
lessError(parse_err); | ||
} | ||
@@ -102,0 +133,0 @@ |
var grunt = require('grunt'); | ||
var fs = require('fs'); | ||
exports['less'] = { | ||
main: function(test) { | ||
exports.less = { | ||
compile: function(test) { | ||
'use strict'; | ||
var expect, result; | ||
test.expect(3); | ||
test.expect(7); | ||
var actual = grunt.file.read('tmp/less.css'); | ||
var expected = grunt.file.read('test/expected/less.css'); | ||
test.equal(expected, actual, 'should compile less, with the ability to handle imported files from alternate include paths'); | ||
expect = 'body {\n color: #ffffff;\n}\n'; | ||
result = grunt.file.read('tmp/less_a.css'); | ||
test.equal(expect, result, 'should compile less, with the ability to handle imported files from alternate include paths'); | ||
actual = grunt.file.read('tmp/concat.css'); | ||
expected = grunt.file.read('test/expected/concat.css'); | ||
test.equal(expected, actual, 'should concat output when passed an array'); | ||
expect = 'body {\n color: #ffffff;\n}\n'; | ||
result = grunt.file.read('tmp/less_b.css'); | ||
test.equal(expect, result, 'should support multiple destination:source sets'); | ||
actual = fs.readdirSync('tmp/individual').sort(); | ||
expected = fs.readdirSync('test/expected/individual').sort(); | ||
test.deepEqual(expected, actual, 'should individually compile files'); | ||
expect = ''; | ||
result = grunt.file.read('tmp/less_c.css'); | ||
test.equal(expect, result, 'should write an empty file when no less sources are found'); | ||
test.done(); | ||
}, | ||
compress: function(test) { | ||
'use strict'; | ||
expect = 'body {\n color: #ffffff;\n}\n\n#header {\n background: #ffffff;\n}\n'; | ||
result = grunt.file.read('tmp/less_d.css'); | ||
test.equal(expect, result, 'should concat output when passed an array'); | ||
test.expect(1); | ||
expect = 'body {\n color: #ffffff;\n}\n'; | ||
result = grunt.file.read('tmp/less_no_paths_specified.css'); | ||
test.equal(expect, result, 'should default paths to the dirname of the less file'); | ||
var actual = grunt.file.read('tmp/compress.css'); | ||
var expected = grunt.file.read('test/expected/compress.css'); | ||
test.equal(expected, actual, 'should compress output when compress option is true'); | ||
expect = 'body{color:#ffffff;}\n'; | ||
result = grunt.file.read('tmp/less_a.min.css'); | ||
test.equal(expect, result, 'should compress output when compress option is true'); | ||
test.done(); | ||
}, | ||
flatten: function(test) { | ||
'use strict'; | ||
expect = 'body{color:#fff}'; | ||
result = grunt.file.read('tmp/less_a.yuimin.css'); | ||
test.equal(expect, result, 'should yuicompress output when yuicompress option is true'); | ||
test.expect(1); | ||
var actual = fs.readdirSync('tmp/individual_flatten').sort(); | ||
var expected = fs.readdirSync('test/expected/individual_flatten').sort(); | ||
test.deepEqual(expected, actual, 'should individually compile files (to flat structure)'); | ||
test.done(); | ||
}, | ||
nopaths: function(test) { | ||
'use strict'; | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/nopaths.css'); | ||
var expected = grunt.file.read('test/expected/nopaths.css'); | ||
test.equal(expected, actual, 'should default paths to the dirname of the less file'); | ||
test.done(); | ||
}, | ||
yuicompress: function(test) { | ||
'use strict'; | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/yuicompress.css'); | ||
var expected = grunt.file.read('test/expected/yuicompress.css'); | ||
test.equal(expected, actual, 'should yuicompress output when yuicompress option is true'); | ||
test.done(); | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14162
26
286
1
+ Addedgrunt-contrib-lib@0.3.0(transitive)
- Removedgrunt-contrib-lib@0.2.1(transitive)
Updatedgrunt-contrib-lib@~0.3.0