From d634eaea22db444fe4915f2710bdac7535486cd5 Mon Sep 17 00:00:00 2001 From: Nitish Shelage Date: Wed, 17 Aug 2022 19:43:46 +0530 Subject: [PATCH] Script updated for GVL changes --- update-vendor-list.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/update-vendor-list.js b/update-vendor-list.js index 7325e44..4bbcb19 100644 --- a/update-vendor-list.js +++ b/update-vendor-list.js @@ -36,7 +36,9 @@ async function updateGVLData(){ console.log(`writing file vendor-list-v${counter}.json`); await downloadFile(`${latestVersionURL}/archives/vendor-list-v${counter}.json`, `./docs/vendorlist/archives/vendor-list-v${counter}.json`); } - await downloadFile(`${latestVersionURL}/archives/vendor-list-v${latestVersion}.json`, `./docs/vendorlist/vendor-list.json`); + console.log(`updating file vendor-list.json`); + await removeOldFile(`./docs/vendorlist/vendor-list.json`); + await updateVendorList(`./docs/vendorlist/vendor-list.json`, `archives/vendor-list-v${latestVersion}.json`); } } @@ -56,4 +58,23 @@ async function downloadFile(fileUrl, outputLocationPath) { }); } +async function removeOldFile(path){ + return Fs.unlink(path,function(err){ + if(err) return console.log(err); + console.log('file deleted successfully'); + }); +} + +async function updateVendorList(path, content){ + return Fs.writeFile(path, content, (err) => { + if (err) + console.log(err); + else { + console.log("File written successfully\n"); + console.log("The written has the following contents:"); + console.log(Fs.readFileSync(path, "utf8")); + } + }); +} + updateGVLData(); \ No newline at end of file