@@ -76,6 +76,37 @@ export function getReactNativeProjectAppVersion(
76
76
}
77
77
78
78
if ( parsedPlist && parsedPlist . CFBundleShortVersionString ) {
79
+ if ( / M A R K E T I N G _ V E R S I O N / i. test ( parsedPlist . CFBundleShortVersionString ) ) {
80
+ try {
81
+ const xcodeProjectConfig =
82
+ path . resolve ( resolvedPlistFile , "../" ) +
83
+ ".xcodeproj/project.pbxproj" ;
84
+ out . text (
85
+ 'Using xcodeProjectConfig version, file path "'
86
+ . concat ( xcodeProjectConfig , '".\n' )
87
+ ) ;
88
+ const xcodeContents = fs . readFileSync ( xcodeProjectConfig ) . toString ( ) ;
89
+ const xcodeVersionRegex = / R e l e a s e [ \s \S ] * M A R K E T I N G _ V E R S I O N = ( \d + \. \d + \. \d + ) / gm;
90
+ let xcodeVersion ;
91
+ let match ;
92
+
93
+ while ( ( match = xcodeVersionRegex . exec ( xcodeContents ) ) !== null ) {
94
+ // 这个循环将重复执行,直到没有更多匹配项
95
+ // match[1] 将包含第一个捕获组的值,即版本号
96
+ xcodeVersion = match [ 1 ] ;
97
+ break ; // 因为我们只需要第一个匹配项,所以找到后就可以退出循环
98
+ }
99
+ out . text (
100
+ 'Using xcodeProjectConfig version, version "' . concat (
101
+ xcodeVersion ,
102
+ '".\n'
103
+ )
104
+ ) ;
105
+ parsedPlist . CFBundleShortVersionString = xcodeVersion ;
106
+ } catch ( error ) {
107
+
108
+ }
109
+ }
79
110
if ( isValidVersion ( parsedPlist . CFBundleShortVersionString ) ) {
80
111
out . text (
81
112
`Using the target binary version value "${ parsedPlist . CFBundleShortVersionString } " from "${ resolvedPlistFile } ".\n` ,
@@ -334,7 +365,7 @@ export function runHermesEmitBinaryCommand(
334
365
) : Promise < void > {
335
366
const hermesArgs : string [ ] = [ ] ;
336
367
const envNodeArgs : string = process . env . CODE_PUSH_NODE_ARGS ;
337
-
368
+ out . text ( chalk . cyan ( 'Converting JS bundle to byte code via Hermes, running command:\n' ) ) ;
338
369
if ( typeof envNodeArgs !== 'undefined' ) {
339
370
Array . prototype . push . apply ( hermesArgs , envNodeArgs . trim ( ) . split ( / \s + / ) ) ;
340
371
}
@@ -458,29 +489,41 @@ export function runHermesEmitBinaryCommand(
458
489
} ) ;
459
490
}
460
491
461
- export function getHermesEnabled ( gradleFile ?: string ) : Promise < boolean > {
462
- let buildGradlePath : string = path . join ( 'android' , 'app' ) ;
463
- if ( gradleFile ) {
464
- buildGradlePath = gradleFile ;
465
- }
466
- if ( fs . lstatSync ( buildGradlePath ) . isDirectory ( ) ) {
492
+ export async function getHermesEnabled ( gradleFile ?: string ) : Promise < boolean > {
493
+ let buildGradlePath = gradleFile ?? path . join ( 'android' , 'app' ) ;
494
+
495
+ if ( await fileDoesNotExistOrIsDirectory ( buildGradlePath ) ) {
467
496
buildGradlePath = path . join ( buildGradlePath , 'build.gradle' ) ;
468
497
}
469
498
470
- if ( fileDoesNotExistOrIsDirectory ( buildGradlePath ) ) {
499
+ if ( await fileDoesNotExistOrIsDirectory ( buildGradlePath ) ) {
471
500
throw new Error ( `Unable to find gradle file "${ buildGradlePath } ".` ) ;
472
501
}
473
502
474
- return g2js
475
- . parseFile ( buildGradlePath )
476
- . catch ( ( ) => {
477
- throw new Error (
478
- `Unable to parse the "${ buildGradlePath } " file. Please ensure it is a well-formed Gradle file.` ,
479
- ) ;
480
- } )
481
- . then ( ( buildGradle : any ) => {
482
- return Array . from ( buildGradle [ 'project.ext.react' ] ) . includes ( 'enableHermes: true' ) ;
483
- } ) ;
503
+ let gradlePropertyPath : string = path . join ( 'android' , 'gradle.properties' ) ;
504
+
505
+ if ( await fileDoesNotExistOrIsDirectory ( gradlePropertyPath ) ) {
506
+ throw new Error ( `Unable to find gradle file "${ gradlePropertyPath } ".` ) ;
507
+ }
508
+
509
+ try {
510
+ const buildGradle = await g2js . parseFile ( buildGradlePath ) ;
511
+ const buildProperty = await g2js . parseFile ( gradlePropertyPath ) ;
512
+
513
+ const hermesPropertyEnabled = buildProperty . hermesEnabled ?? false ;
514
+ let hermesBuildEnabled = false ;
515
+
516
+ // 如果buildGradle["project.ext.react"]是一个数组,则继续处理
517
+ if ( Array . isArray ( buildGradle [ "project.ext.react" ] ) ) {
518
+ const reactSettings : string [ ] = buildGradle [ "project.ext.react" ] ;
519
+ hermesBuildEnabled = reactSettings . some ( line => / ^ e n a b l e H e r m e s \s * : \s * t r u e / . test ( line ) ) ;
520
+ }
521
+
522
+ return hermesPropertyEnabled || hermesBuildEnabled ;
523
+ } catch ( error ) {
524
+ // error.message 可能需要根据实际在 try 块中发生的错误进行调整
525
+ throw new Error ( `An error occurred while processing the Gradle files: ${ error . message } ` ) ;
526
+ }
484
527
}
485
528
486
529
export function getiOSHermesEnabled ( podFile : string ) : Promise < boolean > {
@@ -538,6 +581,17 @@ function getHermesCommand(): string {
538
581
}
539
582
} ;
540
583
// assume if hermes-engine exists it should be used instead of hermesvm
584
+ const hermesEngineNew = path . join (
585
+ 'node_modules' ,
586
+ 'react-native' ,
587
+ 'sdks' ,
588
+ 'hermesc' ,
589
+ getHermesOSBin ( ) ,
590
+ getHermesOSExe ( )
591
+ ) ;
592
+ if ( fileExists ( hermesEngineNew ) ) {
593
+ return hermesEngineNew ;
594
+ }
541
595
const hermesEngine = path . join (
542
596
'node_modules' ,
543
597
'hermes-engine' ,
0 commit comments