Skip to content

Commit 453573b

Browse files
committed
chore: update nativescript-zip to latest and use {N} scoped
1 parent 8c996fd commit 453573b

10 files changed

+83
-85
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ demo/platforms
2626
publish/src
2727
publish/package
2828

29-
node_modules
29+
node_modules
30+
package-lock.json

Diff for: demo-ng/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"nativescript": {
33
"id": "org.nativescript.demong.AppSync",
44
"tns-android": {
5-
"version": "6.1.2"
5+
"version": "6.2.0"
66
},
77
"tns-ios": {
8-
"version": "6.1.0"
8+
"version": "6.2.0"
99
}
1010
},
1111
"description": "NativeScript Application",
@@ -47,13 +47,13 @@
4747
"nativescript-theme-core": "~1.0.6",
4848
"reflect-metadata": "~0.1.13",
4949
"rxjs": "~6.5.2",
50-
"tns-core-modules": "~6.1.0",
50+
"tns-core-modules": "~6.2.0",
5151
"zone.js": "~0.10.0"
5252
},
5353
"devDependencies": {
5454
"@angular/compiler-cli": "~8.2.3",
5555
"@ngtools/webpack": "~8.2.2",
56-
"nativescript-dev-webpack": "~1.2.0",
57-
"typescript": "3.4.5"
56+
"nativescript-dev-webpack": "~1.3.0",
57+
"typescript": "~3.5.3"
5858
}
5959
}

Diff for: demo/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"nativescript": {
33
"id": "org.nativescript.plugindemo.AppSync",
44
"tns-ios": {
5-
"version": "6.0.2"
5+
"version": "6.2.0"
66
},
77
"tns-android": {
8-
"version": "6.0.2"
8+
"version": "6.2.0"
99
}
1010
},
1111
"scripts": {
@@ -34,7 +34,7 @@
3434
"nativescript-app-sync": "file:../publish/package/nativescript-app-sync-1.0.7.tgz",
3535
"nativescript-theme-core": "~1.0.4",
3636
"nativescript-unit-test-runner": "0.7.0",
37-
"tns-core-modules": "~6.0.0"
37+
"tns-core-modules": "~6.2.0"
3838
},
3939
"devDependencies": {
4040
"babel-traverse": "6.26.0",
@@ -46,10 +46,10 @@
4646
"karma-jasmine": "2.0.1",
4747
"karma-nativescript-launcher": "^0.4.0",
4848
"lazy": "1.0.11",
49-
"nativescript-dev-webpack": "1.0.1",
50-
"tns-platform-declarations": "~6.0.0",
51-
"tslint": "~5.4.3",
52-
"typescript": "3.4.5",
49+
"nativescript-dev-webpack": "1.3.0",
50+
"tns-platform-declarations": "~6.2.0",
51+
"tslint": "~5.20.0",
52+
"typescript": "~3.5.3",
5353
"karma-webpack": "3.0.5"
5454
}
5555
}

Diff for: src/TNSAcquisitionManager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as AppVersion from "nativescript-appversion";
22
import { AcquisitionManager as AppSyncSDK } from "nativescript-app-sync-sdk/script/acquisition-sdk";
3-
import { device } from "tns-core-modules/platform";
3+
import { Device } from "@nativescript/core";
44
import { TNSRequester } from "./TNSRequester";
55

66
export class TNSAcquisitionManager {
@@ -11,7 +11,7 @@ export class TNSAcquisitionManager {
1111
const config: Configuration = {
1212
serverUrl,
1313
appVersion: AppVersion.getVersionNameSync(),
14-
clientUniqueId: device.uuid,
14+
clientUniqueId: Device.uuid,
1515
deploymentKey
1616
};
1717
this.appSyncSDK = new AppSyncSDK(new TNSRequester(), config);

Diff for: src/TNSLocalPackage.ts

+32-31
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { Zip } from "nativescript-zip";
2-
import * as appSettings from "tns-core-modules/application-settings";
3-
import * as fs from "tns-core-modules/file-system";
4-
import * as fsa from "tns-core-modules/file-system/file-system-access";
5-
import { isIOS } from "tns-core-modules/platform";
6-
import * as utils from "tns-core-modules/utils/utils";
2+
import { isIOS, ApplicationSettings, knownFolders, File, Folder, Utils } from "@nativescript/core";
3+
import { FileSystemAccess } from "@nativescript/core/file-system/file-system-access";
74
import { AppSync } from "./app-sync";
85
import { TNSAcquisitionManager } from "./TNSAcquisitionManager";
96

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

3229
install(installSuccess: Function, errorCallback?: ErrorCallback, installOptions?: InstallOptions): void {
33-
let appFolderPath = fs.knownFolders.documents().path + "/app";
34-
let unzipFolderPath = fs.knownFolders.documents().path + "/AppSync-Unzipped/" + this.packageHash;
35-
let appSyncFolder = fs.knownFolders.documents().path + "/AppSync";
30+
let appFolderPath = knownFolders.documents().path + "/app";
31+
let unzipFolderPath = knownFolders.documents().path + "/AppSync-Unzipped/" + this.packageHash;
32+
let appSyncFolder = knownFolders.documents().path + "/AppSync";
3633
// make sure the AppSync folder exists
37-
fs.Folder.fromPath(appSyncFolder);
38-
let newPackageFolderPath = fs.knownFolders.documents().path + "/AppSync/" + this.packageHash;
34+
Folder.fromPath(appSyncFolder);
35+
let newPackageFolderPath = knownFolders.documents().path + "/AppSync/" + this.packageHash;
3936
// in case of a rollback make 'newPackageFolderPath' could already exist, so check and remove
40-
if (fs.Folder.exists(newPackageFolderPath)) {
41-
fs.Folder.fromPath(newPackageFolderPath).removeSync();
37+
if (Folder.exists(newPackageFolderPath)) {
38+
Folder.fromPath(newPackageFolderPath).removeSync();
4239
}
4340

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

51-
const previousHash = appSettings.getString(AppSync.CURRENT_HASH_KEY, null);
52-
const isDiffPackage = fs.File.exists(unzipFolderPath + "/hotappsync.json");
48+
const previousHash = ApplicationSettings.getString(AppSync.CURRENT_HASH_KEY, null);
49+
const isDiffPackage = File.exists(unzipFolderPath + "/hotappsync.json");
5350
if (isDiffPackage) {
54-
const copySourceFolder = previousHash === null ? appFolderPath : fs.knownFolders.documents().path + "/AppSync/" + previousHash;
51+
const copySourceFolder = previousHash === null ? appFolderPath : knownFolders.documents().path + "/AppSync/" + previousHash;
5552
if (!TNSLocalPackage.copyFolder(copySourceFolder, newPackageFolderPath)) {
5653
errorCallback && errorCallback(new Error(`Failed to copy ${copySourceFolder} to ${newPackageFolderPath}`));
5754
return;
@@ -61,39 +58,39 @@ export class TNSLocalPackage implements ILocalPackage {
6158
return;
6259
}
6360
} else {
64-
new fsa.FileSystemAccess().rename(unzipFolderPath, newPackageFolderPath, (error) => {
61+
new FileSystemAccess().rename(unzipFolderPath, newPackageFolderPath, (error) => {
6562
errorCallback && errorCallback(new Error(error));
6663
return;
6764
});
6865
}
6966

7067
if (!isIOS) {
71-
let pendingFolderPath = fs.knownFolders.documents().path + "/AppSync/pending";
72-
if (fs.Folder.exists(pendingFolderPath)) {
73-
fs.Folder.fromPath(pendingFolderPath).removeSync();
68+
let pendingFolderPath = knownFolders.documents().path + "/AppSync/pending";
69+
if (Folder.exists(pendingFolderPath)) {
70+
Folder.fromPath(pendingFolderPath).removeSync();
7471
}
7572
if (!TNSLocalPackage.copyFolder(newPackageFolderPath, pendingFolderPath)) {
7673
errorCallback && errorCallback(new Error(`Failed to copy ${newPackageFolderPath} to ${pendingFolderPath}`));
7774
return;
7875
}
7976
}
8077

81-
appSettings.setString(TNSLocalPackage.APPSYNC_CURRENT_APPVERSION, this.appVersion);
78+
ApplicationSettings.setString(TNSLocalPackage.APPSYNC_CURRENT_APPVERSION, this.appVersion);
8279
TNSLocalPackage.saveCurrentPackage(this);
8380

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

9895
installSuccess();
9996
};
@@ -121,7 +118,11 @@ export class TNSLocalPackage implements ILocalPackage {
121118
}
122119
);
123120
} else {
124-
Zip.unzipWithProgress(archive, destination, progressCallback).then(
121+
Zip.unzip({
122+
archive,
123+
directory: destination,
124+
onProgress: progressCallback
125+
}).then(
125126
() => {
126127
completionCallback(true);
127128
},
@@ -138,20 +139,20 @@ export class TNSLocalPackage implements ILocalPackage {
138139
return;
139140
}
140141

141-
appSettings.remove(TNSLocalPackage.APPSYNC_CURRENT_APPVERSION);
142-
appSettings.remove(TNSLocalPackage.APPSYNC_CURRENT_APPBUILDTIME);
142+
ApplicationSettings.remove(TNSLocalPackage.APPSYNC_CURRENT_APPVERSION);
143+
ApplicationSettings.remove(TNSLocalPackage.APPSYNC_CURRENT_APPBUILDTIME);
143144

144-
const appSyncFolder = fs.Folder.fromPath(fs.knownFolders.documents().path + "/AppSync");
145+
const appSyncFolder = Folder.fromPath(knownFolders.documents().path + "/AppSync");
145146
//noinspection JSIgnoredPromiseFromCall
146147
appSyncFolder.clear();
147148
}
148149

149150
private static saveCurrentPackage(pack: IPackage): void {
150-
appSettings.setString(TNSLocalPackage.APPSYNC_CURRENT_PACKAGE, JSON.stringify(pack));
151+
ApplicationSettings.setString(TNSLocalPackage.APPSYNC_CURRENT_PACKAGE, JSON.stringify(pack));
151152
}
152153

153154
static getCurrentPackage(): IPackage {
154-
const packageStr: string = appSettings.getString(TNSLocalPackage.APPSYNC_CURRENT_PACKAGE, null);
155+
const packageStr: string = ApplicationSettings.getString(TNSLocalPackage.APPSYNC_CURRENT_PACKAGE, null);
155156
return packageStr === null ? null : JSON.parse(packageStr);
156157
}
157158

Diff for: src/TNSRemotePackage.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { File } from "tns-core-modules/file-system";
2-
import { getFile } from "tns-core-modules/http";
1+
import { File, Http } from "@nativescript/core";
32
import { TNSAcquisitionManager } from "./TNSAcquisitionManager";
43
import { TNSLocalPackage } from "./TNSLocalPackage";
54

@@ -36,15 +35,15 @@ export class TNSRemotePackage implements IRemotePackage {
3635
};
3736

3837
// download, with a silly but effective retry mechanism
39-
getFile(this.downloadUrl)
38+
Http.getFile(this.downloadUrl)
4039
.then(onDownloadSuccess)
4140
.catch(() => {
4241
setTimeout(() => {
43-
getFile(this.downloadUrl)
42+
Http.getFile(this.downloadUrl)
4443
.then(onDownloadSuccess)
4544
.catch(() => {
4645
setTimeout(() => {
47-
getFile(this.downloadUrl)
46+
Http.getFile(this.downloadUrl)
4847
.then(onDownloadSuccess)
4948
.catch((e: any) => downloadError(new Error("Could not download remote package. " + e)));
5049
}, 3000);

Diff for: src/TNSRequester.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HttpResponse, request } from "tns-core-modules/http";
1+
import { HttpResponse, Http as nsHttp } from "@nativescript/core";
22
import Requester = Http.Requester;
33

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

19-
request({
19+
nsHttp.request({
2020
method: TNSRequester.getHttpMethodName(verb),
2121
url,
2222
content: requestBody,

0 commit comments

Comments
 (0)