import * as fs from 'node:fs'; import * as path from 'node:path'; import { fileURLToPath } from 'node:url'; import 'dotenv/config'; // Get the current file's directory const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); if (!process.env.VITE_BANG_URL) { console.error('VITE_BANG_URL environment variable must be set.'); } // Get the Bang URL from environment or use a default for local development const bangUrl = process.env.VITE_BANG_URL; // Create the OpenSearch XML content const openSearchXml = ` Bang! A better default search engine with bangs UTF-8 ${bangUrl}/bang.svg ${bangUrl} `; // Ensure the public directory exists const publicDir = path.resolve(__dirname, '../public'); if (!fs.existsSync(publicDir)) { fs.mkdirSync(publicDir, { recursive: true }); } // Write the OpenSearch XML file fs.writeFileSync(path.join(publicDir, 'opensearch.xml'), openSearchXml); console.log('OpenSearch XML file generated successfully!');