#!/usr/bin/env node var path = require('path'), fs = require('fs'), sys = require('sys'); require.paths.unshift(__dirname, path.join(__dirname, '..')); var less = require('lib/less'); var args = process.argv.slice(1); args = args.filter(function (arg) { var match; if (match = arg.match(/^--?([a-z][a-z-]*)$/i)) { arg = match[1] } else { return arg } switch (arg) { case 'v': sys.puts("lessc " + less.version.join('.') + " (LESS Compiler)"); process.exit(0); case 'h': sys.puts("usage: lessc source [destination]"); process.exit(0); } }); var input = args[1] && path.join(process.cwd(), args[1]), output = args[2] && path.join(process.cwd(), args[2]); var css, fd, tree; if (! input) { process.stdio.writeError("lessc: no input files\n"); process.exit(1); } fs.stat(input, function (e, stats) { if (e) { process.stdio.writeError("lessc: " + e.message + ": '" + input + "'\n"); process.exit(1); } fs.open(input, process.O_RDONLY, stats.mode, function (e, fd) { fs.read(fd, stats.size, 0, "utf8", function (e, data) { less.parser.parse(data, function (err, tree) { if (err) { process.stdio.writeError(err); } else { css = tree.toCSS([], {frames: []}); if (output) { fd = fs.openSync(output, "w"); fs.writeSync(fd, css, 0, "utf8"); } else { sys.print(css); } } }); }); }); });