timesafari
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.

72 lines
2.3 KiB

const fs = require('fs-extra');
const path = require('path');
async function main() {
try {
console.log('Starting electron build process...');
// Clean directories
const distElectronDir = path.resolve(__dirname, '../dist-electron');
const buildDir = path.resolve(__dirname, '../dist-electron-build');
await fs.emptyDir(distElectronDir);
await fs.emptyDir(buildDir);
console.log('Cleaned directories');
// First build the web app if it doesn't exist
const webDist = path.resolve(__dirname, '../dist');
if (!await fs.pathExists(webDist)) {
console.log('Web dist not found, building web app first...');
throw new Error('Please run \'npm run build\' first to build the web app');
}
// Copy web files to www directory
const wwwDir = path.join(distElectronDir, 'www');
await fs.copy(webDist, wwwDir);
console.log('Copied web files to:', wwwDir);
// Copy and process main.js
const mainJsSrc = path.resolve(__dirname, '../src/electron/main.js');
const mainJsDest = path.join(distElectronDir, 'main.js');
await fs.copy(mainJsSrc, mainJsDest);
console.log('Copied main.js to:', mainJsDest);
// Create the production package.json
const devPackageJson = require('../package.json');
const prodPackageJson = {
name: devPackageJson.name,
version: devPackageJson.version,
description: devPackageJson.description,
author: devPackageJson.author,
main: 'main.js',
private: true
};
await fs.writeJson(
path.join(distElectronDir, 'package.json'),
prodPackageJson,
{ spaces: 2 }
);
// Verify the structure
console.log('\nVerifying build structure:');
const printDir = async (dir, prefix = '') => {
const items = await fs.readdir(dir);
for (const item of items) {
const fullPath = path.join(dir, item);
const stat = await fs.stat(fullPath);
console.log(`${prefix}${item}${stat.isDirectory() ? '/' : ''}`);
if (stat.isDirectory()) {
await printDir(fullPath, `${prefix} `);
}
}
};
await printDir(distElectronDir);
console.log('\nBuild completed successfully!');
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
}
main().catch(console.error);