mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 08:13:37 +00:00
feat: enhance Electron app packaging and server preparation
- 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.
This commit is contained in:
@@ -64,4 +64,18 @@ execSync('npm install --omit=dev', {
|
||||
}
|
||||
});
|
||||
|
||||
// Step 6: Rebuild native modules for current architecture
|
||||
// This is critical for modules like node-pty that have native bindings
|
||||
console.log('🔨 Rebuilding native modules for current architecture...');
|
||||
try {
|
||||
execSync('npm rebuild', {
|
||||
cwd: BUNDLE_DIR,
|
||||
stdio: 'inherit'
|
||||
});
|
||||
console.log('✅ Native modules rebuilt successfully');
|
||||
} catch (error) {
|
||||
console.warn('⚠️ Warning: Failed to rebuild native modules. Terminal functionality may not work.');
|
||||
console.warn(' Error:', error.message);
|
||||
}
|
||||
|
||||
console.log('\n✅ Server prepared for bundling at:', BUNDLE_DIR);
|
||||
|
||||
66
apps/app/scripts/rebuild-server-natives.js
Normal file
66
apps/app/scripts/rebuild-server-natives.js
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Electron-builder afterPack hook
|
||||
* Rebuilds native modules in the server bundle for the target architecture
|
||||
*/
|
||||
|
||||
const { exec } = require('child_process');
|
||||
const { promisify } = require('util');
|
||||
const path = require('path');
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
exports.default = async function(context) {
|
||||
const { appOutDir, electronPlatformName, arch, packager } = context;
|
||||
const electronVersion = packager.config.electronVersion;
|
||||
|
||||
// Convert arch to string if it's a number (electron-builder sometimes passes indices)
|
||||
const archNames = ['ia32', 'x64', 'armv7l', 'arm64', 'universal'];
|
||||
const archStr = typeof arch === 'number' ? archNames[arch] : arch;
|
||||
|
||||
console.log(`\n🔨 Rebuilding server native modules for ${electronPlatformName}-${archStr}...`);
|
||||
|
||||
// Path to server node_modules in the packaged app
|
||||
let serverNodeModulesPath;
|
||||
if (electronPlatformName === 'darwin') {
|
||||
serverNodeModulesPath = path.join(
|
||||
appOutDir,
|
||||
`${packager.appInfo.productName}.app`,
|
||||
'Contents',
|
||||
'Resources',
|
||||
'server',
|
||||
'node_modules'
|
||||
);
|
||||
} else if (electronPlatformName === 'win32') {
|
||||
serverNodeModulesPath = path.join(
|
||||
appOutDir,
|
||||
'resources',
|
||||
'server',
|
||||
'node_modules'
|
||||
);
|
||||
} else {
|
||||
serverNodeModulesPath = path.join(
|
||||
appOutDir,
|
||||
'resources',
|
||||
'server',
|
||||
'node_modules'
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
// Rebuild native modules for the target architecture
|
||||
const rebuildCmd = `npx --yes @electron/rebuild --version=${electronVersion} --arch=${archStr} --force --module-dir="${serverNodeModulesPath}/.."`;
|
||||
|
||||
console.log(` Command: ${rebuildCmd}`);
|
||||
|
||||
const { stdout, stderr } = await execAsync(rebuildCmd);
|
||||
if (stdout) console.log(stdout);
|
||||
if (stderr) console.error(stderr);
|
||||
|
||||
console.log(`✅ Server native modules rebuilt successfully for ${archStr}\n`);
|
||||
} catch (error) {
|
||||
console.error(`❌ Failed to rebuild server native modules:`, error.message);
|
||||
// Don't fail the build, just warn
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user