-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.js
55 lines (45 loc) · 1.49 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
const fs = require('fs');
const process = require("process");
const child_process = require("child_process");
const path = require("path");
const copyRecursiveSync = (src, dest) => {
const exists = fs.existsSync(src);
const stats = exists && fs.statSync(src);
const isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest);
fs.readdirSync(src).forEach(function (childItemName) {
copyRecursiveSync(path.join(src, childItemName),
path.join(dest, childItemName));
});
} else {
fs.copyFileSync(src, dest);
}
};
const runCommand = (cmd) => {
console.log("\n", cmd);
child_process.execSync(cmd, { stdio: 'inherit' });
}
const createReleaseDir = () => {
if (fs.existsSync("release")) {
fs.rmSync("release", { recursive: true, force: true });
}
fs.mkdirSync("release/oasis", { recursive: true }, (e) => {
if (e) {
throw e;
}
});
}
const filename = process.platform.startsWith("win") ? "oasis.exe" : "oasis";
createReleaseDir();
process.chdir("frontend");
runCommand("npm i");
runCommand("npm run build");
copyRecursiveSync("public", "../release/oasis/public");
process.chdir("../backend");
runCommand("cargo build --release");
copyRecursiveSync("target/release/" + filename, "../release/oasis/" + filename);
copyRecursiveSync("assets/oasis.conf.sample", "../release/oasis/oasis.conf.sample");
process.chdir("../release/oasis");
fs.chmodSync(filename, 0o755);
console.log("\nBuild complete. Please check the 'release' directory.");