Merge pull request #404 from Microsoft/generate-hash-no-assets

Android binary hashing when there are no asset files
This commit is contained in:
Geoffrey Goh
2016-06-27 14:08:08 -07:00
committed by GitHub

View File

@@ -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);