-
Notifications
You must be signed in to change notification settings - Fork 2
/
updateServiceWorkerDateFromInfoPlist.js
65 lines (47 loc) · 1.97 KB
/
updateServiceWorkerDateFromInfoPlist.js
1
/* updateServiceWorkerDateFromInfoPlist.jsThis program extracts the "versionDate" from Info.plist,and from "webAppServiceWorker.js".If they differ, "webAppServiceWorker.js" is rewritten with the"versionDate" from Info.plist.Run with Node.©2024 Michael Bach, bach@uni-freiburg.deHistory=======2024-08-02 fully working2024-08-01 begun*/const fs = require('fs');const plistPath = './Info.plist';const serviceWorkerPath = './webAppServiceWorker.js';console.info("***\nComparing versionDates in " + plistPath, " and " + serviceWorkerPath + ".");console.info("If they differ, " + serviceWorkerPath + " is updated.");console.info("***\n");// Info.plistlet data = fs.readFileSync(plistPath, 'utf8');let i = data.indexOf("VersionDate</key>");let searchString = "<string>";let indexStart = data.indexOf(searchString, i) + searchString.length;let indexEnd = data.indexOf("</string>", indexStart);const versionDate = data.substring(indexStart, indexEnd);data = ""; // release memoryconsole.info("versionDate in " + plistPath + ": " + versionDate)// serviceWorkerdata = fs.readFileSync(serviceWorkerPath, 'utf8');searchString = 'cacheName = "FrACT10'; // The "á" does not work in `indexOf`???indexStart = data.indexOf(searchString) + searchString.length + 1;let dataOut = data.substring(0, indexStart)searchString = '";'indexEnd = data.indexOf(searchString, indexStart);// + searchString.length + 1;const versionDateInServiceWorker = data.substring(indexStart, indexEnd);console.info("versionDate in " + serviceWorkerPath + ": " + versionDateInServiceWorker+ "\n");// now compare, exit if equalif (versionDate === versionDateInServiceWorker) { console.info("versionDates are identical, no further action; good bye.\n"); return;}console.info("versionDates differ, rewriting " + serviceWorkerPath);dataOut += versionDate + data.substring(indexEnd);data = "";//console.info(dataOut)fs.writeFileSync(serviceWorkerPath, dataOut);console.log("File written successfully.\n");