@@ -13,6 +13,7 @@ import (
13
13
"net/url"
14
14
"os"
15
15
"os/exec"
16
+ "runtime"
16
17
"strconv"
17
18
"strings"
18
19
"time"
@@ -52,17 +53,20 @@ func (App) CreateBundle() {
52
53
var rnDir string
53
54
var description string
54
55
var isMinifyDisabled bool
56
+ var hermes bool
55
57
56
58
flag .StringVar (& targetVersion , "t" , "" , "Target version" )
57
59
flag .StringVar (& appName , "n" , "" , "AppName" )
58
60
flag .StringVar (& deployment , "d" , "" , "DeploymentName" )
59
61
flag .StringVar (& rnDir , "p" , "./" , "React native project dir" )
60
62
flag .StringVar (& description , "description" , "" , "Description" )
61
63
flag .BoolVar (& isMinifyDisabled , "disable-minify" , false , "Disable minify" )
64
+ flag .BoolVar (& hermes , "hermes" , false , "Enable hermes" )
65
+
62
66
flag .Parse ()
63
67
64
68
if targetVersion == "" || appName == "" || deployment == "" {
65
- fmt .Println ("Usage: code-push-go create_bundle -t <TargetVersion> -n <AppName> -d <deployment> -p <*Optional React native project dir> --description <*Optional Description> --disable-minify (*Optional)" )
69
+ fmt .Println ("Usage: code-push-go create_bundle -t <TargetVersion> -n <AppName> -d <deployment> -p <*Optional React native project dir> --description <*Optional Description> --disable-minify (*Optional) --hermes (*Optional) " )
66
70
return
67
71
}
68
72
log .Println ("Get app info..." )
@@ -105,15 +109,16 @@ func (App) CreateBundle() {
105
109
if isMinifyDisabled {
106
110
minify = "false"
107
111
}
108
-
112
+ buildUrl := rnDir + "build/CodePush"
113
+ bundelUrl := buildUrl + "/" + jsName
109
114
cmd := exec .Command (
110
115
"npx" ,
111
116
"react-native" ,
112
117
"bundle" ,
113
118
"--assets-dest" ,
114
- rnDir + "build/CodePush" ,
119
+ buildUrl ,
115
120
"--bundle-output" ,
116
- rnDir + "build/CodePush/" + jsName ,
121
+ bundelUrl ,
117
122
"--dev" ,
118
123
"false" ,
119
124
"--entry-file" ,
@@ -129,6 +134,49 @@ func (App) CreateBundle() {
129
134
log .Panic ("cmd.Run() failed with " , err )
130
135
}
131
136
137
+ if hermes {
138
+ sysType := runtime .GOOS
139
+ exc := "/osx-bin/hermesc"
140
+ if sysType == "linux" {
141
+ exc = "/linux64-bin/hermesc"
142
+ }
143
+ if sysType == "windows" {
144
+ exc = "/win64-bin/hermesc.exe"
145
+ }
146
+ hbcUrl := rnDir + "build/CodePush/" + jsName + ".hbc"
147
+ cmd := exec .Command (
148
+ "./node_modules/react-native/sdks/hermesc" + exc ,
149
+ "-emit-binary" ,
150
+ "-out" ,
151
+ hbcUrl ,
152
+ bundelUrl ,
153
+ // "-output-source-map",
154
+ )
155
+
156
+ cmd .Dir = rnDir
157
+ out , err := cmd .CombinedOutput ()
158
+ if err != nil {
159
+ fmt .Printf ("combined out:\n %s\n " , string (out ))
160
+ log .Panic ("cmd.Run() failed with " , err )
161
+ }
162
+ err = os .Remove (bundelUrl )
163
+ if err != nil {
164
+ panic (err .Error ())
165
+ }
166
+ data , err := os .ReadFile (hbcUrl )
167
+ if err != nil {
168
+ panic (err .Error ())
169
+ }
170
+ err = os .WriteFile (bundelUrl , data , 0755 )
171
+ if err != nil {
172
+ panic (err .Error ())
173
+ }
174
+ err = os .Remove (hbcUrl )
175
+ if err != nil {
176
+ panic (err .Error ())
177
+ }
178
+ }
179
+
132
180
hash , error := getHash (rnDir + "build" )
133
181
if error != nil {
134
182
log .Panic ("hash error" , error .Error ())
0 commit comments