11
11
12
12
const fs = require ( 'fs' ) ;
13
13
const path = require ( 'path' ) ;
14
- const { echo , exec , exit } = require ( 'shelljs ' ) ;
14
+ const { execSync } = require ( 'child_process ' ) ;
15
15
16
16
const SDKS_DIR = path . normalize ( path . join ( __dirname , '..' , '..' , 'sdks' ) ) ;
17
17
const HERMES_DIR = path . join ( SDKS_DIR , 'hermes' ) ;
@@ -41,14 +41,21 @@ function prepareFileSystem() {
41
41
42
42
function readHermesTag ( ) {
43
43
if ( fs . existsSync ( HERMES_TAG_FILE_PATH ) ) {
44
- const data = fs . readFileSync ( HERMES_TAG_FILE_PATH , {
45
- encoding : 'utf8' ,
46
- flag : 'r' ,
47
- } ) ;
48
- return data . trim ( ) ;
49
- } else {
50
- return 'main' ;
44
+ const data = fs
45
+ . readFileSync ( HERMES_TAG_FILE_PATH , {
46
+ encoding : 'utf8' ,
47
+ flag : 'r' ,
48
+ } )
49
+ . trim ( ) ;
50
+
51
+ if ( data . length > 0 ) {
52
+ return data ;
53
+ } else {
54
+ throw new Error ( '[Hermes] .hermesversion file is empty.' ) ;
55
+ }
51
56
}
57
+
58
+ return 'main' ;
52
59
}
53
60
54
61
function setHermesTag ( hermesTag ) {
@@ -64,10 +71,11 @@ function setHermesTag(hermesTag) {
64
71
}
65
72
66
73
function getHermesTagSHA ( hermesTag ) {
67
- return exec (
74
+ return execSync (
68
75
`git ls-remote https://github.com/facebook/hermes ${ hermesTag } | cut -f 1` ,
69
- { silent : true } ,
70
- ) . trim ( ) ;
76
+ )
77
+ . toString ( )
78
+ . trim ( ) ;
71
79
}
72
80
73
81
function getHermesTarballDownloadPath ( hermesTag ) {
@@ -87,11 +95,13 @@ function downloadHermesTarball() {
87
95
return ;
88
96
}
89
97
90
- echo ( `[Hermes] Downloading Hermes source code for commit ${ hermesTagSHA } ` ) ;
91
- if ( exec ( `curl ${ hermesTarballUrl } -Lo ${ hermesTarballDownloadPath } ` ) . code ) {
92
- echo ( '[Hermes] Failed to download Hermes tarball.' ) ;
93
- exit ( 1 ) ;
94
- return ;
98
+ console . info (
99
+ `[Hermes] Downloading Hermes source code for commit ${ hermesTagSHA } ` ,
100
+ ) ;
101
+ try {
102
+ execSync ( `curl ${ hermesTarballUrl } -Lo ${ hermesTarballDownloadPath } ` ) ;
103
+ } catch ( error ) {
104
+ throw new Error ( `[Hermes] Failed to download Hermes tarball. ${ error } ` ) ;
95
105
}
96
106
}
97
107
@@ -103,32 +113,24 @@ function expandHermesTarball() {
103
113
prepareFileSystem ( ) ;
104
114
105
115
if ( ! fs . existsSync ( hermesTarballDownloadPath ) ) {
106
- echo (
107
- `[Hermes] Failed to expand Hermes tarball, no file found at ${ hermesTarballDownloadPath } .` ,
108
- ) ;
109
- exit ( 1 ) ;
110
- return ;
116
+ throw new Error ( `[Hermes] Failed to expand Hermes tarball.` ) ;
111
117
}
112
118
113
- echo ( `[Hermes] Expanding Hermes tarball for commit ${ hermesTagSHA } ` ) ;
114
- if (
115
- exec (
119
+ console . info ( `[Hermes] Expanding Hermes tarball for commit ${ hermesTagSHA } ` ) ;
120
+ try {
121
+ execSync (
116
122
`tar -zxf ${ hermesTarballDownloadPath } --strip-components=1 --directory ${ HERMES_DIR } ` ,
117
- ) . code
118
- ) {
119
- echo ( '[Hermes] Failed to expand Hermes tarball.' ) ;
120
- exit ( 1 ) ;
121
- return ;
123
+ ) ;
124
+ } catch ( error ) {
125
+ throw new Error ( '[Hermes] Failed to expand Hermes tarball.' ) ;
122
126
}
123
127
}
124
128
125
129
function copyBuildScripts ( ) {
126
130
if ( ! fs . existsSync ( HERMES_DIR ) ) {
127
- echo (
131
+ throw new Error (
128
132
'[Hermes] Failed to copy Hermes build scripts, no Hermes source directory found.' ,
129
133
) ;
130
- exit ( 1 ) ;
131
- return ;
132
134
}
133
135
134
136
fs . copyFileSync (
@@ -163,8 +165,14 @@ set_target_properties(native-hermesc PROPERTIES
163
165
IMPORTED_LOCATION "${ MACOS_HERMESC_PATH } "
164
166
)` ;
165
167
166
- fs . mkdirSync ( MACOS_BIN_DIR , { recursive : true } ) ;
167
- fs . writeFileSync ( MACOS_IMPORT_HERMESC_PATH , IMPORT_HERMESC_TEMPLATE ) ;
168
+ try {
169
+ fs . mkdirSync ( MACOS_BIN_DIR , { recursive : true } ) ;
170
+ fs . writeFileSync ( MACOS_IMPORT_HERMESC_PATH , IMPORT_HERMESC_TEMPLATE ) ;
171
+ } catch ( error ) {
172
+ console . warn (
173
+ `[Hermes] Re-compiling hermesc. Unable to configure make: ${ error } ` ,
174
+ ) ;
175
+ }
168
176
}
169
177
170
178
module . exports = {
0 commit comments