const fs = require('fs');
const path = require('path');

const dir = path.join(__dirname, '../components/memberInfo');
const files = fs.readdirSync(dir).filter((f) => f.endsWith('.vue'));

const optionsBlock = `    options: {
        virtualHost: true,
        styleIsolation: 'apply-shared'
    },`;

for (const file of files) {
    let content = fs.readFileSync(path.join(dir, file), 'utf8');
    content = content.replace(/\r\n/g, '\n');
    content = content.replace(/\n<style>[\s\S]*?<\/style>\n?/g, '\n');

    if (content.includes('options:')) {
        content = content.replace(/options:\s*\{[\s\S]*?\},?/m, optionsBlock);
    } else {
        content = content.replace(/export default \{\n/, `export default {\n${optionsBlock}\n`);
    }

    fs.writeFileSync(path.join(dir, file), content.endsWith('\n') ? content : content + '\n', 'utf8');
    console.log('updated', file);
}
