Files
less.js/Gruntfile.js
Christian Hammond daec7dff1c Support specifying custom variables when calling lessc and less.js.
Both lessc and less.js can now be provided with global variables that
all .less files will have immediate access to. This can be used to
provide, for example, a base path for an @import, signed URLs offering
temporary access to an image on S3, or anything else.

lessc has two new parameters, --global-var and --modify-var. Both take
a value of the form "varname=value". --global-var declares variables
immediately before the content of the .less files, and --modify-var
declares them after.

--global-var is used when rules, imports, or other variables will depend
on the provided variable.

--modify-var is used to override a variable declared within the .less
file.

less.js's equivalent for global variables is less.globalVars. This can
be set before loading less.js. There is no new requivalent to
--modify-var, as less.modifyVars can be used for that purpose.
2013-11-14 02:58:34 -08:00

274 lines
7.9 KiB
JavaScript

'use strict';
module.exports = function(grunt) {
// Report the elapsed execution time of tasks.
require('time-grunt')(grunt);
// Project configuration.
grunt.initConfig({
// Metadata required for build.
build: grunt.file.readYAML('build/build.yml'),
pkg: grunt.file.readJSON('package.json'),
meta: {
license: '<%= _.pluck(pkg.licenses, "type").join(", ") %>',
copyright: 'Copyright (c) 2009-<%= grunt.template.today("yyyy") %>',
banner:
'/*! \n' +
' * LESS - <%= pkg.description %> v<%= pkg.version %> \n' +
' * http://lesscss.org \n' +
' * \n' +
' * <%= meta.copyright %>, <%= pkg.author.name %> <<%= pkg.author.email %>> \n' +
' * Licensed under the <%= meta.license %> License. \n' +
' * \n' +
' * @licence \n' +
' */ \n\n'
},
shell: {
options: {stdout: true, failOnError: true},
test: {
command: 'node test/less-test.js'
},
benchmark: {
command: 'node benchmark/less-benchmark.js'
},
"browsertest-server": {
command: 'node node_modules/http-server/bin/http-server . -p 8088'
},
"sourcemap-test": {
command: [
'node bin/lessc --source-map --source-map-inline test/less/import.less test/sourcemaps/import.css',
'node bin/lessc --source-map --source-map-inline test/less/sourcemaps/basic.less test/sourcemaps/basic.css',
'node node_modules/http-server/bin/http-server test/sourcemaps -p 8084'].join('&&')
}
},
concat: {
options: {
stripBanners: 'all',
banner: '<%= meta.banner %>\n\n(function (window, undefined) {',
footer: '\n})(window);'
},
// Browser versions
browsertest: {
src: ['<%= build.browser %>'],
dest: 'test/browser/less.js'
},
stable: {
src: ['<%= build.browser %>'],
dest: 'dist/less-<%= pkg.version %>.js'
},
// Rhino
rhino: {
options: {
banner: '/* LESS.js v<%= pkg.version %> RHINO | <%= meta.copyright %>, <%= pkg.author.name %> <<%= pkg.author.email %>> */\n\n',
footer: '' // override task-level footer
},
src: ['<%= build.rhino %>'],
dest: 'dist/less-rhino-<%= pkg.version %>.js'
},
// Generate readme
readme: {
// override task-level banner and footer
options: {process: true, banner: '', footer: ''},
src: ['build/README.md'],
dest: 'README.md'
}
},
uglify: {
options: {
banner: '<%= meta.banner %>',
mangle: true
},
stable: {
src: ['<%= concat.stable.src %>'],
dest: 'dist/less-<%= pkg.version %>.min.js'
}
},
jshint: {
options: {jshintrc: '.jshintrc'},
files: {
src: [
'Gruntfile.js',
'lib/**/*.js'
]
}
},
connect: {
server: {
options: {
port: 8081
}
}
},
jasmine: {
options: {
// version: '2.0.0-rc2',
keepRunner: true,
host: 'http://localhost:8081/',
vendor: ['test/browser/common.js', 'test/browser/less.js'],
template: 'test/browser/test-runner-template.tmpl'
},
main: {
// src is used to build list of less files to compile
src: ['test/less/*.less', '!test/less/javascript.less', '!test/less/urls.less'],
options: {
helpers: 'test/browser/runner-main-options.js',
specs: 'test/browser/runner-main-spec.js',
outfile: 'tmp/browser/test-runner-main.html'
}
},
legacy: {
src: ['test/less/legacy/*.less'],
options: {
helpers: 'test/browser/runner-legacy-options.js',
specs: 'test/browser/runner-legacy-spec.js',
outfile: 'tmp/browser/test-runner-legacy.html'
}
},
errors: {
src: ['test/less/errors/*.less', '!test/less/errors/javascript-error.less'],
options: {
timeout: 20000,
helpers: 'test/browser/runner-errors-options.js',
specs: 'test/browser/runner-errors-spec.js',
outfile: 'tmp/browser/test-runner-errors.html'
}
},
noJsErrors: {
src: ['test/less/no-js-errors/*.less'],
options: {
helpers: 'test/browser/runner-no-js-errors-options.js',
specs: 'test/browser/runner-no-js-errors-spec.js',
outfile: 'tmp/browser/test-runner-no-js-errors.html'
}
},
browser: {
src: ['test/browser/less/*.less'],
options: {
helpers: 'test/browser/runner-browser-options.js',
specs: 'test/browser/runner-browser-spec.js',
outfile: 'tmp/browser/test-runner-browser.html'
}
},
relativeUrls: {
src: ['test/browser/less/relative-urls/*.less'],
options: {
helpers: 'test/browser/runner-relative-urls-options.js',
specs: 'test/browser/runner-relative-urls-spec.js',
outfile: 'tmp/browser/test-runner-relative-urls.html'
}
},
rootpath: {
src: ['test/browser/less/rootpath/*.less'],
options: {
helpers: 'test/browser/runner-rootpath-options.js',
specs: 'test/browser/runner-rootpath-spec.js',
outfile: 'tmp/browser/test-runner-rootpath.html'
}
},
rootpathRelative: {
src: ['test/browser/less/rootpath-relative/*.less'],
options: {
helpers: 'test/browser/runner-rootpath-relative-options.js',
specs: 'test/browser/runner-rootpath-relative-spec.js',
outfile: 'tmp/browser/test-runner-rootpath-relative.html'
}
},
production: {
src: ['test/browser/less/production/*.less'],
options: {
helpers: 'test/browser/runner-production-options.js',
specs: 'test/browser/runner-production-spec.js',
outfile: 'tmp/browser/test-runner-production.html'
}
},
modifyVars: {
src: ['test/browser/less/modify-vars/*.less'],
options: {
helpers: 'test/browser/runner-modify-vars-options.js',
specs: 'test/browser/runner-modify-vars-spec.js',
outfile: 'tmp/browser/test-runner-modify-vars.html'
}
},
globalVars: {
src: ['test/browser/less/global-vars/*.less'],
options: {
helpers: 'test/browser/runner-global-vars-options.js',
specs: 'test/browser/runner-global-vars-spec.js',
outfile: 'tmp/browser/test-runner-global-vars.html'
}
}
},
// Clean the version of less built for the tests
clean: {
test: ['test/browser/less.js', 'tmp'],
"sourcemap-test": ['test/sourcemaps/*.css', 'test/sourcemaps/*.map']
}
});
// Load these plugins to provide the necessary tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// Actually load this plugin's task(s).
grunt.loadTasks('build/tasks');
// by default, run tests
grunt.registerTask('default', [
'test'
]);
// Release
grunt.registerTask('stable', [
'concat:stable',
'uglify:stable'
]);
// Run all browser tests
grunt.registerTask('browsertest', [
'browser',
'connect',
'jasmine'
]);
// setup a web server to run the browser tests in a browser rather than phantom
grunt.registerTask('browsertest-server', [
'shell:browsertest-server'
]);
// Create the browser version of less.js
grunt.registerTask('browser', [
'concat:browsertest'
]);
// Run all tests
grunt.registerTask('test', [
'clean',
'jshint',
'shell:test',
'browsertest'
]);
// generate a good test environment for testing sourcemaps
grunt.registerTask('sourcemap-test', [
'clean:sourcemap-test',
'shell:sourcemap-test'
]);
// Run benchmark
grunt.registerTask('benchmark', [
'shell:benchmark'
]);
// Readme.
grunt.registerTask('readme', [
'concat:readme'
]);
};