generated from mmcs-gd/space-invaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
50 lines (42 loc) · 1.42 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
const glob = require("glob");
const path = require('path');
const { exec } = require('child_process');
const { exit } = require("process");
const dirname = process.argv[2]
const mode = process.argv[3]
const output_js = process.argv[4]
const flag_list = {
"release": "-O3 -s USE_SDL=2 -s MIN_WEBGL_VERSION=2 -s MAX_WEBGL_VERSION=3 -fexceptions -s INITIAL_MEMORY=67108864",
"debug": "-g -s USE_SDL=2 -s MIN_WEBGL_VERSION=2 -s MAX_WEBGL_VERSION=3 -fexceptions -D DEBUG=1 -s INITIAL_MEMORY=67108864"
};
if (process.argv.includes("-h") || process.argv.length < 5) {
console.log("node build.js <source_dir> <build_mode> <output_file>");
console.log(" source_dir - directory with .cpp files");
console.log(" build_mode - debug|release");
console.log(" output_file - output .js file");
exit()
}
if (!(mode in flag_list)) {
console.log(`error: unknown build mode "${mode}"`);
exit();
}
glob(path.join(dirname, '/**/*.cpp'), function(err, files) {
if (err) {
console.log(`read files error: ${err}`)
return;
}
exec([
"em++",
files.join(" "),
`-o ${output_js}`,
`-I ${dirname}`,
flag_list[mode]
].join(" "),
(err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
if (err) {
console.log(`exec error: ${err}`);
}
});
});