import fs from 'fs';
import path from 'path';

const BASE_URL = process.env.BASE_URL || 'https://bayareait.services';

const generateRobots = () => {
    const content = `User-agent: *
Allow: /
Disallow: /admin
Disallow: /api

Sitemap: ${BASE_URL}/sitemap.xml
`;
    return content;
};

const robots = generateRobots();
const outputPath = path.resolve(process.cwd(), 'public/robots.txt');
const publicDir = path.dirname(outputPath);

if (!fs.existsSync(publicDir)) {
    fs.mkdirSync(publicDir, { recursive: true });
}

fs.writeFileSync(outputPath, robots);
console.log(`Robots.txt generated at ${outputPath}`);
