forked from codinit-dev/codinit-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectron-dev.mjs
More file actions
81 lines (64 loc) · 2.16 KB
/
electron-dev.mjs
File metadata and controls
81 lines (64 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import fs from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const rootDir = join(__dirname, '..');
function runCommand(command, args, options = {}) {
return new Promise((resolve, reject) => {
console.log(`\n🔧 Running: ${command} ${args.join(' ')}\n`);
const child = spawn(command, args, {
stdio: 'inherit',
shell: true,
...options,
});
child.on('error', (error) => {
console.error(`Error executing ${command}:`, error);
reject(error);
});
child.on('exit', (code) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`${command} exited with code ${code}`));
}
});
});
}
async function buildElectron() {
console.log('\n📦 Building Electron app for development...\n');
try {
console.log('Step 1/3: Building Remix renderer for Electron...');
await runCommand('pnpm', ['electron:build:renderer']);
console.log('\n✅ Renderer build complete!\n');
console.log('Step 2/3: Building Electron main and preload...');
await runCommand('pnpm', ['electron:build:deps']);
console.log('\n✅ Main and preload build complete!\n');
console.log('Step 3/3: Starting Electron...');
const electronPath = join(rootDir, 'node_modules/.bin/electron');
const mainPath = join(rootDir, 'build/electron/main/index.mjs');
if (!fs.existsSync(mainPath)) {
throw new Error(`Main process file not found at: ${mainPath}`);
}
const electronProcess = spawn(electronPath, [mainPath], {
stdio: 'inherit',
env: {
...process.env,
NODE_ENV: 'development',
},
});
electronProcess.on('exit', (code) => {
console.log(`\n👋 Electron exited with code ${code}\n`);
process.exit(code || 0);
});
electronProcess.on('error', (error) => {
console.error('Failed to start Electron:', error);
process.exit(1);
});
} catch (error) {
console.error('\n❌ Build failed:', error.message);
process.exit(1);
}
}
buildElectron();