Skip to content

Commit f72ca8b

Browse files
committed
Support build hermes
1 parent 8041a53 commit f72ca8b

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Code-push-go cli used with [code-push-server-go](https://github.com/htdcx/code-p
66
git clone https://github.com/htdcx/code-push-go.git
77
cd code-push-go
88

9-
#MacOS build GOOS:windows,darwin
10-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o code-push-go(.exe) main.go
9+
#MacOS build GOOS:windows,darwin GOARCH:amd64,arm64
10+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o code-push-go(.exe) main.go
1111

1212
#Windows build
13-
set GOARCH=amd64
13+
set GOARCH=amd64 #GOARCH:amd64,arm64
1414
set GOOS=linux #windows,darwin
1515
go build -o code-push-go(.exe) main.go
1616
mv code-push-go(.exe) <You project>
@@ -29,7 +29,7 @@ chmod +x code-push-go
2929
./code-push-go app create_deployment -n <AppName> -dn <DeploymentName>
3030

3131
#Update react native
32-
./code-push-go create_bundle -t <TargetVersion> -n <AppName> -d <DeploymentName> -p <(*Optional) React native project default:./> --description <(*Optional) Description default: ""/>
32+
./code-push-go create_bundle -t <TargetVersion> -n <AppName> -d <DeploymentName> -p <(*Optional) React native project default:./> --description <(*Optional) Description default: ""/> --hermes (*Optional)
3333

3434
#More command
3535
./code-push-go

opt/app.go

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)