forked from vhqtvn/VHEditor-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle-rnjs.js
48 lines (39 loc) · 1.46 KB
/
bundle-rnjs.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
var child_process = require('child_process');
var isWin = process.platform === "win32" || process.platform === "win64";
const reactNativeBin = (
isWin ? ".\\node_modules\\.bin\\react-native.cmd"
:"./node_modules/.bin/react-native"
);
const child = child_process.spawnSync(reactNativeBin, [
"bundle",
"--platform","android",
"--dev","false",
"--entry-file","loader.js",
"--bundle-output","app/src/main/assets/loader.bundled.js",
"--minify","false",
"--assets-dest","app/src/main/res/",
], { encoding : 'utf8', shell: true, stdio: ['inherit', 'inherit', 'inherit'] });
if(child.error) {
console.log("ERROR: ",child.error);
process.exit(child.error)
}
const hermescBin = isWin ? 'hermesc.exe' : 'hermesc';
let osBin = "linux64-bin";
if(isWin) {
osBin = "win64-bin"
} else if (process.platform == "darwin") {
osBin = "osx-bin"
}
let hermescCmd = `node_modules/react-native/sdks/hermesc/${osBin}/${hermescBin}`
if(isWin) hermescCmd = hermescCmd.replace(/\//g,'\\');
const child2 = child_process.spawnSync(hermescCmd, [
"-emit-binary",
"-out","app/src/main/assets/loader.bundled.tmp.js",
"app/src/main/assets/loader.bundled.js",
"-O"
], { encoding : 'utf8', shell: true, stdio: ['inherit', 'inherit', 'inherit'] });
if(child2.error) {
console.log("ERROR: ",child2.error);
process.exit(child2.error)
}
require("fs").renameSync("app/src/main/assets/loader.bundled.tmp.js", "app/src/main/assets/loader.bundled.js");