remove process.exit calls as they do not guarentee a flushed stdout

This commit is contained in:
Luke Page
2012-08-15 21:14:06 +01:00
parent fb21a897f6
commit 2d8ede3436

View File

@@ -16,6 +16,12 @@ var options = {
color: true,
strictImports: false
};
var continueProcessing = true,
currentErrorcode;
// calling process.exit does not flush stdout always
// so use this to set the exit code
process.on('exit', function() { process.reallyExit(currentErrorcode) });
args = args.filter(function (arg) {
var match;
@@ -32,7 +38,7 @@ args = args.filter(function (arg) {
case 'v':
case 'version':
sys.puts("lessc " + less.version.join('.') + " (LESS Compiler) [JavaScript]");
process.exit(0);
continueProcessing = false;
case 'verbose':
options.verbose = true;
break;
@@ -46,7 +52,7 @@ args = args.filter(function (arg) {
case 'h':
case 'help':
require('../lib/less/lessc_helper').printUsage();
process.exit(0);
continueProcessing = false;
case 'x':
case 'compress':
options.compress = true;
@@ -61,7 +67,7 @@ args = args.filter(function (arg) {
options.paths = match[2].split(os.type().match(/Windows/) ? ';' : ':')
.map(function(p) {
if (p) {
return path.resolve(process.cwd(), p);
return path.resolve(process.cwd(), p);
}
});
break;
@@ -71,6 +77,10 @@ args = args.filter(function (arg) {
}
});
if (!continueProcessing) {
return;
}
var input = args[1];
if (input && input != '-') {
input = path.resolve(process.cwd(), input);
@@ -80,17 +90,21 @@ if (output) {
output = path.resolve(process.cwd(), output);
}
var css, fd, tree;
if (! input) {
sys.puts("lessc: no input files");
process.exit(1);
sys.puts("");
require('../lib/less/lessc_helper').printUsage();
currentErrorcode = 1;
return;
}
var css, fd, tree;
var parseLessFile = function (e, data) {
if (e) {
sys.puts("lessc: " + e.message);
process.exit(1);
currentErrorcode = 1;
return;
}
new(less.Parser)({
@@ -101,7 +115,8 @@ var parseLessFile = function (e, data) {
}).parse(data, function (err, tree) {
if (err) {
less.writeError(err, options);
process.exit(1);
currentErrorcode = 1;
return;
} else {
try {
css = tree.toCSS({
@@ -117,7 +132,8 @@ var parseLessFile = function (e, data) {
}
} catch (e) {
less.writeError(e, options);
process.exit(2);
currentErrorcode = 2;
return;
}
}
});