From de41cd04ff80b65f4d682a49d5bb21bff9c77c14 Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Sat, 14 Oct 2023 15:11:23 -0600 Subject: [PATCH] feat: improved `fix-frontend-js.js` to fix multiple files --- common/fix-frontend-js.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/common/fix-frontend-js.js b/common/fix-frontend-js.js index 789d45c..d3f4439 100644 --- a/common/fix-frontend-js.js +++ b/common/fix-frontend-js.js @@ -2,13 +2,24 @@ const fs = require('fs-extra'); const { path } = require('@tycrek/joint'); const log = new (require('@tycrek/log').TLog)(); -log.info('Fixing frontend JS'); +const FILES = { + prefix: 'dist-frontend', + suffix: '.mjs', + pages: [ + 'setup', + 'login' + ] +}; -// Read & fix file data -const setupUiFile = path.join('dist-frontend/setup.mjs'); -const setupUiNew = fs.readFileSync(setupUiFile).toString().replace('export {};', ''); +const fixFile = (page) => { + const filePath = path.join(FILES.prefix, `${page}${FILES.suffix}`); + const fixed = fs.readFileSync(filePath).toString().replace('export {};', ''); -// Write new file -fs.writeFileSync(setupUiFile, setupUiNew); + return fs.writeFile(filePath, fixed); +}; + +log.info('Fixing frontend JS', `${FILES.pages.length} files`); +Promise.all(FILES.pages.map(fixFile)) + .then(() => log.success('Fixed.')) + .catch(console.error); -log.success('Fixed.');