From aaedf965646fdc002d16efed36388e014abfd90a Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Wed, 2 Mar 2011 05:15:51 +0800 Subject: [PATCH] Add an --include-path option to lessc. 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. --- bin/lessc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bin/lessc b/bin/lessc index 9d799f91..2c8974ef 100755 --- a/bin/lessc +++ b/bin/lessc @@ -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) { @@ -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; @@ -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) {