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.
148 lines
4.8 KiB
148 lines
4.8 KiB
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
console.log('Starting electron build process...');
|
|
|
|
// Define paths
|
|
const electronDistPath = path.join(__dirname, '..', 'dist-electron');
|
|
const wwwPath = path.join(electronDistPath, 'www');
|
|
|
|
// Create www directory if it doesn't exist
|
|
if (!fs.existsSync(wwwPath)) {
|
|
fs.mkdirSync(wwwPath, { recursive: true });
|
|
}
|
|
|
|
// Copy the Vite-built index.html to www directory
|
|
const viteIndexPath = path.join(electronDistPath, 'index.html');
|
|
const wwwIndexPath = path.join(wwwPath, 'index.html');
|
|
|
|
if (fs.existsSync(viteIndexPath)) {
|
|
console.log('Copying Vite-built index.html to www directory...');
|
|
fs.copyFileSync(viteIndexPath, wwwIndexPath);
|
|
|
|
// Remove the original index.html from dist-electron root
|
|
fs.unlinkSync(viteIndexPath);
|
|
console.log('Moved index.html to www directory');
|
|
} else {
|
|
console.error('Vite-built index.html not found at:', viteIndexPath);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Copy assets directory if it exists in dist-electron
|
|
const assetsSrc = path.join(electronDistPath, 'assets');
|
|
const assetsDest = path.join(wwwPath, 'assets');
|
|
|
|
if (fs.existsSync(assetsSrc)) {
|
|
console.log('Moving assets directory to www...');
|
|
if (fs.existsSync(assetsDest)) {
|
|
fs.rmSync(assetsDest, { recursive: true, force: true });
|
|
}
|
|
fs.renameSync(assetsSrc, assetsDest);
|
|
console.log('Moved assets directory to www');
|
|
}
|
|
|
|
// Copy favicon if it exists
|
|
const faviconSrc = path.join(electronDistPath, 'favicon.ico');
|
|
const faviconDest = path.join(wwwPath, 'favicon.ico');
|
|
|
|
if (fs.existsSync(faviconSrc)) {
|
|
console.log('Moving favicon to www...');
|
|
fs.renameSync(faviconSrc, faviconDest);
|
|
console.log('Moved favicon to www');
|
|
}
|
|
|
|
// Remove service worker files from www directory
|
|
const swFilesToRemove = [
|
|
'sw.js',
|
|
'sw.js.map',
|
|
'workbox-*.js',
|
|
'workbox-*.js.map',
|
|
'registerSW.js',
|
|
'manifest.webmanifest'
|
|
];
|
|
|
|
console.log('Removing service worker files...');
|
|
swFilesToRemove.forEach(pattern => {
|
|
const files = fs.readdirSync(wwwPath).filter(file =>
|
|
file.match(new RegExp(pattern.replace(/\*/g, '.*')))
|
|
);
|
|
files.forEach(file => {
|
|
const filePath = path.join(wwwPath, file);
|
|
console.log(`Removing ${filePath}`);
|
|
try {
|
|
fs.unlinkSync(filePath);
|
|
} catch (err) {
|
|
console.warn(`Could not remove ${filePath}:`, err.message);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Also check and remove from assets directory
|
|
if (fs.existsSync(assetsDest)) {
|
|
swFilesToRemove.forEach(pattern => {
|
|
const files = fs.readdirSync(assetsDest).filter(file =>
|
|
file.match(new RegExp(pattern.replace(/\*/g, '.*')))
|
|
);
|
|
files.forEach(file => {
|
|
const filePath = path.join(assetsDest, file);
|
|
console.log(`Removing ${filePath}`);
|
|
try {
|
|
fs.unlinkSync(filePath);
|
|
} catch (err) {
|
|
console.warn(`Could not remove ${filePath}:`, err.message);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
// Verify the final index.html structure
|
|
const finalIndexContent = fs.readFileSync(wwwIndexPath, 'utf8');
|
|
console.log('Final index.html structure:');
|
|
console.log('- Has CSS link:', finalIndexContent.includes('<link rel="stylesheet"'));
|
|
console.log('- Has main script:', finalIndexContent.includes('main.electron.js'));
|
|
console.log('- No service worker references:', !finalIndexContent.includes('serviceWorker'));
|
|
|
|
// Copy main process files to the correct location
|
|
console.log('Setting up main process files...');
|
|
|
|
// The main process files are already in the correct location
|
|
// Just verify they exist and are ready
|
|
const mainPath = path.join(electronDistPath, 'main.js');
|
|
const preloadPath = path.join(electronDistPath, 'preload.js');
|
|
|
|
if (fs.existsSync(mainPath)) {
|
|
console.log('Main process file ready at:', mainPath);
|
|
} else {
|
|
console.error('Main process file not found at:', mainPath);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (fs.existsSync(preloadPath)) {
|
|
console.log('Preload script ready at:', preloadPath);
|
|
} else {
|
|
console.warn('Preload script not found at:', preloadPath);
|
|
}
|
|
|
|
// Clean up any remaining files in dist-electron root (except main.js, preload.js, and www directory)
|
|
const remainingFiles = fs.readdirSync(electronDistPath);
|
|
remainingFiles.forEach(file => {
|
|
if (file !== 'main.js' && file !== 'preload.js' && file !== 'www') {
|
|
const filePath = path.join(electronDistPath, file);
|
|
console.log(`Removing remaining file: ${file}`);
|
|
try {
|
|
if (fs.statSync(filePath).isDirectory()) {
|
|
fs.rmSync(filePath, { recursive: true, force: true });
|
|
} else {
|
|
fs.unlinkSync(filePath);
|
|
}
|
|
} catch (err) {
|
|
console.warn(`Could not remove ${filePath}:`, err.message);
|
|
}
|
|
}
|
|
});
|
|
|
|
console.log('Electron build process completed successfully');
|
|
console.log('Final structure:');
|
|
console.log('- Main process:', path.join(electronDistPath, 'main.js'));
|
|
console.log('- Preload script:', path.join(electronDistPath, 'preload.js'));
|
|
console.log('- Web assets:', path.join(electronDistPath, 'www'));
|