-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
56 lines (44 loc) · 1.47 KB
/
build.js
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
const { exec } = require('child_process');
const path = require('path');
const fs = require('fs');
// Define paths
const reactAppPath = path.join(__dirname, 'src', 'renderer');
const buildPath = path.join(reactAppPath, 'build');
function buildReactApp() {
return new Promise((resolve, reject) => {
console.log('Building React app...');
exec('npm run build', { cwd: reactAppPath }, (error, stdout, stderr) => {
if (error) {
console.error(`Error building React app: ${stderr}`);
return reject(error);
}
console.log(stdout);
resolve();
});
});
}
function startElectronApp() {
return new Promise((resolve, reject) => {
console.log('Starting Electron app...');
exec('electron .', { cwd: __dirname }, (error, stdout, stderr) => {
if (error) {
console.error(`Error starting Electron app: ${stderr}`);
return reject(error);
}
console.log(stdout);
resolve();
});
});
}
async function main() {
try {
await buildReactApp();
if (!fs.existsSync(buildPath)) {
throw new Error('Build directory does not exist. Please check if the React app built successfully.');
}
await startElectronApp();
} catch (error) {
console.error(`Failed to build and start the application: ${error.message}`);
}
}
main();