Skip to content

Commit

Permalink
Add an --include-path option to lessc.
Browse files Browse the repository at this point in the history
This adds an optional `--include-path=foo` argument to the command line lessc script. Paths are evaluated relative to the current working directory, so paths like `../foo`, `./bar` and `baz` all work just like you'd expect.

Multiple paths can be supplied by separating them with colons, e.g. `--include-path=foo:../bar:/baz`

The basedir of the input file is always in the include path because that just makes sense.
  • Loading branch information
bobthecow authored and Alexis Sellier committed May 3, 2011
1 parent 2de86bd commit aaedf96
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions bin/lessc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ var args = process.argv.slice(1);
var options = {
compress: false,
optimization: 1,
silent: false
silent: false,
paths: []
};

args = args.filter(function (arg) {
var match;

if (match = arg.match(/^--?([a-z][0-9a-z-]*)$/i)) { arg = match[1] }
if (match = arg.match(/^--?([a-z][0-9a-z-]*)(?:=([^\s]+))?$/i)) { arg = match[1] }
else { return arg }

switch (arg) {
Expand All @@ -40,6 +41,16 @@ args = args.filter(function (arg) {
case 'compress':
options.compress = true;
break;
case 'include-path':
options.paths = match[2].split(':')
.map(function(p) {
if (p && p[0] == '/') {
return path.join(path.dirname(input), p);
} else if (p) {
return path.join(process.cwd(), p);
}
});
break;
case 'O0': options.optimization = 0; break;
case 'O1': options.optimization = 1; break;
case 'O2': options.optimization = 2; break;
Expand Down Expand Up @@ -69,7 +80,7 @@ fs.readFile(input, 'utf-8', function (e, data) {
}

new(less.Parser)({
paths: [path.dirname(input)],
paths: [path.dirname(input)].concat(options.paths),
optimization: options.optimization,
filename: input
}).parse(data, function (err, tree) {
Expand Down

0 comments on commit aaedf96

Please sign in to comment.