Skip to content

feat: enhance Electron build process and server preparation#65

Merged
Shironex merged 8 commits intomainfrom
fix-electron-build
Dec 14, 2025
Merged

feat: enhance Electron build process and server preparation#65
Shironex merged 8 commits intomainfrom
fix-electron-build

Conversation

@SuperComboGamer
Copy link
Collaborator

  • 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.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Enhanced Electron Build Scripts: Introduced platform-specific build commands (build:electron:win, build:electron:mac, build:electron:linux) in apps/app/package.json and the root package.json to streamline cross-platform Electron application packaging.
  • Automated Server Preparation: A new script, scripts/prepare-server.js, was added to automate the process of building the backend server, copying its distribution and production-only node_modules into a dedicated server-bundle directory, ensuring it's ready for Electron packaging.
  • Improved Electron Main Process: The Electron main process (electron/main.js) now includes robust checks for the existence of server files, enhanced error handling for server startup failures, and correctly sets the NODE_PATH and cwd for the spawned server process, crucial for bundled environments.
  • Optimized Bundling for Server: The apps/app/package.json build configuration was updated to include the server-bundle directory and its node_modules as extraResources, ensuring the server is properly included in the final Electron application.
  • Dependency Updates: The electron and typescript dependencies were updated to their latest patch versions for improved stability and features.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +23 to +26
"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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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"

Comment on lines 21 to 67
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.
@Shironex Shironex merged commit a3d74fb into main Dec 14, 2025
2 checks passed
@Shironex Shironex deleted the fix-electron-build branch December 14, 2025 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants