(bin) add compress and optimization options
This commit is contained in:
parent
d369a658ff
commit
a7678bbd4f
14
bin/lessc
14
bin/lessc
@ -8,6 +8,10 @@ require.paths.unshift(path.join(__dirname, '..', 'lib'));
|
|||||||
|
|
||||||
var less = require('less');
|
var less = require('less');
|
||||||
var args = process.argv.slice(1);
|
var args = process.argv.slice(1);
|
||||||
|
var options = {
|
||||||
|
compress: false,
|
||||||
|
optimization: 1
|
||||||
|
};
|
||||||
|
|
||||||
args = args.filter(function (arg) {
|
args = args.filter(function (arg) {
|
||||||
var match;
|
var match;
|
||||||
@ -24,6 +28,13 @@ args = args.filter(function (arg) {
|
|||||||
case 'help':
|
case 'help':
|
||||||
sys.puts("usage: lessc source [destination]");
|
sys.puts("usage: lessc source [destination]");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
|
case 'x':
|
||||||
|
case 'compress':
|
||||||
|
options.compress = true;
|
||||||
|
break;
|
||||||
|
case 'O0': options.optimization = 0; break;
|
||||||
|
case 'O1': options.optimization = 1; break;
|
||||||
|
case 'O2': options.optimization = 2; break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -52,12 +63,13 @@ fs.stat(input, function (e, stats) {
|
|||||||
fs.read(fd, stats.size, 0, "utf8", function (e, data) {
|
fs.read(fd, stats.size, 0, "utf8", function (e, data) {
|
||||||
new(less.Parser)({
|
new(less.Parser)({
|
||||||
paths: [path.dirname(input)],
|
paths: [path.dirname(input)],
|
||||||
|
optimization: options.optimization,
|
||||||
filename: input
|
filename: input
|
||||||
}).parse(data, function (err, tree) {
|
}).parse(data, function (err, tree) {
|
||||||
if (err) {
|
if (err) {
|
||||||
less.writeError(err);
|
less.writeError(err);
|
||||||
} else {
|
} else {
|
||||||
css = tree.toCSS();
|
css = tree.toCSS({ compress: options.compress });
|
||||||
if (output) {
|
if (output) {
|
||||||
fd = fs.openSync(output, "w");
|
fd = fs.openSync(output, "w");
|
||||||
fs.writeSync(fd, css, 0, "utf8");
|
fs.writeSync(fd, css, 0, "utf8");
|
||||||
|
Loading…
Reference in New Issue
Block a user