From b771e4615f1a32bf184a6a26d3244202023736d6 Mon Sep 17 00:00:00 2001 From: "RP\\sergey.akhalkov" Date: Mon, 8 May 2017 15:51:18 +0300 Subject: [PATCH] Fix code-push version dependency, add support for latest typescript --- bin/www/codePushUtil.js | 10 +++--- bin/www/localPackage.js | 35 +++++++++++-------- bin/www/remotePackage.js | 17 +++++---- plugin.xml | 2 +- test/test.ts | 74 ++++++++++++++++++++-------------------- 5 files changed, 74 insertions(+), 64 deletions(-) diff --git a/bin/www/codePushUtil.js b/bin/www/codePushUtil.js index 1be539fd..69fa5411 100644 --- a/bin/www/codePushUtil.js +++ b/bin/www/codePushUtil.js @@ -38,11 +38,11 @@ var CodePushUtil = (function () { var errorMessage = message || "" + " " + CodePushUtil.getErrorMessage(error); console.error(CodePushUtil.TAG + " " + errorMessage); }; - CodePushUtil.TAG = "[CodePush]"; - CodePushUtil.invokeErrorCallback = function (error, errorCallback) { - CodePushUtil.logError(null, error); - errorCallback && errorCallback(error); - }; return CodePushUtil; }()); +CodePushUtil.TAG = "[CodePush]"; +CodePushUtil.invokeErrorCallback = function (error, errorCallback) { + CodePushUtil.logError(null, error); + errorCallback && errorCallback(error); +}; module.exports = CodePushUtil; diff --git a/bin/www/localPackage.js b/bin/www/localPackage.js index aaec59cb..189c3977 100644 --- a/bin/www/localPackage.js +++ b/bin/www/localPackage.js @@ -8,11 +8,16 @@ "use strict"; -var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); -}; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); var Package = require("./package"); var NativeAppInfo = require("./nativeAppInfo"); var FileUtil = require("./fileUtil"); @@ -21,7 +26,7 @@ var Sdk = require("./sdk"); var LocalPackage = (function (_super) { __extends(LocalPackage, _super); function LocalPackage() { - _super.apply(this, arguments); + return _super !== null && _super.apply(this, arguments) || this; } LocalPackage.prototype.install = function (installSuccess, errorCallback, installOptions) { var _this = this; @@ -372,15 +377,15 @@ var LocalPackage = (function (_super) { } return LocalPackage.DefaultInstallOptions; }; - LocalPackage.RootDir = "codepush"; - LocalPackage.DownloadDir = LocalPackage.RootDir + "/download"; - LocalPackage.DownloadUnzipDir = LocalPackage.DownloadDir + "/unzipped"; - LocalPackage.DeployDir = LocalPackage.RootDir + "/deploy"; - LocalPackage.VersionsDir = LocalPackage.DeployDir + "/versions"; - LocalPackage.PackageUpdateFileName = "update.zip"; - LocalPackage.PackageInfoFile = "currentPackage.json"; - LocalPackage.OldPackageInfoFile = "oldPackage.json"; - LocalPackage.DiffManifestFile = "hotcodepush.json"; return LocalPackage; }(Package)); +LocalPackage.RootDir = "codepush"; +LocalPackage.DownloadDir = LocalPackage.RootDir + "/download"; +LocalPackage.DownloadUnzipDir = LocalPackage.DownloadDir + "/unzipped"; +LocalPackage.DeployDir = LocalPackage.RootDir + "/deploy"; +LocalPackage.VersionsDir = LocalPackage.DeployDir + "/versions"; +LocalPackage.PackageUpdateFileName = "update.zip"; +LocalPackage.PackageInfoFile = "currentPackage.json"; +LocalPackage.OldPackageInfoFile = "oldPackage.json"; +LocalPackage.DiffManifestFile = "hotcodepush.json"; module.exports = LocalPackage; diff --git a/bin/www/remotePackage.js b/bin/www/remotePackage.js index dce31b9d..7d779f6b 100644 --- a/bin/www/remotePackage.js +++ b/bin/www/remotePackage.js @@ -8,11 +8,16 @@ "use strict"; -var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); -}; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); var LocalPackage = require("./localPackage"); var Package = require("./package"); var NativeAppInfo = require("./nativeAppInfo"); @@ -21,7 +26,7 @@ var Sdk = require("./sdk"); var RemotePackage = (function (_super) { __extends(RemotePackage, _super); function RemotePackage() { - _super.apply(this, arguments); + return _super !== null && _super.apply(this, arguments) || this; } RemotePackage.prototype.download = function (successCallback, errorCallback, downloadProgress) { var _this = this; diff --git a/plugin.xml b/plugin.xml index 14fd4786..1566e10b 100644 --- a/plugin.xml +++ b/plugin.xml @@ -6,7 +6,7 @@ cordova,code,push https://github.com/Microsoft/cordova-plugin-code-push.git - + diff --git a/test/test.ts b/test/test.ts index 8c37d07e..db60250f 100644 --- a/test/test.ts +++ b/test/test.ts @@ -78,7 +78,7 @@ function cleanupTest(): void { } function setupTests(): void { - it("sets up tests correctly", (done) => { + it("sets up tests correctly", (done: any) => { var promises: Q.Promise[] = []; targetPlatforms.forEach(platform => { @@ -274,7 +274,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo }); if (!onlyRunCoreTests) { - it("window.codePush.checkForUpdate.noUpdate", function(done) { + it("window.codePush.checkForUpdate.noUpdate", function(done: any) { var noUpdateResponse = createDefaultResponse(); noUpdateResponse.isAvailable = false; noUpdateResponse.appVersion = "0.0.1"; @@ -293,7 +293,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo projectManager.runPlatform(testRunDirectory, targetPlatform); }); - it("window.codePush.checkForUpdate.sendsBinaryHash", function(done) { + it("window.codePush.checkForUpdate.sendsBinaryHash", function(done: any) { var noUpdateResponse = createDefaultResponse(); noUpdateResponse.isAvailable = false; noUpdateResponse.appVersion = "0.0.1"; @@ -320,7 +320,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo projectManager.runPlatform(testRunDirectory, targetPlatform); }); - it("window.codePush.checkForUpdate.noUpdate.updateAppVersion", function(done) { + it("window.codePush.checkForUpdate.noUpdate.updateAppVersion", function(done: any) { var updateAppVersionResponse = createDefaultResponse(); updateAppVersionResponse.updateAppVersion = true; updateAppVersionResponse.appVersion = "2.0.0"; @@ -341,7 +341,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo } // CORE TEST - it("window.codePush.checkForUpdate.update", function(done) { + it("window.codePush.checkForUpdate.update", function(done: any) { var updateResponse = createMockResponse(); mockResponse = { updateInfo: updateResponse }; @@ -375,7 +375,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo }); if (!onlyRunCoreTests) { - it("window.codePush.checkForUpdate.error", function(done) { + it("window.codePush.checkForUpdate.error", function(done: any) { mockResponse = "invalid {{ json"; testMessageCallback = (requestBody: any) => { @@ -407,7 +407,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo return prepareTest(); }); - it("window.codePush.checkForUpdate.customKey.update", function(done) { + it("window.codePush.checkForUpdate.customKey.update", function(done: any) { var updateResponse = createMockResponse(); mockResponse = { updateInfo: updateResponse }; @@ -445,7 +445,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo return updateResponse; }; - it("remotePackage.download.success", function(done) { + it("remotePackage.download.success", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; /* pass the path to any file for download (here, config.xml) to make sure the download completed callback is invoked */ @@ -463,7 +463,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo projectManager.runPlatform(testRunDirectory, targetPlatform); }); - it("remotePackage.download.error", function(done) { + it("remotePackage.download.error", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; /* pass an invalid path */ @@ -502,7 +502,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo return updateResponse; }; - it("localPackage.install.unzip.error", function(done) { + it("localPackage.install.unzip.error", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -521,7 +521,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo projectManager.runPlatform(testRunDirectory, targetPlatform); }); - it("localPackage.install.handlesDiff.againstBinary", function(done) { + it("localPackage.install.handlesDiff.againstBinary", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -545,7 +545,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("localPackage.install.immediately", function(done) { + it("localPackage.install.immediately", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -584,7 +584,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo return prepareTest(); }); - it("localPackage.install.revert.dorevert", function(done) { + it("localPackage.install.revert.dorevert", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -624,7 +624,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("localPackage.install.revert.norevert", function(done) { + it("localPackage.install.revert.norevert", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -665,7 +665,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo }); // CORE TEST - it("localPackage.installOnNextResume.dorevert", function(done) { + it("localPackage.installOnNextResume.dorevert", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -696,7 +696,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo }); if (!onlyRunCoreTests) { - it("localPackage.installOnNextResume.norevert", function(done) { + it("localPackage.installOnNextResume.norevert", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -744,7 +744,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo }); if (!onlyRunCoreTests) { - it("localPackage.installOnNextRestart.dorevert", function(done) { + it("localPackage.installOnNextRestart.dorevert", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -778,7 +778,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo } // CORE TEST - it("localPackage.installOnNextRestart.norevert", function(done) { + it("localPackage.installOnNextRestart.norevert", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -810,7 +810,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo }); if (!onlyRunCoreTests) { - it("localPackage.installOnNextRestart.revertToPrevious", function(done) { + it("localPackage.installOnNextRestart.revertToPrevious", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -877,7 +877,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo return prepareTest(); }); - it("localPackage.installOnNextRestart2x.revertToFirst", function(done) { + it("localPackage.installOnNextRestart2x.revertToFirst", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; updateCheckCallback = () => { // Update the packageHash so we can install the same update twice. @@ -927,7 +927,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo return prepareTest(); }); - it("codePush.restartApplication.checkPackages", function(done) { + it("codePush.restartApplication.checkPackages", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -985,7 +985,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo return prepareTest(); }); - it("window.codePush.sync.noupdate", function(done) { + it("window.codePush.sync.noupdate", function(done: any) { var noUpdateResponse = createDefaultResponse(); noUpdateResponse.isAvailable = false; noUpdateResponse.appVersion = "0.0.1"; @@ -1004,7 +1004,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("window.codePush.sync.checkerror", function(done) { + it("window.codePush.sync.checkerror", function(done: any) { mockResponse = "invalid {{ json"; Q({}) @@ -1020,7 +1020,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("window.codePush.sync.downloaderror", function(done) { + it("window.codePush.sync.downloaderror", function(done: any) { var invalidUrlResponse = createMockResponse(); invalidUrlResponse.downloadURL = path.join(templatePath, "invalid_path.zip"); mockResponse = { updateInfo: invalidUrlResponse }; @@ -1039,7 +1039,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("window.codePush.sync.dorevert", function(done) { + it("window.codePush.sync.dorevert", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -1069,7 +1069,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("window.codePush.sync.update", function(done) { + it("window.codePush.sync.update", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; /* create an update */ @@ -1120,7 +1120,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo }); if (!onlyRunCoreTests) { - it("window.codePush.sync.2x.noupdate", function(done) { + it("window.codePush.sync.2x.noupdate", function(done: any) { var noUpdateResponse = createDefaultResponse(); noUpdateResponse.isAvailable = false; noUpdateResponse.appVersion = "0.0.1"; @@ -1140,7 +1140,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("window.codePush.sync.2x.checkerror", function(done) { + it("window.codePush.sync.2x.checkerror", function(done: any) { mockResponse = "invalid {{ json"; Q({}) @@ -1157,7 +1157,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("window.codePush.sync.2x.downloaderror", function(done) { + it("window.codePush.sync.2x.downloaderror", function(done: any) { var invalidUrlResponse = createMockResponse(); invalidUrlResponse.downloadURL = path.join(templatePath, "invalid_path.zip"); mockResponse = { updateInfo: invalidUrlResponse }; @@ -1177,7 +1177,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("window.codePush.sync.2x.dorevert", function(done) { + it("window.codePush.sync.2x.dorevert", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; @@ -1212,7 +1212,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo }); } - it("window.codePush.sync.2x.update", function(done) { + it("window.codePush.sync.2x.update", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; /* create an update */ @@ -1263,7 +1263,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo return prepareTest(); }); - it("defaults to no minimum", function(done) { + it("defaults to no minimum", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; setupScenario(ScenarioSyncResume).then(() => { @@ -1292,7 +1292,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("min background duration 5s", function(done) { + it("min background duration 5s", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; setupScenario(ScenarioSyncResumeDelay).then(() => { @@ -1324,7 +1324,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("has no effect on restart", function(done) { + it("has no effect on restart", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; setupScenario(ScenarioSyncRestartDelay).then(() => { @@ -1364,7 +1364,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo return prepareTest(); }); - it("defaults to IMMEDIATE", function(done) { + it("defaults to IMMEDIATE", function(done: any) { mockResponse = { updateInfo: getMockResponse(true) }; setupScenario(ScenarioSyncMandatoryDefault).then(() => { @@ -1383,7 +1383,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("works correctly when update is mandatory and mandatory install mode is specified", function(done) { + it("works correctly when update is mandatory and mandatory install mode is specified", function(done: any) { mockResponse = { updateInfo: getMockResponse(true) }; setupScenario(ScenarioSyncMandatoryResume).then(() => { @@ -1412,7 +1412,7 @@ function runTests(targetPlatform: platform.IPlatform, useWkWebView: boolean): vo .done(done, done); }); - it("has no effect on updates that are not mandatory", function(done) { + it("has no effect on updates that are not mandatory", function(done: any) { mockResponse = { updateInfo: getMockResponse() }; setupScenario(ScenarioSyncMandatoryRestart).then(() => {