From 01ecc7c48764040e06e515a42692fa0520b3369c Mon Sep 17 00:00:00 2001 From: Jesse Hall Date: Thu, 24 Mar 2022 12:04:33 -0500 Subject: [PATCH] update update_info file --- backend/utils/update_info.js | 48 +++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/backend/utils/update_info.js b/backend/utils/update_info.js index 2753c398a8..770f4625a8 100644 --- a/backend/utils/update_info.js +++ b/backend/utils/update_info.js @@ -8,31 +8,33 @@ const { namePrefix, } = require(`${basePath}/src/config.js`); -// read json data -let rawdata = fs.readFileSync(`${basePath}/build/json/_metadata.json`); -let data = JSON.parse(rawdata); +(async () => { + // read json data + let rawdata = fs.readFileSync(`${basePath}/build/json/_metadata.json`); + let data = JSON.parse(rawdata); -console.log("Info will be updated using the config.js data."); -const updateName = await yesno(`Update names?`); -const updateDescription = await yesno(`Update descriptions?`); -const updateBaseUri = await yesno(`Update images base URI?`); + console.log("Info will be updated using the config.js data."); + const updateName = await yesno(`Update names?`); + const updateDescription = await yesno(`Update descriptions?`); + const updateBaseUri = await yesno(`Update images base URI?`); + + data.forEach((item) => { + if(updateName) item.name = `${namePrefix} #${item.edition}`; + if(updateDescription) item.description = description; + if(updateBaseUri) item.image = `${baseUri}/${item.edition}.png`; + + fs.writeFileSync( + `${basePath}/build/json/${item.edition}.json`, + JSON.stringify(item, null, 2) + ); + }); -data.forEach((item) => { - if(updateName) item.name = `${namePrefix} #${item.edition}`; - if(updateDescription) item.description = description; - if(updateBaseUri) item.image = `${baseUri}/${item.edition}.png`; - fs.writeFileSync( - `${basePath}/build/json/${item.edition}.json`, - JSON.stringify(item, null, 2) + `${basePath}/build/json/_metadata.json`, + JSON.stringify(data, null, 2) ); -}); - -fs.writeFileSync( - `${basePath}/build/json/_metadata.json`, - JSON.stringify(data, null, 2) -); -if(updateName) console.log(`Updated name prefix for images to ===> ${namePrefix}`); -if(updateBaseUri) console.log(`Updated baseUri for images to ===> ${baseUri}`); -if(updateDescription) console.log(`Updated description for images to ===> ${description}`); + if(updateName) console.log(`Updated name prefix for images to ===> ${namePrefix}`); + if(updateBaseUri) console.log(`Updated baseUri for images to ===> ${baseUri}`); + if(updateDescription) console.log(`Updated description for images to ===> ${description}`); +})()