3 var path = require('path'),
8 // For old node.js versions
9 require.paths.unshift( path.join( __dirname, '..', 'lib' ) );
13 var less = require('less');
14 var args = process.argv.slice(1);
23 args = args.filter(function (arg) {
26 if (match = arg.match(/^-I(.+)$/)) {
27 options.paths.push(match[1]);
31 if (match = arg.match(/^--?([a-z][0-9a-z-]*)(?:=([^\s]+))?$/i)) { arg = match[1] }
37 sys.puts("lessc " + less.version.join('.') + " (LESS Compiler) [JavaScript]");
40 options.verbose = true;
44 options.silent = true;
48 sys.puts("usage: lessc source [destination]");
52 options.compress = true;
55 options.color = false;
58 options.paths = match[2].split(':')
60 if (p && p[0] == '/') {
61 return path.join(path.dirname(input), p);
63 return path.join(process.cwd(), p);
67 case 'O0': options.optimization = 0; break;
68 case 'O1': options.optimization = 1; break;
69 case 'O2': options.optimization = 2; break;
74 if (input && input[0] != '/' && input != '-') {
75 input = path.join(process.cwd(), input);
78 if (output && output[0] != '/') {
79 output = path.join(process.cwd(), output);
85 sys.puts("lessc: no input files");
89 var parseLessFile = function (e, data) {
91 sys.puts("lessc: " + e.message);
96 paths: [path.dirname(input)].concat(options.paths),
97 optimization: options.optimization,
99 }).parse(data, function (err, tree) {
101 less.writeError(err, options);
105 css = tree.toCSS({ compress: options.compress });
107 fd = fs.openSync(output, "w");
108 fs.writeSync(fd, css, 0, "utf8");
113 less.writeError(e, options);
121 fs.readFile(input, 'utf-8', parseLessFile);
123 process.stdin.resume();
124 process.stdin.setEncoding('utf8');
127 process.stdin.on('data', function(data) {
131 process.stdin.on('end', function() {
132 parseLessFile(false, buffer);