const fs = require('fs');
const path = require('path');
const rootDir = path.resolve(__dirname, '..');
const apps = [
{ name: 'Doctor', dir: path.join(rootDir, 'public', 'App', 'Doctor'), bundleName: 'doctor-app.bundle.js' },
{ name: 'Nursing', dir: path.join(rootDir, 'public', 'App', 'Nursing'), bundleName: 'nursing-app.bundle.js' },
{ name: 'MedicalStore', dir: path.join(rootDir, 'public', 'App', 'MedicalStore'), bundleName: 'medicalstore-app.bundle.js' }
];
for (const app of apps) {
const htmlPath = path.join(app.dir, 'index.html');
let content = fs.readFileSync(htmlPath, 'utf8');
// 1. Remove unsafe-eval from meta CSP
content = content.replace(/'unsafe-eval'\s*/g, '');
// 2. Remove babel.min.js script tag
content = content.replace(/\s* with the bundle script
const babelStart = content.indexOf('', babelStart);
if (babelEnd !== -1) {
const before = content.substring(0, babelStart);
const after = content.substring(babelEnd + ''.length);
content = before + `` + after;
console.log(`Updated ${app.name}/index.html to use ${app.bundleName}`);
} else {
console.warn(`Could not find closing for ${app.name}`);
}
} else {
console.log(`${app.name}/index.html already updated`);
}
fs.writeFileSync(htmlPath, content, 'utf8');
}
console.log('All PWA index.html files switched to precompiled bundles without Babel or unsafe-eval.');