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

const styleDir = path.join(__dirname, '../common/style');

function walk(dir) {
    for (const name of fs.readdirSync(dir)) {
        const full = path.join(dir, name);
        if (fs.statSync(full).isDirectory()) {
            walk(full);
            continue;
        }
        if (!name.endsWith('.css')) continue;
        let css = fs.readFileSync(full, 'utf8');
        const next = css
            .replace(/url\(@\/static\/images\//g, 'url(/static/images/')
            .replace(/url\("@\/static\/images\//g, 'url("/static/images/')
            .replace(/url\('@\/static\/images\//g, "url('/static/images/");
        if (next !== css) {
            fs.writeFileSync(full, next, 'utf8');
            console.log('fixed', path.relative(styleDir, full));
        }
    }
}

walk(styleDir);
console.log('done');
