Skip to content

Commit

Permalink
Merge pull request #158 from Recras/set-exit-code-on-error
Browse files Browse the repository at this point in the history
Set error state if there is any error
  • Loading branch information
jimfleming committed Jul 30, 2015
2 parents 5c51845 + fcdf2bf commit a1a9ff7
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function handleJavascript(fullPath, original) {
js = jsfmt.parseAST(JSON.parse(js));
} catch ( err ) {
console.error(relativePath, err.message);
return;
return false;
}
}

Expand All @@ -123,16 +123,17 @@ function handleJavascript(fullPath, original) {
});
} catch ( err ) {
console.error(relativePath, err.message);
return false;
}
return;
return true;
}

if (argv['--rewrite']) {
try {
js = jsfmt.rewrite(js, argv['--rewrite']).toString();
} catch ( err ) {
console.error(relativePath, err);
return;
return false;
}
}

Expand All @@ -145,7 +146,7 @@ function handleJavascript(fullPath, original) {
}
} catch ( err ) {
console.error(relativePath, err);
return;
return false;
}
}

Expand All @@ -161,7 +162,7 @@ function handleJavascript(fullPath, original) {
var msg = util.format('Error: %s Line: %s Column: %s', error.description, error.lineNumber, error.column);
console.error(msg);
});
process.exit(-1);
return false;
}
}

Expand All @@ -186,6 +187,7 @@ function handleJavascript(fullPath, original) {
// Print to stdout
process.stdout.write(js);
}
return true;
}

function handleDirectory(currentPath, callback) {
Expand Down Expand Up @@ -214,11 +216,15 @@ if (paths.length > 0) {
if (fs.statSync(fullPath).isDirectory()) {
handleDirectory(fullPath, function(paths) {
_.each(paths, function(fullPath) {
handleJavascript(path.normalize(fullPath), fs.readFileSync(fullPath, 'utf-8'));
if (!handleJavascript(path.normalize(fullPath), fs.readFileSync(fullPath, 'utf-8'))) {
process.exitCode = -1;
}
});
});
} else {
handleJavascript(fullPath, fs.readFileSync(fullPath, 'utf-8'));
if (!handleJavascript(fullPath, fs.readFileSync(fullPath, 'utf-8'))) {
process.exitCode = -1;
}
}
});
});
Expand All @@ -233,6 +239,8 @@ if (paths.length > 0) {
}
});
process.stdin.on('end', function() {
handleJavascript('stdin', js);
if (!handleJavascript('stdin', js)) {
process.exitCode = -1;
}
});
}

0 comments on commit a1a9ff7

Please sign in to comment.