more code duplication for having a separate update version for cordova

This commit is contained in:
Slava Kim
2014-08-15 14:43:31 -07:00
parent b4abcf1a95
commit e3ae279a60
2 changed files with 38 additions and 5 deletions

View File

@@ -51,6 +51,7 @@ ClientVersions = new Meteor.Collection("meteor_autoupdate_clientVersions",
Autoupdate.autoupdateVersion = null;
Autoupdate.autoupdateVersionRefreshable = null;
Autoupdate.autoupdateVersionCordova = null;
var syncQueue = new Meteor._SynchronousQueue();
var startupVersion = null;
@@ -78,6 +79,12 @@ var updateVersions = function (shouldReloadClientProgram) {
process.env.SERVER_ID || // XXX COMPAT 0.6.6
WebApp.calculateClientHashRefreshable();
Autoupdate.autoupdateVersionCordova =
__meteor_runtime_config__.autoupdateVersionCordova =
process.env.AUTOUPDATE_VERSION ||
process.env.SERVER_ID || // XXX COMPAT 0.6.6
WebApp.calculateClientHashCordova();
// Step 2: form the new client boilerplate which contains the updated
// assets and __meteor_runtime_config__.
if (shouldReloadClientProgram) {
@@ -109,6 +116,18 @@ var updateVersions = function (shouldReloadClientProgram) {
assets: WebAppInternals.refreshableAssets
}});
}
if (! ClientVersions.findOne({_id: "version-cordova"})) {
ClientVersions.insert({
_id: "version-cordova",
version: Autoupdate.autoupdateVersionCordova,
refreshable: false
});
} else {
ClientVersions.update("version-cordova", { $set: {
version: Autoupdate.autoupdateVersionCordova
}});
}
});
};

View File

@@ -182,12 +182,16 @@ var appUrl = function (url) {
// (but the second is a performance enhancement, not a hard
// requirement).
var calculateClientHash = function (manifest, includeFilter) {
var calculateClientHash = function (manifest, includeFilter, skipRuntimeCfg) {
var hash = crypto.createHash('sha1');
// Omit the old hashed client values in the new hash. These may be
// modified in the new boilerplate.
hash.update(JSON.stringify(_.omit(__meteor_runtime_config__,
['autoupdateVersion', 'autoupdateVersionRefreshable']), 'utf8'));
if (! skipRuntimeCfg) {
// Omit the old hashed client values in the new hash. These may be
// modified in the new boilerplate.
var runtimeCfgString = _.omit(__meteor_runtime_config__,
['autoupdateVersion', 'autoupdateVersionRefreshable']);
hash.update(JSON.stringify(runtimeCfgString, 'utf8'));
}
_.each(manifest, function (resource) {
if ((! includeFilter || includeFilter(resource.type)) &&
(resource.where === 'client' || resource.where === 'internal')) {
@@ -236,6 +240,16 @@ Meteor.startup(function () {
return name !== "css";
});
};
WebApp.calculateClientHashCordova = function () {
var archName = 'web.cordova';
if (! WebApp.clientPrograms[archName])
return 'none';
return calculateClientHash(
WebApp.clientPrograms[archName].manifest,
function () { return true; },
true);
};
});