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