feat: enhance Electron build process and server preparation#65
feat: enhance Electron build process and server preparation#65
Conversation
SuperComboGamer
commented
Dec 13, 2025
- Added new build scripts for Electron targeting Windows, macOS, and Linux.
- Updated the main build script to include server preparation steps.
- Introduced a new script to prepare the server for bundling with Electron, including cleaning previous builds and installing production dependencies.
- Modified the Electron main process to verify server file existence and improved error handling.
- Updated .gitignore to exclude the new server-bundle directory.
- Added new build scripts for Electron targeting Windows, macOS, and Linux. - Updated the main build script to include server preparation steps. - Introduced a new script to prepare the server for bundling with Electron, including cleaning previous builds and installing production dependencies. - Modified the Electron main process to verify server file existence and improved error handling. - Updated .gitignore to exclude the new server-bundle directory.
Summary of ChangesHello @SuperComboGamer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refines the Electron application's build process by introducing dedicated scripts for platform-specific builds and automating the preparation of the backend server for bundling. These changes ensure that the server component is correctly packaged and launched within the Electron environment, improving reliability and simplifying the build workflow for different operating systems. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request significantly enhances the Electron build process by introducing a dedicated script to prepare the backend server for bundling. This includes building the server, isolating its production dependencies, and configuring the Electron build to include these artifacts. The changes also improve the main Electron process by adding verification for the server's existence and better error handling for the server process. My review focuses on improving the maintainability of the new build scripts and the robustness of the server preparation script.
| "build:electron": "node scripts/prepare-server.js && next build && electron-builder", | ||
| "build:electron:win": "node scripts/prepare-server.js && next build && electron-builder --win", | ||
| "build:electron:mac": "node scripts/prepare-server.js && next build && electron-builder --mac", | ||
| "build:electron:linux": "node scripts/prepare-server.js && next build && electron-builder --linux", |
There was a problem hiding this comment.
There's some duplication in the build:electron:* scripts. Each script repeats node scripts/prepare-server.js && next build. To improve maintainability and reduce repetition, you could extract the common preparation steps into a separate script. This way, if the preparation steps change, you only need to update it in one place.
"prepare:electron:build": "node scripts/prepare-server.js && next build",
"build:electron": "npm run prepare:electron:build && electron-builder",
"build:electron:win": "npm run prepare:electron:build && electron-builder --win",
"build:electron:mac": "npm run prepare:electron:build && electron-builder --mac",
"build:electron:linux": "npm run prepare:electron:build && electron-builder --linux"| console.log('🔧 Preparing server for Electron bundling...\n'); | ||
|
|
||
| // Step 1: Clean up previous bundle | ||
| if (existsSync(BUNDLE_DIR)) { | ||
| console.log('🗑️ Cleaning previous server-bundle...'); | ||
| rmSync(BUNDLE_DIR, { recursive: true }); | ||
| } | ||
| mkdirSync(BUNDLE_DIR, { recursive: true }); | ||
|
|
||
| // Step 2: Build the server TypeScript | ||
| console.log('📦 Building server TypeScript...'); | ||
| execSync('npm run build', { cwd: SERVER_DIR, stdio: 'inherit' }); | ||
|
|
||
| // Step 3: Copy server dist | ||
| console.log('📋 Copying server dist...'); | ||
| cpSync(join(SERVER_DIR, 'dist'), join(BUNDLE_DIR, 'dist'), { recursive: true }); | ||
|
|
||
| // Step 4: Create a minimal package.json for the server | ||
| console.log('📝 Creating server package.json...'); | ||
| const serverPkg = JSON.parse(readFileSync(join(SERVER_DIR, 'package.json'), 'utf-8')); | ||
|
|
||
| const bundlePkg = { | ||
| name: '@automaker/server-bundle', | ||
| version: serverPkg.version, | ||
| type: 'module', | ||
| main: 'dist/index.js', | ||
| dependencies: serverPkg.dependencies | ||
| }; | ||
|
|
||
| writeFileSync( | ||
| join(BUNDLE_DIR, 'package.json'), | ||
| JSON.stringify(bundlePkg, null, 2) | ||
| ); | ||
|
|
||
| // Step 5: Install production dependencies | ||
| console.log('📥 Installing server production dependencies...'); | ||
| execSync('npm install --omit=dev', { | ||
| cwd: BUNDLE_DIR, | ||
| stdio: 'inherit', | ||
| env: { | ||
| ...process.env, | ||
| // Prevent npm from using workspace resolution | ||
| npm_config_workspace: '' | ||
| } | ||
| }); | ||
|
|
||
| console.log('\n✅ Server prepared for bundling at:', BUNDLE_DIR); |
There was a problem hiding this comment.
This is a well-structured script for preparing the server. To make it more robust, consider wrapping the main logic in a try...catch block. This will provide a clearer error message and ensure a non-zero exit code on failure, which is good practice for build scripts.
try {
console.log('🔧 Preparing server for Electron bundling...\n');
// Step 1: Clean up previous bundle
if (existsSync(BUNDLE_DIR)) {
console.log('🗑️ Cleaning previous server-bundle...');
rmSync(BUNDLE_DIR, { recursive: true });
}
mkdirSync(BUNDLE_DIR, { recursive: true });
// Step 2: Build the server TypeScript
console.log('📦 Building server TypeScript...');
execSync('npm run build', { cwd: SERVER_DIR, stdio: 'inherit' });
// Step 3: Copy server dist
console.log('📋 Copying server dist...');
cpSync(join(SERVER_DIR, 'dist'), join(BUNDLE_DIR, 'dist'), { recursive: true });
// Step 4: Create a minimal package.json for the server
console.log('📝 Creating server package.json...');
const serverPkg = JSON.parse(readFileSync(join(SERVER_DIR, 'package.json'), 'utf-8'));
const bundlePkg = {
name: '@automaker/server-bundle',
version: serverPkg.version,
type: 'module',
main: 'dist/index.js',
dependencies: serverPkg.dependencies
};
writeFileSync(
join(BUNDLE_DIR, 'package.json'),
JSON.stringify(bundlePkg, null, 2)
);
// Step 5: Install production dependencies
console.log('📥 Installing server production dependencies...');
execSync('npm install --omit=dev', {
cwd: BUNDLE_DIR,
stdio: 'inherit',
env: {
...process.env,
// Prevent npm from using workspace resolution
npm_config_workspace: ''
}
});
console.log('\n✅ Server prepared for bundling at:', BUNDLE_DIR);
} catch (error) {
console.error('\n❌ Failed to prepare server for bundling:', error);
process.exit(1);
}- Upgraded Electron version to 39.2.7 and TypeScript to 5.9.3 in package-lock.json. - Modified next.config.ts to set output to "export" for static site generation. - Changed package.json to include the output directory for deployment. - Enhanced main.js to implement a static file server for production builds, serving files from the "out" directory. - Adjusted the loading mechanism to use the static server in production and the Next.js dev server in development.
- Added functionality to set a default workspace directory in Electron, creating it if it doesn't exist. - Improved project path construction in the New Project Modal to use platform-specific path separators. - Enhanced error handling in the Templates route for parent directory access, including logging for better debugging.
- Added useEffect hook to automatically collapse the sidebar when the screen width is below 1024px. - Included event listener for media query changes to handle sidebar state dynamically.
- Enhanced the layout of the FileBrowserDialog component by adding overflow handling and padding to improve visual consistency. - Updated the DialogHeader and DialogFooter with additional styling for better separation and usability.
- Updated the project path construction to use platform-specific path separators, enhancing compatibility across different operating systems. - Implemented a check for the Electron API to determine the appropriate path separator based on the user's platform.
- Changed the application icon from "public/logo_larger.png" to "public/icon.ico" for improved branding. - Added new icon file "icon.ico" to the public directory.
- Added afterPack script in package.json to rebuild native modules for the server bundle. - Improved icon handling in main.js to support cross-platform formats and verify icon existence. - Updated startStaticServer function to return a promise for better error handling. - Introduced a new script, rebuild-server-natives.js, to rebuild native modules based on the target architecture. - Enhanced prepare-server.js to include native module rebuilding step for improved terminal functionality.
f9386ea to
8dc3bdd
Compare