mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 07:10:36 +08:00
Merge pull request #404 from Microsoft/generate-hash-no-assets
Android binary hashing when there are no asset files
This commit is contained in:
@@ -51,23 +51,29 @@ if (bundleGeneratedAssetFiles.length) {
|
||||
// Generate hash for each asset file
|
||||
addFileToManifest(resourcesDir, assetFile, manifest, function() {
|
||||
if (manifest.length === bundleGeneratedAssetFiles.length) {
|
||||
// Generate hash for JS bundle
|
||||
addFileToManifest(path.dirname(jsBundleFilePath), path.basename(jsBundleFilePath), manifest, function() {
|
||||
// ...and the JS bundle "meta"
|
||||
var jsBundleMetaFilePath = jsBundleFilePath + ".meta";
|
||||
addFileToManifest(path.dirname(jsBundleMetaFilePath), path.basename(jsBundleMetaFilePath), manifest, function() {
|
||||
manifest = manifest.sort();
|
||||
var finalHash = crypto.createHash(HASH_ALGORITHM)
|
||||
.update(JSON.stringify(manifest))
|
||||
.digest("hex");
|
||||
|
||||
var savedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_FILE_NAME;
|
||||
fs.writeFileSync(savedResourcesManifestPath, finalHash);
|
||||
});
|
||||
});
|
||||
addJsBundleAndMetaToManifest();
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
addJsBundleAndMetaToManifest();
|
||||
}
|
||||
|
||||
function addJsBundleAndMetaToManifest() {
|
||||
addFileToManifest(path.dirname(jsBundleFilePath), path.basename(jsBundleFilePath), manifest, function() {
|
||||
var jsBundleMetaFilePath = jsBundleFilePath + ".meta";
|
||||
addFileToManifest(path.dirname(jsBundleMetaFilePath), path.basename(jsBundleMetaFilePath), manifest, function() {
|
||||
manifest = manifest.sort();
|
||||
var finalHash = crypto.createHash(HASH_ALGORITHM)
|
||||
.update(JSON.stringify(manifest))
|
||||
.digest("hex");
|
||||
|
||||
console.log(finalHash);
|
||||
|
||||
var savedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_FILE_NAME;
|
||||
fs.writeFileSync(savedResourcesManifestPath, finalHash);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function addFileToManifest(folder, assetFile, manifest, done) {
|
||||
@@ -98,4 +104,4 @@ function fileExists(file) {
|
||||
catch (e) { return false; }
|
||||
}
|
||||
|
||||
fs.unlinkSync(TEMP_FILE_PATH);
|
||||
fs.unlinkSync(TEMP_FILE_PATH);
|
||||
|
||||
Reference in New Issue
Block a user