11import fs from "fs" ;
2+ import path from "path" ;
23import { prepareToBundleJS } from "../../functions/prepareToBundleJS.js" ;
34import { runReactNativeBundleCommand } from "../../functions/runReactNativeBundleCommand.js" ;
45import { runExpoBundleCommand } from "../../functions/runExpoBundleCommand.js" ;
@@ -17,6 +18,7 @@ export async function bundleCodePush(
1718 entryFile : string = ENTRY_FILE ,
1819 jsBundleName : string , // JS bundle file name (not CodePush bundle file)
1920 bundleDirectory : string , // CodePush bundle output directory
21+ outputMetroDir ?: string ,
2022) : Promise < string > {
2123 if ( fs . existsSync ( outputRootPath ) ) {
2224 fs . rmSync ( outputRootPath , { recursive : true } ) ;
@@ -49,6 +51,8 @@ export async function bundleCodePush(
4951
5052 console . log ( 'log: JS bundling complete' ) ;
5153
54+ copyMetroOutputsIfNeeded ( outputRootPath , outputMetroDir , OUTPUT_CONTENT_PATH , _jsBundleName , SOURCEMAP_OUTPUT ) ;
55+
5256 await runHermesEmitBinaryCommand (
5357 _jsBundleName ,
5458 OUTPUT_CONTENT_PATH ,
@@ -61,3 +65,27 @@ export async function bundleCodePush(
6165
6266 return codePushBundleFileName ;
6367}
68+
69+ function copyMetroOutputsIfNeeded (
70+ outputRootPath : string ,
71+ outputMetroDir : string | undefined ,
72+ outputContentPath : string ,
73+ jsBundleName : string ,
74+ sourceMapOutputPath : string ,
75+ ) {
76+ if ( ! outputMetroDir ) {
77+ return ;
78+ }
79+
80+ const resolvedOutputMetroDir = path . join ( outputRootPath , outputMetroDir ) ;
81+
82+ fs . mkdirSync ( resolvedOutputMetroDir , { recursive : true } ) ;
83+ fs . copyFileSync (
84+ path . join ( outputContentPath , jsBundleName ) ,
85+ path . join ( resolvedOutputMetroDir , jsBundleName ) ,
86+ ) ;
87+ fs . copyFileSync (
88+ sourceMapOutputPath ,
89+ path . join ( resolvedOutputMetroDir , path . basename ( sourceMapOutputPath ) ) ,
90+ ) ;
91+ }
0 commit comments