import fs from "fs-extra"; import path from "node:path"; import { fileURLToPath } from "node:url"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const root = path.resolve(__dirname, "..", ".."); const source = path.join(root, "chat", "public"); const dest = path.resolve(__dirname, "..", "www"); async function copyUi() { if (!(await fs.pathExists(source))) { throw new Error(`Source UI folder not found: ${source}`); } await fs.emptyDir(dest); await fs.copy(source, dest, { filter: (src) => !src.endsWith(".map") && !src.includes(".DS_Store"), overwrite: true, }); } async function findHtmlFiles(dir) { const entries = await fs.readdir(dir, { withFileTypes: true }); const files = await Promise.all( entries.map(async (entry) => { const full = path.join(dir, entry.name); if (entry.isDirectory()) { return findHtmlFiles(full); } return entry.isFile() && entry.name.endsWith(".html") ? [full] : []; }) ); return files.flat(); } async function injectMetaTags() { const files = await findHtmlFiles(dest); await Promise.all( files.map(async (fullPath) => { let html = await fs.readFile(fullPath, "utf8"); // Add viewport meta if missing if (!html.includes('viewport')) { html = html.replace('
', '\n '); } // Add Capacitor script if (!html.includes('capacitor.js')) { html = html.replace('', ' \n'); } // Add capacitor-bridge.js before closing body tag if (!html.includes('capacitor-bridge.js')) { html = html.replace('
Build WordPress plugins with AI
Build custom WordPress plugins with AI. No coding required - just describe what you need.
Loading your plugins...
', ' \n'); } await fs.writeFile(fullPath, html, "utf8"); }) ); } async function createMobileIndex() { const mobileIndex = `