-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile.js
63 lines (53 loc) · 1.68 KB
/
compile.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
57
58
59
60
61
62
63
const rimraf = require("rimraf");
const fs = require("fs");
const path = require("path");
const { exec } = require("child_process");
const Dist_Directory = path.join(__dirname, "/dist");
const Build_Directory = path.join(__dirname, "/build");
const newBuild = path.join(__dirname, "/src/electron-starter.js");
const moveTo = path.join(__dirname, "/public/electron.js");
const Run_React_Build = () => {
return new Promise((resolve, reject) => {
console.log(`Starting Yarn run build`);
exec(`yarn run build`, (err, stdout, stderr) => {
console.log(`Completed Yarn run build`);
return err ? reject(err) : resolve(true);
});
});
};
const Run_Electron_Build = () => {
return new Promise((resolve, reject) => {
console.log(`Starting electron-builder`);
exec(`yarn run electron-pack`, (err, stdout, stderr) => {
console.log(`Completed electron-builder`);
return err ? reject(err) : resolve(true);
});
});
};
async function build() {
console.log(`Starting........`);
try {
if (fs.existsSync(Dist_Directory)) {
console.log(`Removing ${Dist_Directory}`);
rimraf.sync(Dist_Directory);
}
if (fs.existsSync(Build_Directory)) {
console.log(`Removing ${Build_Directory}`);
rimraf.sync(Build_Directory);
}
if (fs.existsSync(moveTo)) {
console.log(`Removing ${moveTo}`);
rimraf.sync(moveTo);
console.log(`Copying ${newBuild} over to /public`);
fs.createReadStream(newBuild).pipe(fs.createWriteStream(moveTo));
}
await Run_React_Build();
await Run_Electron_Build();
} catch (e) {
console.log(`ERROR`);
console.log(e);
process.exit();
}
console.log(`DONE`);
}
build();