import fs from 'fs/promises'; import path from 'path'; import { fileURLToPath } from 'url'; const AMPLITUDE_API_KEY = process.env.AMPLITUDE_API_KEY; const currentPath = fileURLToPath(import.meta.url); const projectRoot = path.dirname(currentPath); const htmlFilePath = path.resolve(projectRoot, '../dist/index.html'); if(AMPLITUDE_API_KEY){ try { const html = await fs.readFile(htmlFilePath, 'utf-8'); const amplitudeCdnScript = ` `; const amplitudeListenerScript = ``; const injectedHtml = html.replace( '
', `\n${amplitudeCdnScript}\n${amplitudeListenerScript}` ); await fs.writeFile(htmlFilePath, injectedHtml, 'utf-8'); console.log('Amplitude scripts successfully injected.'); } catch (err) { console.error('Error injecting Amplitude scripts:', err); } }