@@ -3,6 +3,8 @@ import path from "path";
33import { bundleCodePush } from "../bundleCommand/bundleCodePush.js" ;
44import { addToReleaseHistory } from "./addToReleaseHistory.js" ;
55import type { CliConfigInterface } from "../../../typings/react-native-code-push.d.ts" ;
6+ import { generatePackageHashFromDirectory } from "../../utils/hash-utils.js" ;
7+ import { unzip } from "../../utils/unzip.js" ;
68
79export async function release (
810 bundleUploader : CliConfigInterface [ 'bundleUploader' ] ,
@@ -22,12 +24,21 @@ export async function release(
2224 skipBundle : boolean ,
2325 skipCleanup : boolean ,
2426 bundleDirectory : string ,
27+ hashCalc ?: boolean ,
2528) : Promise < void > {
2629 const bundleFileName = skipBundle
2730 ? readBundleFileNameFrom ( bundleDirectory )
2831 : await bundleCodePush ( framework , platform , outputPath , entryFile , jsBundleName , bundleDirectory ) ;
2932 const bundleFilePath = `${ bundleDirectory } /${ bundleFileName } ` ;
3033
34+ const packageHash = await ( ( ) => {
35+ if ( skipBundle && hashCalc ) {
36+ return calcHashFromBundleFile ( bundleFilePath ) ;
37+ }
38+ // If not using --skip-bundle, the bundleFileName represents package hash already.
39+ return bundleFileName ;
40+ } ) ( ) ;
41+
3142 const downloadUrl = await ( async ( ) => {
3243 try {
3344 const { downloadUrl } = await bundleUploader ( bundleFilePath , platform , identifier ) ;
@@ -42,7 +53,7 @@ export async function release(
4253 appVersion ,
4354 binaryVersion ,
4455 downloadUrl ,
45- bundleFileName ,
56+ packageHash ,
4657 getReleaseHistory ,
4758 setReleaseHistory ,
4859 platform ,
@@ -70,3 +81,22 @@ function readBundleFileNameFrom(bundleDirectory: string): string {
7081 const bundleFilePath = path . join ( bundleDirectory , files [ 0 ] ) ;
7182 return path . basename ( bundleFilePath ) ;
7283}
84+
85+ async function calcHashFromBundleFile ( bundleFilePath : string ) : Promise < string > {
86+ const tempDir = path . resolve ( path . join ( path . dirname ( bundleFilePath ) , 'temp_contents_for_hash_calc' ) ) ;
87+ const zipFilePath = path . resolve ( bundleFilePath ) ;
88+
89+ if ( fs . existsSync ( tempDir ) ) {
90+ fs . rmSync ( tempDir , { recursive : true , force : true } ) ;
91+ }
92+ fs . mkdirSync ( tempDir , { recursive : true } ) ;
93+
94+ try {
95+ await unzip ( zipFilePath , tempDir ) ;
96+ const hash = await generatePackageHashFromDirectory ( tempDir , tempDir ) ;
97+ console . log ( `log: Calculated package hash from existing bundle file: ${ hash } ` ) ;
98+ return hash ;
99+ } finally {
100+ fs . rmSync ( tempDir , { recursive : true , force : true } ) ;
101+ }
102+ }
0 commit comments