Add support for reading lessdata from stdin by using - as source target.

This commit is contained in:
Steeve Lennmark
2011-08-05 15:03:06 +02:00
parent 15d6127ccd
commit f62b311aa2

View File

@@ -58,7 +58,7 @@ args = args.filter(function (arg) {
});
var input = args[1];
if (input && input[0] != '/') {
if (input && input[0] != '/' && input != '-') {
input = path.join(process.cwd(), input);
}
var output = args[2];
@@ -73,7 +73,7 @@ if (! input) {
process.exit(1);
}
fs.readFile(input, 'utf-8', function (e, data) {
var parseLessFile = function (e, data) {
if (e) {
sys.puts("lessc: " + e.message);
process.exit(1);
@@ -102,4 +102,20 @@ fs.readFile(input, 'utf-8', function (e, data) {
}
}
});
});
};
if (input != '-') {
fs.readFile(input, 'utf-8', parseLessFile);
} else {
process.stdin.resume();
process.stdin.setEncoding('utf8');
var buffer = '';
process.stdin.on('data', function(data) {
buffer += data;
});
process.stdin.on('end', function() {
parseLessFile(false, buffer);
});
}