Skip to content

chore: update nativescript-zip to latest and use {N} scoped #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ demo/platforms
publish/src
publish/package

node_modules
node_modules
package-lock.json
10 changes: 5 additions & 5 deletions demo-ng/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"nativescript": {
"id": "org.nativescript.demong.AppSync",
"tns-android": {
"version": "6.1.2"
"version": "6.2.0"
},
"tns-ios": {
"version": "6.1.0"
"version": "6.2.0"
}
},
"description": "NativeScript Application",
Expand Down Expand Up @@ -47,13 +47,13 @@
"nativescript-theme-core": "~1.0.6",
"reflect-metadata": "~0.1.13",
"rxjs": "~6.5.2",
"tns-core-modules": "~6.1.0",
"tns-core-modules": "~6.2.0",
"zone.js": "~0.10.0"
},
"devDependencies": {
"@angular/compiler-cli": "~8.2.3",
"@ngtools/webpack": "~8.2.2",
"nativescript-dev-webpack": "~1.2.0",
"typescript": "3.4.5"
"nativescript-dev-webpack": "~1.3.0",
"typescript": "~3.5.3"
}
}
14 changes: 7 additions & 7 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"nativescript": {
"id": "org.nativescript.plugindemo.AppSync",
"tns-ios": {
"version": "6.0.2"
"version": "6.2.0"
},
"tns-android": {
"version": "6.0.2"
"version": "6.2.0"
}
},
"scripts": {
Expand Down Expand Up @@ -34,7 +34,7 @@
"nativescript-app-sync": "file:../publish/package/nativescript-app-sync-1.0.7.tgz",
"nativescript-theme-core": "~1.0.4",
"nativescript-unit-test-runner": "0.7.0",
"tns-core-modules": "~6.0.0"
"tns-core-modules": "~6.2.0"
},
"devDependencies": {
"babel-traverse": "6.26.0",
Expand All @@ -46,10 +46,10 @@
"karma-jasmine": "2.0.1",
"karma-nativescript-launcher": "^0.4.0",
"lazy": "1.0.11",
"nativescript-dev-webpack": "1.0.1",
"tns-platform-declarations": "~6.0.0",
"tslint": "~5.4.3",
"typescript": "3.4.5",
"nativescript-dev-webpack": "1.3.0",
"tns-platform-declarations": "~6.2.0",
"tslint": "~5.20.0",
"typescript": "~3.5.3",
"karma-webpack": "3.0.5"
}
}
4 changes: 2 additions & 2 deletions src/TNSAcquisitionManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as AppVersion from "nativescript-appversion";
import { AcquisitionManager as AppSyncSDK } from "nativescript-app-sync-sdk/script/acquisition-sdk";
import { device } from "tns-core-modules/platform";
import { Device } from "@nativescript/core";
import { TNSRequester } from "./TNSRequester";

export class TNSAcquisitionManager {
Expand All @@ -11,7 +11,7 @@ export class TNSAcquisitionManager {
const config: Configuration = {
serverUrl,
appVersion: AppVersion.getVersionNameSync(),
clientUniqueId: device.uuid,
clientUniqueId: Device.uuid,
deploymentKey
};
this.appSyncSDK = new AppSyncSDK(new TNSRequester(), config);
Expand Down
63 changes: 32 additions & 31 deletions src/TNSLocalPackage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Zip } from "nativescript-zip";
import * as appSettings from "tns-core-modules/application-settings";
import * as fs from "tns-core-modules/file-system";
import * as fsa from "tns-core-modules/file-system/file-system-access";
import { isIOS } from "tns-core-modules/platform";
import * as utils from "tns-core-modules/utils/utils";
import { isIOS, ApplicationSettings, knownFolders, File, Folder, Utils } from "@nativescript/core";
import { FileSystemAccess } from "@nativescript/core/file-system/file-system-access";
import { AppSync } from "./app-sync";
import { TNSAcquisitionManager } from "./TNSAcquisitionManager";

Expand All @@ -30,15 +27,15 @@ export class TNSLocalPackage implements ILocalPackage {
serverUrl: string;

install(installSuccess: Function, errorCallback?: ErrorCallback, installOptions?: InstallOptions): void {
let appFolderPath = fs.knownFolders.documents().path + "/app";
let unzipFolderPath = fs.knownFolders.documents().path + "/AppSync-Unzipped/" + this.packageHash;
let appSyncFolder = fs.knownFolders.documents().path + "/AppSync";
let appFolderPath = knownFolders.documents().path + "/app";
let unzipFolderPath = knownFolders.documents().path + "/AppSync-Unzipped/" + this.packageHash;
let appSyncFolder = knownFolders.documents().path + "/AppSync";
// make sure the AppSync folder exists
fs.Folder.fromPath(appSyncFolder);
let newPackageFolderPath = fs.knownFolders.documents().path + "/AppSync/" + this.packageHash;
Folder.fromPath(appSyncFolder);
let newPackageFolderPath = knownFolders.documents().path + "/AppSync/" + this.packageHash;
// in case of a rollback make 'newPackageFolderPath' could already exist, so check and remove
if (fs.Folder.exists(newPackageFolderPath)) {
fs.Folder.fromPath(newPackageFolderPath).removeSync();
if (Folder.exists(newPackageFolderPath)) {
Folder.fromPath(newPackageFolderPath).removeSync();
}

const onUnzipComplete = (success: boolean, error?: string) => {
Expand All @@ -48,10 +45,10 @@ export class TNSLocalPackage implements ILocalPackage {
return;
}

const previousHash = appSettings.getString(AppSync.CURRENT_HASH_KEY, null);
const isDiffPackage = fs.File.exists(unzipFolderPath + "/hotappsync.json");
const previousHash = ApplicationSettings.getString(AppSync.CURRENT_HASH_KEY, null);
const isDiffPackage = File.exists(unzipFolderPath + "/hotappsync.json");
if (isDiffPackage) {
const copySourceFolder = previousHash === null ? appFolderPath : fs.knownFolders.documents().path + "/AppSync/" + previousHash;
const copySourceFolder = previousHash === null ? appFolderPath : knownFolders.documents().path + "/AppSync/" + previousHash;
if (!TNSLocalPackage.copyFolder(copySourceFolder, newPackageFolderPath)) {
errorCallback && errorCallback(new Error(`Failed to copy ${copySourceFolder} to ${newPackageFolderPath}`));
return;
Expand All @@ -61,39 +58,39 @@ export class TNSLocalPackage implements ILocalPackage {
return;
}
} else {
new fsa.FileSystemAccess().rename(unzipFolderPath, newPackageFolderPath, (error) => {
new FileSystemAccess().rename(unzipFolderPath, newPackageFolderPath, (error) => {
errorCallback && errorCallback(new Error(error));
return;
});
}

if (!isIOS) {
let pendingFolderPath = fs.knownFolders.documents().path + "/AppSync/pending";
if (fs.Folder.exists(pendingFolderPath)) {
fs.Folder.fromPath(pendingFolderPath).removeSync();
let pendingFolderPath = knownFolders.documents().path + "/AppSync/pending";
if (Folder.exists(pendingFolderPath)) {
Folder.fromPath(pendingFolderPath).removeSync();
}
if (!TNSLocalPackage.copyFolder(newPackageFolderPath, pendingFolderPath)) {
errorCallback && errorCallback(new Error(`Failed to copy ${newPackageFolderPath} to ${pendingFolderPath}`));
return;
}
}

appSettings.setString(TNSLocalPackage.APPSYNC_CURRENT_APPVERSION, this.appVersion);
ApplicationSettings.setString(TNSLocalPackage.APPSYNC_CURRENT_APPVERSION, this.appVersion);
TNSLocalPackage.saveCurrentPackage(this);

let buildTime: string;
// Note that this 'if' hardly justifies subclassing so we're not
if (isIOS) {
const plist = NSBundle.mainBundle.pathForResourceOfType(null, "plist");
const fileDate = new fsa.FileSystemAccess().getLastModified(plist);
const fileDate = new FileSystemAccess().getLastModified(plist);
buildTime = "" + fileDate.getTime();
} else {
const appSyncApkBuildTimeStringId = utils.ad.resources.getStringId(TNSLocalPackage.APPSYNC_APK_BUILD_TIME);
buildTime = utils.ad.getApplicationContext().getResources().getString(appSyncApkBuildTimeStringId);
const appSyncApkBuildTimeStringId = Utils.android.resources.getStringId(TNSLocalPackage.APPSYNC_APK_BUILD_TIME);
buildTime = Utils.android.getApplicationContext().getResources().getString(appSyncApkBuildTimeStringId);
}
appSettings.setString(TNSLocalPackage.APPSYNC_CURRENT_APPBUILDTIME, buildTime);
ApplicationSettings.setString(TNSLocalPackage.APPSYNC_CURRENT_APPBUILDTIME, buildTime);
//noinspection JSIgnoredPromiseFromCall (removal is async, don't really care if it fails)
fs.File.fromPath(this.localPath).remove();
File.fromPath(this.localPath).remove();

installSuccess();
};
Expand Down Expand Up @@ -121,7 +118,11 @@ export class TNSLocalPackage implements ILocalPackage {
}
);
} else {
Zip.unzipWithProgress(archive, destination, progressCallback).then(
Zip.unzip({
archive,
directory: destination,
onProgress: progressCallback
}).then(
() => {
completionCallback(true);
},
Expand All @@ -138,20 +139,20 @@ export class TNSLocalPackage implements ILocalPackage {
return;
}

appSettings.remove(TNSLocalPackage.APPSYNC_CURRENT_APPVERSION);
appSettings.remove(TNSLocalPackage.APPSYNC_CURRENT_APPBUILDTIME);
ApplicationSettings.remove(TNSLocalPackage.APPSYNC_CURRENT_APPVERSION);
ApplicationSettings.remove(TNSLocalPackage.APPSYNC_CURRENT_APPBUILDTIME);

const appSyncFolder = fs.Folder.fromPath(fs.knownFolders.documents().path + "/AppSync");
const appSyncFolder = Folder.fromPath(knownFolders.documents().path + "/AppSync");
//noinspection JSIgnoredPromiseFromCall
appSyncFolder.clear();
}

private static saveCurrentPackage(pack: IPackage): void {
appSettings.setString(TNSLocalPackage.APPSYNC_CURRENT_PACKAGE, JSON.stringify(pack));
ApplicationSettings.setString(TNSLocalPackage.APPSYNC_CURRENT_PACKAGE, JSON.stringify(pack));
}

static getCurrentPackage(): IPackage {
const packageStr: string = appSettings.getString(TNSLocalPackage.APPSYNC_CURRENT_PACKAGE, null);
const packageStr: string = ApplicationSettings.getString(TNSLocalPackage.APPSYNC_CURRENT_PACKAGE, null);
return packageStr === null ? null : JSON.parse(packageStr);
}

Expand Down
9 changes: 4 additions & 5 deletions src/TNSRemotePackage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { File } from "tns-core-modules/file-system";
import { getFile } from "tns-core-modules/http";
import { File, Http } from "@nativescript/core";
import { TNSAcquisitionManager } from "./TNSAcquisitionManager";
import { TNSLocalPackage } from "./TNSLocalPackage";

Expand Down Expand Up @@ -36,15 +35,15 @@ export class TNSRemotePackage implements IRemotePackage {
};

// download, with a silly but effective retry mechanism
getFile(this.downloadUrl)
Http.getFile(this.downloadUrl)
.then(onDownloadSuccess)
.catch(() => {
setTimeout(() => {
getFile(this.downloadUrl)
Http.getFile(this.downloadUrl)
.then(onDownloadSuccess)
.catch(() => {
setTimeout(() => {
getFile(this.downloadUrl)
Http.getFile(this.downloadUrl)
.then(onDownloadSuccess)
.catch((e: any) => downloadError(new Error("Could not download remote package. " + e)));
}, 3000);
Expand Down
4 changes: 2 additions & 2 deletions src/TNSRequester.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpResponse, request } from "tns-core-modules/http";
import { HttpResponse, Http as nsHttp } from "@nativescript/core";
import Requester = Http.Requester;

const packageJson = require("./package.json");
Expand All @@ -16,7 +16,7 @@ export class TNSRequester implements Requester {
requestBody = JSON.stringify(requestBody);
}

request({
nsHttp.request({
method: TNSRequester.getHttpMethodName(verb),
url,
content: requestBody,
Expand Down
Loading