You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.6 KiB
50 lines
1.6 KiB
const fs = require("fs");
|
|
const fse = require("fs-extra");
|
|
const path = require("path");
|
|
|
|
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 <script> block
|
|
indexContent = indexContent.replace(
|
|
/<script[^>]*type="module"[^>]*>/,
|
|
match => `${match}\n window.process = { env: { VITE_PLATFORM: 'electron' } };`
|
|
);
|
|
|
|
// Write the modified index.html to dist-electron/www
|
|
fs.writeFileSync(finalIndexPath, indexContent);
|
|
|
|
console.log("Electron index.html copied and patched for Electron context.");
|
|
|