Skip to content

Commit 301b448

Browse files
author
Alexis Sellier
committed
Merge pull request #340 from steevel/master
Read less-content from stdin
2 parents ccfe84f + f62b311 commit 301b448

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

bin/lessc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ args = args.filter(function (arg) {
6767
});
6868

6969
var input = args[1];
70-
if (input && input[0] != '/') {
70+
if (input && input[0] != '/' && input != '-') {
7171
input = path.join(process.cwd(), input);
7272
}
7373
var output = args[2];
@@ -82,7 +82,7 @@ if (! input) {
8282
process.exit(1);
8383
}
8484

85-
fs.readFile(input, 'utf-8', function (e, data) {
85+
var parseLessFile = function (e, data) {
8686
if (e) {
8787
sys.puts("lessc: " + e.message);
8888
process.exit(1);
@@ -111,4 +111,20 @@ fs.readFile(input, 'utf-8', function (e, data) {
111111
}
112112
}
113113
});
114-
});
114+
};
115+
116+
if (input != '-') {
117+
fs.readFile(input, 'utf-8', parseLessFile);
118+
} else {
119+
process.stdin.resume();
120+
process.stdin.setEncoding('utf8');
121+
122+
var buffer = '';
123+
process.stdin.on('data', function(data) {
124+
buffer += data;
125+
});
126+
127+
process.stdin.on('end', function() {
128+
parseLessFile(false, buffer);
129+
});
130+
}

0 commit comments

Comments
 (0)