@@ -9,6 +9,7 @@ import { spawn, spawnSync } from 'node:child_process';
9
9
const g2js = require ( 'gradle-to-js/lib/parser' ) ;
10
10
import os from 'os' ;
11
11
const properties = require ( 'properties' ) ;
12
+ const path = require ( 'path' ) ;
12
13
13
14
let bsdiff , hdiff , diff ;
14
15
try {
@@ -72,32 +73,51 @@ async function runReactNativeBundleCommand(
72
73
} ) ;
73
74
}
74
75
}
75
- const bundleCommand = usingExpo ? 'export:embed' : 'bundle' ;
76
-
77
- Array . prototype . push . apply ( reactNativeBundleArgs , [
78
- cliPath ,
79
- bundleCommand ,
80
- '--assets-dest' ,
81
- outputFolder ,
82
- '--bundle-output' ,
83
- path . join ( outputFolder , bundleName ) ,
84
- '--dev' ,
85
- development ,
86
- '--entry-file' ,
87
- entryFile ,
88
- '--platform' ,
89
- platform ,
90
- '--reset-cache' ,
91
- ] ) ;
76
+ const bundleCommand = usingExpo ? 'export:embed' : platform === 'harmony' ? 'bundle-harmony' : 'bundle' ;
77
+ if ( platform == 'harmony' ) {
78
+ Array . prototype . push . apply ( reactNativeBundleArgs , [
79
+ cliPath ,
80
+ bundleCommand ,
81
+ '--dev' ,
82
+ development ,
83
+ '--entry-file' ,
84
+ entryFile ,
85
+ ] ) ;
92
86
93
- if ( sourcemapOutput ) {
94
- reactNativeBundleArgs . push ( '--sourcemap-output' , sourcemapOutput ) ;
95
- }
87
+ if ( sourcemapOutput ) {
88
+ reactNativeBundleArgs . push ( '--sourcemap-output' , sourcemapOutput ) ;
89
+ }
96
90
97
- if ( config ) {
98
- reactNativeBundleArgs . push ( '--config' , config ) ;
91
+ if ( config ) {
92
+ reactNativeBundleArgs . push ( '--config' , config ) ;
93
+ }
99
94
}
100
-
95
+ else {
96
+ Array . prototype . push . apply ( reactNativeBundleArgs , [
97
+ cliPath ,
98
+ bundleCommand ,
99
+ '--assets-dest' ,
100
+ outputFolder ,
101
+ '--bundle-output' ,
102
+ path . join ( outputFolder , bundleName ) ,
103
+ '--dev' ,
104
+ development ,
105
+ '--entry-file' ,
106
+ entryFile ,
107
+ '--platform' ,
108
+ platform ,
109
+ '--reset-cache' ,
110
+ ] ) ;
111
+
112
+ if ( sourcemapOutput ) {
113
+ reactNativeBundleArgs . push ( '--sourcemap-output' , sourcemapOutput ) ;
114
+ }
115
+
116
+ if ( config ) {
117
+ reactNativeBundleArgs . push ( '--config' , config ) ;
118
+ }
119
+ }
120
+
101
121
const reactNativeBundleProcess = spawn ( 'node' , reactNativeBundleArgs ) ;
102
122
console . log (
103
123
`Running bundle command: node ${ reactNativeBundleArgs . join ( ' ' ) } ` ,
@@ -146,6 +166,8 @@ async function runReactNativeBundleCommand(
146
166
fs . existsSync ( 'ios/Pods/hermes-engine' )
147
167
) {
148
168
hermesEnabled = true ;
169
+ } else if ( platform === 'harmony' ) {
170
+ await copyHarmonyBundle ( outputFolder ) ;
149
171
}
150
172
if ( hermesEnabled ) {
151
173
await compileHermesByteCode (
@@ -160,6 +182,21 @@ async function runReactNativeBundleCommand(
160
182
} ) ;
161
183
}
162
184
185
+ async function copyHarmonyBundle ( outputFolder ) {
186
+ const harmonyRawPath = 'harmony/entry/src/main/resources/rawfile' ;
187
+
188
+ try {
189
+ await fs . ensureDir ( outputFolder ) ;
190
+ await fs . copy ( harmonyRawPath , outputFolder ) ;
191
+
192
+ console . log (
193
+ `Successfully copied from ${ harmonyRawPath } to ${ outputFolder } ` ,
194
+ ) ;
195
+ } catch ( error ) {
196
+ console . error ( 'Error in copyHarmonyBundle:' , error ) ;
197
+ }
198
+ }
199
+
163
200
function getHermesOSBin ( ) {
164
201
if ( os . platform ( ) === 'win32' ) return 'win64-bin' ;
165
202
if ( os . platform ( ) === 'darwin' ) return 'osx-bin' ;
@@ -335,7 +372,7 @@ async function diffFromPPK(origin, next, output) {
335
372
// isFile
336
373
originMap [ entry . crc32 ] = entry . fileName ;
337
374
338
- if ( entry . fileName === 'index.bundlejs' ) {
375
+ if ( entry . fileName === 'index.bundlejs' || entry . fileName === 'bundle.harmony.js' ) {
339
376
// This is source.
340
377
return readEntire ( entry , zipFile ) . then ( ( v ) => ( originSource = v ) ) ;
341
378
}
@@ -397,6 +434,16 @@ async function diffFromPPK(origin, next, output) {
397
434
) ;
398
435
//console.log('End diff');
399
436
} ) ;
437
+ } else if ( entry . fileName === 'bundle.harmony.js' ) {
438
+ //console.log('Found bundle');
439
+ return readEntire ( entry , nextZipfile ) . then ( ( newSource ) => {
440
+ //console.log('Begin diff');
441
+ zipfile . addBuffer (
442
+ diff ( originSource , newSource ) ,
443
+ 'bundle.harmony.js.patch' ,
444
+ ) ;
445
+ //console.log('End diff');
446
+ } ) ;
400
447
} else {
401
448
// If same file.
402
449
const originEntry = originEntries [ entry . fileName ] ;
@@ -519,7 +566,17 @@ async function diffFromPackage(
519
566
) ;
520
567
//console.log('End diff');
521
568
} ) ;
522
- } else {
569
+ } else if ( entry . fileName === 'bundle.harmony.js' ) {
570
+ //console.log('Found bundle');
571
+ return readEntire ( entry , nextZipfile ) . then ( ( newSource ) => {
572
+ //console.log('Begin diff');
573
+ zipfile . addBuffer (
574
+ diff ( originSource , newSource ) ,
575
+ 'bundle.harmony.js.patch' ,
576
+ ) ;
577
+ //console.log('End diff');
578
+ } ) ;
579
+ } else {
523
580
// If same file.
524
581
if ( originEntries [ entry . fileName ] === entry . crc32 ) {
525
582
copies [ entry . fileName ] = '' ;
@@ -551,22 +608,53 @@ async function diffFromPackage(
551
608
await writePromise ;
552
609
}
553
610
554
- function enumZipEntries ( zipFn , callback ) {
611
+ async function enumZipEntries ( zipFn , callback , nestedPath = '' ) {
555
612
return new Promise ( ( resolve , reject ) => {
556
- openZipFile ( zipFn , { lazyEntries : true } , ( err , zipfile ) => {
613
+ openZipFile ( zipFn , { lazyEntries : true } , async ( err , zipfile ) => {
557
614
if ( err ) {
558
615
return reject ( err ) ;
559
616
}
617
+
560
618
zipfile . on ( 'end' , resolve ) ;
561
619
zipfile . on ( 'error' , reject ) ;
562
- zipfile . on ( 'entry' , ( entry ) => {
563
- const result = callback ( entry , zipfile ) ;
564
- if ( result && typeof result . then === 'function' ) {
565
- result . then ( ( ) => zipfile . readEntry ( ) ) ;
566
- } else {
567
- zipfile . readEntry ( ) ;
620
+ zipfile . on ( 'entry' , async ( entry ) => {
621
+ const fullPath = nestedPath + entry . fileName ;
622
+
623
+ try {
624
+ if (
625
+ ! entry . fileName . endsWith ( '/' ) &&
626
+ entry . fileName . toLowerCase ( ) . endsWith ( '.hap' )
627
+ ) {
628
+ const tempDir = path . join ( os . tmpdir ( ) , 'nested_zip_' + Date . now ( ) ) ;
629
+ await fs . ensureDir ( tempDir ) ;
630
+ const tempZipPath = path . join ( tempDir , 'temp.zip' ) ;
631
+
632
+ await new Promise ( ( res , rej ) => {
633
+ zipfile . openReadStream ( entry , async ( err , readStream ) => {
634
+ if ( err ) return rej ( err ) ;
635
+ const writeStream = fs . createWriteStream ( tempZipPath ) ;
636
+ readStream . pipe ( writeStream ) ;
637
+ writeStream . on ( 'finish' , res ) ;
638
+ writeStream . on ( 'error' , rej ) ;
639
+ } ) ;
640
+ } ) ;
641
+
642
+ await enumZipEntries ( tempZipPath , callback , fullPath + '/' ) ;
643
+
644
+ await fs . remove ( tempDir ) ;
645
+ }
646
+
647
+ const result = callback ( entry , zipfile , fullPath ) ;
648
+ if ( result && typeof result . then === 'function' ) {
649
+ await result ;
650
+ }
651
+ } catch ( error ) {
652
+ console . error ( '处理文件时出错:' , error ) ;
568
653
}
654
+
655
+ zipfile . readEntry ( ) ;
569
656
} ) ;
657
+
570
658
zipfile . readEntry ( ) ;
571
659
} ) ;
572
660
} ) ;
@@ -700,6 +788,21 @@ export const commands = {
700
788
console . log ( `${ realOutput } generated.` ) ;
701
789
} ,
702
790
791
+ async hdiffFromApp ( { args, options } ) {
792
+ const { origin, next, realOutput } = diffArgsCheck (
793
+ args ,
794
+ options ,
795
+ 'hdiffFromApp' ,
796
+ ) ;
797
+ await diffFromPackage (
798
+ origin ,
799
+ next ,
800
+ realOutput ,
801
+ 'resources/rawfile/bundle.harmony.js' ,
802
+ ) ;
803
+ console . log ( `${ realOutput } generated.` ) ;
804
+ } ,
805
+
703
806
async diffFromIpa ( { args, options } ) {
704
807
const { origin, next, realOutput } = diffArgsCheck (
705
808
args ,
0 commit comments