This commit is contained in:
Geoffrey Goh
2016-02-26 17:50:32 -08:00
parent 1c74ab3903
commit 3ab1fa0a10
4 changed files with 15 additions and 16 deletions

View File

@@ -70,7 +70,7 @@ async function checkForUpdate(deploymentKey = null) {
* because we want to avoid having to install diff updates against the binary's
* version, which we can't do yet on Android.
*/
if (!update || update.updateAppVersion || localPackage && (update.packageHash === localPackage.packageHash) || config.packageHash === update.packageHash) {
if (!update || update.updateAppVersion || localPackage && (update.packageHash === localPackage.packageHash) || !localPackage && config.packageHash === update.packageHash) {
if (update && update.updateAppVersion) {
log("An update is available but it is targeting a newer binary version than you are currently running.");
}

View File

@@ -21,20 +21,19 @@ gradle.projectsEvaluated {
productFlavors.each { productFlavorName ->
buildTypes.each { buildTypeName ->
def sourceName = "${buildTypeName}"
def targetName = "${sourceName.capitalize()}"
if (productFlavorName) {
sourceName = "${productFlavorName}${targetName}"
}
def targetName = "${productFlavorName.capitalize()}${buildTypeName.capitalize()}"
def targetPath = productFlavorName ?
"${productFlavorName}/${buildTypeName}" :
"${buildTypeName}"
def jsBundleDirConfigName = "jsBundleDir${targetName}"
def assetsDir = "$buildDir/intermediates/assets/${targetPath}"
def jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?:
file("$buildDir/intermediates/assets/${sourceName}")
file(assetsDir)
def resourcesDirConfigName = "jsBundleDir${targetName}"
def resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?:
file("$buildDir/intermediates/res/merged/${sourceName}")
file("$buildDir/intermediates/res/merged/${targetPath}")
def jsBundleFile = file("$jsBundleDir/$bundleAssetName")
// Make this task run right before the bundle task
@@ -52,7 +51,7 @@ gradle.projectsEvaluated {
def generateBundledResourcesHash = tasks.create(
name: "generateBundledResourcesHash${targetName}",
type: Exec) {
commandLine "node", "../../node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js", resourcesDir, "$jsBundleDir/$bundleAssetName", "$buildDir/intermediates/assets/${sourceName}"
commandLine "node", "../../node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js", resourcesDir, "$jsBundleDir/$bundleAssetName", assetsDir
}
generateBundledResourcesHash.dependsOn("bundle${targetName}JsAndAssets")

View File

@@ -20,7 +20,6 @@ var getFilesInFolder = require("./getFilesInFolder");
var CODE_PUSH_FOLDER_PREFIX = "CodePush";
var CODE_PUSH_HASH_FILE_NAME = "CodePushHash.json";
var HASH_ALGORITHM = "sha256";
var JS_BUNDLE_FILE_NAME = "main.jsbundle";
var TEMP_FILE_PATH = path.join(require("os").tmpdir(), "CodePushResourcesMap.json");
var resourcesDir = process.argv[2];
@@ -61,7 +60,7 @@ if (bundleGeneratedAssetFiles.length) {
hashStream.end();
var buffer = hashStream.read();
var fileHash = buffer.toString("hex");
manifest.push(CODE_PUSH_FOLDER_PREFIX + assetFile + ":" + fileHash);
manifest.push(CODE_PUSH_FOLDER_PREFIX + assetFile.replace(/\\/g, "/") + ":" + fileHash);
if (manifest.length === bundleGeneratedAssetFiles.length) {
// Generate hash for JS bundle
@@ -75,7 +74,7 @@ if (bundleGeneratedAssetFiles.length) {
hashStream.end();
var buffer = hashStream.read();
var fileHash = buffer.toString("hex");
manifest.push(CODE_PUSH_FOLDER_PREFIX + "/" + JS_BUNDLE_FILE_NAME + ":" + fileHash);
manifest.push(CODE_PUSH_FOLDER_PREFIX + "/" + path.basename(jsBundleFilePath) + ":" + fileHash);
manifest = manifest.sort();
var finalHash = crypto.createHash(HASH_ALGORITHM)

View File

@@ -1,15 +1,16 @@
var fs = require("fs");
var path = require("path");
// Utility function that collects the stats of every file in a directory
// as well as in its subdirectories.
function getFilesInFolder(folderName, fileList) {
var folderFiles = fs.readdirSync(folderName);
folderFiles.forEach(function(file) {
var fileStats = fs.statSync(folderName + "/" + file);
var fileStats = fs.statSync(path.join(folderName, file));
if (fileStats.isDirectory()) {
getFilesInFolder(folderName + "/" + file, fileList);
getFilesInFolder(path.join(folderName, file), fileList);
} else {
fileStats.path = folderName + "/" + file;
fileStats.path = path.join(folderName, file);
fileList.push(fileStats);
}
});