const fs = require("fs"); const fse = require("fs-extra"); const path = require("path"); const { execSync } = require('child_process'); console.log("Starting Electron build finalization..."); // Define paths const distPath = path.join(__dirname, "..", "dist"); const electronDistPath = path.join(__dirname, "..", "dist-electron"); const wwwPath = path.join(electronDistPath, "www"); const builtIndexPath = path.join(distPath, "index.html"); const finalIndexPath = path.join(wwwPath, "index.html"); // Ensure target directory exists if (!fs.existsSync(wwwPath)) { fs.mkdirSync(wwwPath, { recursive: true }); } // Copy assets directory const assetsSrc = path.join(distPath, "assets"); const assetsDest = path.join(wwwPath, "assets"); if (fs.existsSync(assetsSrc)) { fse.copySync(assetsSrc, assetsDest, { overwrite: true }); } // Copy favicon.ico const faviconSrc = path.join(distPath, "favicon.ico"); if (fs.existsSync(faviconSrc)) { fs.copyFileSync(faviconSrc, path.join(wwwPath, "favicon.ico")); } // Copy manifest.webmanifest const manifestSrc = path.join(distPath, "manifest.webmanifest"); if (fs.existsSync(manifestSrc)) { fs.copyFileSync(manifestSrc, path.join(wwwPath, "manifest.webmanifest")); } // Load and modify index.html from Vite output let indexContent = fs.readFileSync(builtIndexPath, "utf-8"); // Inject the window.process shim after the first