diff --git a/scripts/getLatestClientRelease.js b/scripts/getLatestClientRelease.js index 4ecc702b..be3af2fe 100644 --- a/scripts/getLatestClientRelease.js +++ b/scripts/getLatestClientRelease.js @@ -19,39 +19,48 @@ gh.getRepo('faforever', 'client').getRelease('latest', function(err, release) { }; //Write to file - fs.writeFile("link.json", JSON.stringify(data), function(error) { - if (error) { - console.log(error); + fs.writeFile("link.json", JSON.stringify(data), function(err) { + if (err) { + console.log(err); + verifyOutput(); } else { console.log(date + ' - Link file created successfully for latest client links.'); } }); - } - }); - - } -} -); - -//Try to read the file after creating it -fs.readFile('link.json', 'utf8', function (err, data) { - try { - //Must of parsed out properly - clientLink = JSON.parse(data); - } catch (e) { - //Must not have... - console.log(date + ' - Link file incorrectly made. Data was - ' + data); - //Write default values to file... - data = { - client_link: 'https://github.com/FAForever/client/releases', - downlords_faf_client_link: 'https://github.com/FAForever/downlords-faf-client/releases' - }; - fs.writeFile("link.json", JSON.stringify(data), function(error) { - if (error) { - console.log(error); } else { - console.log(date + ' - Link file verified.'); + console.log(err); + verifyOutput(); } }); + + } else { + console.log(err); + verifyOutput(); } }); + +function verifyOutput() +{ + //Try to read the file after creating it + fs.readFile('link.json', 'utf8', function (err, data) { + try { + //Must of parsed out properly + clientLink = JSON.parse(data); + } catch (e) { + //Must not have... + console.log(date + ' - Link file incorrectly made. Data was - ' + data); + //Write default values to file... + data = { + client_link: 'https://github.com/FAForever/client/releases', + downlords_faf_client_link: 'https://github.com/FAForever/downlords-faf-client/releases' + }; + fs.writeFile("link.json", JSON.stringify(data), function(error) { + if (error) { + console.log(error); + } else { + console.log(date + ' - Link file verified.'); + } + }); + } + }); +} \ No newline at end of file