shelljs-transpiler
shelljs-transpiler copied to clipboard
JS `error()` gives string whereas SH `$?` gives int
Input (bash) code
some command
RESULT=$?
if [ $RESULT != 0 ]; then
echo "Aborting on $RESULT, command failed:"
exit $RESULT
fi
Expected output ShellJS (JavaScript) code
exec('some command');
env.RESULT = (error()=='null' ? 0 : 1);
if (env.RESULT !== 0) {
echo('Aborting on ' + env.RESULT + ', command failed:');
exit(env.RESULT);
}
Actual output ShellJS (JavaScript) code
exec('some command');
env.RESULT = error();
if (env.RESULT !== 0) {
echo('Aborting on ' + env.RESULT + ', command failed:');
exit(env.RESULT);
}
This will be supported in shell.errorCode(). That will be in the next shelljs release when I get around to it.
I'll keep this open in case someone wants to update the transpiler to use the new API when it's available.
Thanks for the feedback!