Skip to content

Commit b9353be

Browse files
committed
--wip-- [skip ci]
1 parent a5c8871 commit b9353be

File tree

2 files changed

+61
-35
lines changed

2 files changed

+61
-35
lines changed

cli/commands/releaseCommand/release.ts

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import fs from "fs";
22
import path from "path";
3-
import yauzl from "yauzl";
43
import { bundleCodePush } from "../bundleCommand/bundleCodePush.js";
54
import { addToReleaseHistory } from "./addToReleaseHistory.js";
65
import type { CliConfigInterface } from "../../../typings/react-native-code-push.d.ts";
76
import { generatePackageHashFromDirectory } from "../../utils/hash-utils.js";
7+
import { unzip } from "../../utils/unzip.js";
88

99
export async function release(
1010
bundleUploader: CliConfigInterface['bundleUploader'],
@@ -81,41 +81,21 @@ function readBundleFileNameFrom(bundleDirectory: string): string {
8181
return path.basename(bundleFilePath);
8282
}
8383

84-
function calcHashFromBundleFile(bundleFilePath: string): Promise<string> {
84+
async function calcHashFromBundleFile(bundleFilePath: string): Promise<string> {
8585
const tempDir = path.join(path.dirname(bundleFilePath), 'temp_contents_for_hash_calc');
86-
console.log('🔥 🔥 🔥 tempDir', tempDir);
87-
fs.mkdirSync(tempDir);
86+
const zipFilePath = path.resolve(bundleFilePath);
8887

89-
// unzip
90-
yauzl.open(bundleFilePath, { lazyEntries: true }, (err, zipFile) => {
91-
if (err) throw err;
92-
zipFile.readEntry();
93-
zipFile.on("entry", (entry) => {
94-
if (/\/$/.test(entry.fileName)) {
95-
// Directory file names end with '/'.
96-
// Note that entries for directories themselves are optional.
97-
// An entry's fileName implicitly requires its parent directories to exist.
98-
zipFile.readEntry();
99-
} else {
100-
// file entry
101-
zipFile.openReadStream(entry, (err, readStream) => {
102-
if (err) throw err;
103-
readStream.on("end", () => {
104-
zipFile.readEntry();
105-
});
106-
readStream.pipe(fs.createWriteStream(tempDir));
107-
});
108-
}
109-
});
110-
});
111-
112-
// calc hash
113-
const hash = generatePackageHashFromDirectory(tempDir, path.join(tempDir, '..'));
114-
115-
// cleanup
116-
fs.rmSync(tempDir, { recursive: true });
117-
118-
console.log('🔥 🔥 🔥 hash', hash);
88+
if (fs.existsSync(tempDir)) {
89+
fs.rmSync(tempDir, { recursive: true, force: true });
90+
}
91+
fs.mkdirSync(tempDir, { recursive: true });
11992

120-
return hash;
93+
try {
94+
await unzip(zipFilePath, tempDir);
95+
const hash = await generatePackageHashFromDirectory(tempDir, tempDir);
96+
console.log(`log: Calculated package hash from existing bundle file: ${hash}`);
97+
return hash;
98+
} finally {
99+
fs.rmSync(tempDir, { recursive: true, force: true });
100+
}
121101
}

cli/utils/unzip.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import yauzl from "yauzl";
4+
5+
export function unzip(zipPath: string, outputDir: string): Promise<void> {
6+
return new Promise<void>((resolve, reject) => {
7+
yauzl.open(zipPath, { lazyEntries: true }, (err, zipFile) => {
8+
if (err) return reject(err);
9+
10+
zipFile.readEntry();
11+
12+
zipFile.on("entry", (entry) => {
13+
const fullPath = path.join(outputDir, entry.fileName);
14+
15+
// Handle directory entry
16+
if (/\/$/.test(entry.fileName)) {
17+
fs.mkdir(fullPath, { recursive: true }, (err) => {
18+
if (err) return reject(err);
19+
zipFile.readEntry();
20+
});
21+
return;
22+
}
23+
24+
// Handle file entry
25+
zipFile.openReadStream(entry, (err, readStream) => {
26+
if (err) return reject(err);
27+
28+
fs.mkdir(path.dirname(fullPath), { recursive: true }, (err) => {
29+
if (err) return reject(err);
30+
31+
const writeStream = fs.createWriteStream(fullPath);
32+
readStream.pipe(writeStream);
33+
34+
// Continue to the next entry after writing
35+
writeStream.on("close", () => {
36+
zipFile.readEntry();
37+
});
38+
});
39+
});
40+
});
41+
42+
zipFile.on("end", resolve);
43+
zipFile.on("error", reject);
44+
});
45+
});
46+
}

0 commit comments

Comments
 (0)