const fs = require('fs');
const { execSync } = require('child_process');

console.log('Copying app.js to app_final.js...');
fs.copyFileSync('app.js', 'app_final.js');

const scriptsToRun = [
    'update_abstracts_features.js',
    'update_app_final2.js',
    'fix_save.js',
    'fix_save_render.js',
    'fix_numbering.js',
    'add_modal_actions.js',
    'fix_actions.js',
    'fix_client_buttons.js'
];

for (const script of scriptsToRun) {
    if (fs.existsSync(script)) {
        console.log(`Running ${script}...`);
        try {
            execSync(`node ${script}`, { stdio: 'inherit' });
        } catch(e) {
            console.error(`Error running ${script}`);
        }
    } else {
        console.log(`Skipping ${script} (not found)`);
    }
}
console.log('Reconstruction done. Length:', fs.readFileSync('app_final.js').length);
