@@ -13,6 +13,7 @@ import (
1313 "net/url"
1414 "os"
1515 "os/exec"
16+ "runtime"
1617 "strconv"
1718 "strings"
1819 "time"
@@ -52,17 +53,20 @@ func (App) CreateBundle() {
5253 var rnDir string
5354 var description string
5455 var isMinifyDisabled bool
56+ var hermes bool
5557
5658 flag .StringVar (& targetVersion , "t" , "" , "Target version" )
5759 flag .StringVar (& appName , "n" , "" , "AppName" )
5860 flag .StringVar (& deployment , "d" , "" , "DeploymentName" )
5961 flag .StringVar (& rnDir , "p" , "./" , "React native project dir" )
6062 flag .StringVar (& description , "description" , "" , "Description" )
6163 flag .BoolVar (& isMinifyDisabled , "disable-minify" , false , "Disable minify" )
64+ flag .BoolVar (& hermes , "hermes" , false , "Enable hermes" )
65+
6266 flag .Parse ()
6367
6468 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) " )
6670 return
6771 }
6872 log .Println ("Get app info..." )
@@ -105,15 +109,16 @@ func (App) CreateBundle() {
105109 if isMinifyDisabled {
106110 minify = "false"
107111 }
108-
112+ buildUrl := rnDir + "build/CodePush"
113+ bundelUrl := buildUrl + "/" + jsName
109114 cmd := exec .Command (
110115 "npx" ,
111116 "react-native" ,
112117 "bundle" ,
113118 "--assets-dest" ,
114- rnDir + "build/CodePush" ,
119+ buildUrl ,
115120 "--bundle-output" ,
116- rnDir + "build/CodePush/" + jsName ,
121+ bundelUrl ,
117122 "--dev" ,
118123 "false" ,
119124 "--entry-file" ,
@@ -129,6 +134,49 @@ func (App) CreateBundle() {
129134 log .Panic ("cmd.Run() failed with " , err )
130135 }
131136
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+
132180 hash , error := getHash (rnDir + "build" )
133181 if error != nil {
134182 log .Panic ("hash error" , error .Error ())
0 commit comments