From 46e66c32c97e2642d51775e459aff4febdab41cb Mon Sep 17 00:00:00 2001 From: Reece Dunham Date: Tue, 6 Aug 2024 10:42:29 -0400 Subject: [PATCH] chore: small refactor to add itemsize tool --- packaging/add_itemsize/add_itemsize.js | 54 ++++++++++++++------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/packaging/add_itemsize/add_itemsize.js b/packaging/add_itemsize/add_itemsize.js index 18bb2868..145790dc 100644 --- a/packaging/add_itemsize/add_itemsize.js +++ b/packaging/add_itemsize/add_itemsize.js @@ -16,6 +16,9 @@ * along with this program. If not, see . */ +const fs = require("fs") +const { execSync } = require("child_process") + // Usage: // - Go to https://glaciermodding.org/rpkg/ and click "Download latest CLI" // - Extract contents of downloaded zip file to packaging/add_itemsize/ @@ -24,12 +27,12 @@ // - either H2 or H3 Runtime path seem to work for Scpc Game Version async function main() { - const fs = require("fs") const rpkgCli = `"./rpkg-cli.exe"` - const { execSync } = require("child_process") + let chunk0patches = fs .readdirSync(`${process.argv[2]}`) .filter((fn) => fn.includes("chunk0") && !fn.includes("300.rpkg")) + let gameprefix = "" if (process.argv[3] === "H1") { gameprefix = "Legacy" @@ -66,14 +69,15 @@ async function main() { 0, repofiles[0].length - 5, )}.json` - await fs.promises - .copyFile(orig, newfile) - .then(function () { - console.log(`${newfile} file copied`) - }) - .catch(function (error) { - console.log(error) - }) + + try { + await fs.promises.copyFile(orig, newfile) + + console.log(`${newfile} file copied`) + } catch (error) { + console.log(error) + } + let repochunk0 = require(`../add_itemsize/${newfile}`) for (let i = 0; i < allunlockables.length; i++) { @@ -114,21 +118,21 @@ async function main() { } const jsonContent = JSON.stringify(allunlockables, null, 4) - fs.writeFile( - `../../static/${gameprefix}allunlockables.json`, - jsonContent, - "utf8", - function (err) { - if (err) { - return console.log(err) - } - console.log( - `${gameprefix}allunlockables.json file updated with item sizes!`, - ) - // Might be better to have the user call this themselves, but it resolves line break inconsistencies - execSync(`yarn prettier`) - }, - ) + try { + await fs.promises.writeFile( + `../../static/${gameprefix}allunlockables.json`, + jsonContent, + "utf8", + ) + + console.log( + `${gameprefix}allunlockables.json file updated with item sizes!`, + ) + // Might be better to have the user call this themselves, but it resolves line break inconsistencies + execSync(`yarn prettier`) + } catch (error) { + console.log(error) + } } main()