Files
firmware/scripts/shared.js
2017-10-29 17:35:55 +01:00

47 lines
1.0 KiB
JavaScript

require('shelljs/global');
function getBlhostCmd() {
let blhostPath;
switch (process.platform) {
case 'linux':
blhostPath = 'linux/amd64/blhost';
break;
case 'darwin':
blhostPath = 'mac/blhost';
break;
case 'win32':
blhostPath = 'win/blhost.exe';
break;
default:
echo('Your operating system is not supported');
exit(1);
break;
}
return `../../../lib/bootloader/bin/Tools/blhost/${blhostPath} --usb 0x1d50,0x6121`;
}
function execRetry(command) {
let firstRun = true;
let remainingRetries = 3;
let code;
do {
if (!firstRun) {
console.log(`Retrying ${command}`)
}
config.fatal = !remainingRetries;
code = exec(command).code;
config.fatal = true;
firstRun = false;
} while(code && --remainingRetries);
}
const exp = {
getBlhostCmd,
execRetry,
}
Object.keys(exp).forEach(function (cmd) {
global[cmd] = exp[cmd];
});